+def action(u, session):
+ cnf = Config()
+ holding = Holding()
+
+ # changes["distribution"] may not exist in corner cases
+ # (e.g. unreadable changes files)
+ if not u.pkg.changes.has_key("distribution") or not isinstance(u.pkg.changes["distribution"], dict):
+ u.pkg.changes["distribution"] = {}
+
+ (summary, short_summary) = u.build_summaries()
+
+ (prompt, answer) = ("", "XXX")
+ if Options["No-Action"] or Options["Automatic"]:
+ answer = 'S'
+
+ queuekey = ''
+
+ pi = u.package_info()
+
+ try:
+ chg = session.query(DBChange).filter_by(changesname=os.path.basename(u.pkg.changes_file)).one()
+ except NoResultFound, e:
+ chg = None
+
+ if len(u.rejects) > 0:
+ if u.upload_too_new():
+ print "SKIP (too new)\n" + pi,
+ prompt = "[S]kip, Quit ?"
+ else:
+ print "REJECT\n" + pi
+ prompt = "[R]eject, Skip, Quit ?"
+ if Options["Automatic"]:
+ answer = 'R'
+ else:
+ # Are we headed for NEW / BYHAND / AUTOBYHAND?
+ # Note that policy queues are no longer handled here
+ qu = determine_target(u)
+ if qu:
+ print "%s for %s\n%s%s" % ( qu.upper(), ", ".join(u.pkg.changes["distribution"].keys()), pi, summary)
+ queuekey = qu[0].upper()
+ if queuekey in "RQSA":
+ queuekey = "D"
+ prompt = "[D]ivert, Skip, Quit ?"
+ else:
+ prompt = "[%s]%s, Skip, Quit ?" % (queuekey, qu[1:].lower())
+ if Options["Automatic"]:
+ answer = queuekey
+ else:
+ # Does suite have a policy_queue configured
+ divert = False
+ for s in u.pkg.changes["distribution"].keys():
+ suite = get_suite(s, session)
+ if suite.policy_queue:
+ if not chg or chg.approved_for_id != su.policy_queue.policy_queue_id:
+ # This routine will check whether the upload is a binary
+ # upload when the source is already in the target suite. If
+ # so, we skip the policy queue, otherwise we go there.
+ divert = package_to_suite(u, suite.suite_name, session=session)
+ if divert:
+ print "%s for %s\n%s%s" % ( suite.policy_queue.queue_name.upper(),
+ ", ".join(u.pkg.changes["distribution"].keys()),
+ pi, summary)
+ queuekey = "P"
+ prompt = "[P]olicy, Skip, Quit ?"
+ policyqueue = suite.policy_queue
+ if Options["Automatic"]:
+ answer = 'P'
+ break
+
+ if not divert:
+ print "ACCEPT\n" + pi + summary,
+ prompt = "[A]ccept, Skip, Quit ?"
+ if Options["Automatic"]:
+ answer = 'A'
+
+ while prompt.find(answer) == -1:
+ answer = utils.our_raw_input(prompt)
+ m = re_default_answer.match(prompt)
+ if answer == "":
+ answer = m.group(1)
+ answer = answer[:1].upper()
+
+ if answer == 'R':
+ os.chdir(u.pkg.directory)
+ u.do_reject(0, pi)
+ elif answer == 'A':
+ if not chg:
+ chg = u.pkg.add_known_changes(holding.holding_dir, session=session)
+ u.accept(summary, short_summary, session)
+ u.check_override()
+ chg.clean_from_queue()
+ session.commit()
+ u.remove()
+ elif answer == 'P':
+ if not chg:
+ chg = u.pkg.add_known_changes(holding.holding_dir, session=session)
+ package_to_queue(u, summary, short_summary, policyqueue, chg, session)
+ chg.upload_into_db(u, holding.holding_dir)
+ session.commit()
+ u.remove()
+ elif answer == queuekey:
+ if not chg:
+ chg = u.pkg.add_known_changes(holding.holding_dir, session=session)
+ QueueInfo[qu]["process"](u, summary, short_summary, chg, session)
+ chg.upload_into_db(u, holding.holding_dir)
+ session.commit()
+ u.remove()
+ elif answer == 'Q':
+ sys.exit(0)
+
+ session.commit()
+
+###############################################################################
+
+def cleanup():
+ h = Holding()
+ if not Options["No-Action"]:
+ h.clean()
+
+def process_it(changes_file, session):