text: #!/usr/bin/python3
  
  import os
  import sys
  from hashlib import sha512
  from optparse import OptionParser
  
  sys.path.insert(0, os.path.normpath(os.path.join(os.path.realpath(__file__), "../../modules")))
  from merge.db_core import *
  
  parser = OptionParser()
  parser.add_option("--catpkg", dest="catpkg", help="catpkg of ebuild")
  parser.add_option("--src_uri", dest="src_uri", help="download URL")
  parser.add_option("--kit", dest="kit", help="kit of ebuild")
  parser.add_option("--branch", dest="branch", help="branch of kit")
  parser.add_option("--replace", dest="replace", action="store_true", default=False, help="replace existing distfile in fastpull.")
  options, args = parser.parse_args()
  
  if len(args) != 1:
  	print("Please specify a single file to inject into queued distfiles.")
  	sys.exit(1)
  
  def get_sha512(fn):
  	with open(fn, "rb") as data:
  		my_hash = sha512()
  		my_hash.update(data.read())
  		return my_hash.hexdigest()
  
  db = FastPullDatabase()
  fn = args[0]
  
  if not os.path.exists(fn):
  	print("File %s does not exist. Can't inject." % fn)
  	sys.exit(1)
  
  with db.get_session() as session:
  	existing = session.query(db.Distfile).filter(db.Distfile.filename == os.path.basename(fn)).first()
  	if existing:
  		if options.replace is True:
  			print("Removing distfile entry for existing file.")
  			session.delete(existing)
  			session.commit()
  		else:
  			print("File already exists in distfiles. Skipping.")
  			sys.exit(1)
  qdsf = db.QueuedDistfile()
  qdsf.filename = os.path.basename(fn)
  qdsf.catpkg = options.catpkg
  qdsf.kit = options.kit
  qdsf.branch = options.branch
  qdsf.src_uri = options.src_uri
  qdsf.size = os.path.getsize(fn)
  qdsf.digest_type = "sha512"
  qdsf.digest = get_sha512(fn)
  with db.get_session() as session:
  	# get_sha512() can take a long time; session can time out.
  	session.add(qdsf)
  	session.commit()
  print("Injected file %s into queued distfiles." % fn)
  