-def do_accept():
- print "ACCEPT";
- if not Options["No-Action"]:
- retry = 0;
- while retry < 10:
- try:
- lock_fd = os.open(Cnf["Lisa::AcceptedLockFile"], os.O_RDONLY | os.O_CREAT | os.O_EXCL);
- retry = 10;
- except OSError, e:
- if errno.errorcode[e.errno] == 'EACCES' or errno.errorcode[e.errno] == 'EEXIST':
- retry += 1;
- if (retry >= 10):
- utils.fubar("Couldn't obtain lock; assuming jennifer is already running.");
- else:
- print("Unable to get accepted lock (try %d of 10)" % retry);
- time.sleep(60);
- else:
- raise;
- (summary, short_summary) = Katie.build_summaries();
- Katie.accept(summary, short_summary);
- os.unlink(Katie.pkg.changes_file[:-8]+".katie");
- os.unlink(Cnf["Lisa::AcceptedLockFile"]);
-
-def check_status(files):
- new = byhand = 0;
- for file in files.keys():
- if files[file]["type"] == "byhand":
- byhand = 1;
- elif files[file].has_key("new"):
- new = 1;
- return (new, byhand);
-
-def do_pkg(changes_file):
- Katie.pkg.changes_file = changes_file;
- Katie.init_vars();
- Katie.update_vars();
- Katie.update_subst();
- files = Katie.pkg.files;
-
- if not recheck():
- return;
-
- (new, byhand) = check_status(files);
- if new or byhand:
- if new:
- do_new();
- if byhand:
- do_byhand();
- (new, byhand) = check_status(files);
-
- if not new and not byhand:
- do_accept();
+def check_daily_lock():
+ """
+ Raises CantGetLockError if the dinstall daily.lock exists.
+ """
+
+ cnf = Config()
+ try:
+ os.open(cnf["Process-New::DinstallLockFile"],
+ os.O_RDONLY | os.O_CREAT | os.O_EXCL)
+ except OSError, e:
+ if e.errno == errno.EEXIST or e.errno == errno.EACCES:
+ raise CantGetLockError
+
+ os.unlink(cnf["Process-New::DinstallLockFile"])
+
+
+@contextlib.contextmanager
+def lock_package(package):
+ """
+ Lock C{package} so that noone else jumps in processing it.
+
+ @type package: string
+ @param package: source package name to lock
+ """
+
+ path = os.path.join(Config()["Process-New::LockDir"], package)
+ try:
+ fd = os.open(path, os.O_CREAT | os.O_EXCL | os.O_RDONLY)
+ except OSError, e:
+ if e.errno == errno.EEXIST or e.errno == errno.EACCES:
+ user = pwd.getpwuid(os.stat(path)[stat.ST_UID])[4].split(',')[0].replace('.', '')
+ raise AlreadyLockedError, user
+
+ try:
+ yield fd
+ finally:
+ os.unlink(path)
+
+class clean_holding(object):
+ def __init__(self,pkg):
+ self.pkg = pkg
+
+ def __enter__(self):
+ pass
+
+ def __exit__(self, type, value, traceback):
+ h = Holding()
+
+ for f in self.pkg.files.keys():
+ if os.path.exists(os.path.join(h.holding_dir, f)):
+ os.unlink(os.path.join(h.holding_dir, f))
+
+
+def do_pkg(changes_file, session):
+ new_queue = get_policy_queue('new', session );
+ u = Upload()
+ u.pkg.changes_file = changes_file
+ (u.pkg.changes["fingerprint"], rejects) = utils.check_signature(changes_file)
+ u.load_changes(changes_file)
+ u.pkg.directory = new_queue.path
+ u.update_subst()
+ u.logger = Logger
+ origchanges = os.path.abspath(u.pkg.changes_file)
+
+ cnf = Config()
+ bcc = "X-DAK: dak process-new"
+ if cnf.has_key("Dinstall::Bcc"):
+ u.Subst["__BCC__"] = bcc + "\nBcc: %s" % (cnf["Dinstall::Bcc"])
+ else:
+ u.Subst["__BCC__"] = bcc
+
+ files = u.pkg.files
+ for deb_filename, f in files.items():
+ if deb_filename.endswith(".udeb") or deb_filename.endswith(".deb"):
+ u.binary_file_checks(deb_filename, session)
+ u.check_binary_against_db(deb_filename, session)
+ else:
+ u.source_file_checks(deb_filename, session)
+ u.check_source_against_db(deb_filename, session)
+
+ u.pkg.changes["suite"] = copy.copy(u.pkg.changes["distribution"])
+
+ try:
+ with lock_package(u.pkg.changes["source"]):
+ with clean_holding(u.pkg):
+ if not recheck(u, session):
+ return
+
+ # FIXME: This does need byhand checks added!
+ new = determine_new(u.pkg.changes, files)
+ if new:
+ do_new(u, session)
+ else:
+ try:
+ check_daily_lock()
+ new_accept(u, Options["No-Action"], session)
+ except CantGetLockError:
+ print "Hello? Operator! Give me the number for 911!"
+ print "Dinstall in the locked area, cant process packages, come back later"
+
+ except AlreadyLockedError, e:
+ print "Seems to be locked by %s already, skipping..." % (e)