-def get_accept_lock():
- retry = 0
- while retry < 10:
- try:
- lock_fd = os.open(Cnf["Process-New::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):
- daklib.utils.fubar("Couldn't obtain lock; assuming 'dak process-unchecked' is already running.")
- else:
- print("Unable to get accepted lock (try %d of 10)" % retry)
- time.sleep(60)
- else:
- raise
-
-def move_to_dir (dest, perms=0660, changesperms=0664):
- daklib.utils.move (Upload.pkg.changes_file, dest, perms=changesperms)
- file_keys = Upload.pkg.files.keys()
- for file in file_keys:
- daklib.utils.move (file, dest, perms=perms)
-
-def 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)
+
+def changes_to_unchecked(upload, session):
+ """move a changes file to unchecked"""
+ unchecked = get_policy_queue('unchecked', session );
+
+# changes.in_queue = unchecked
+
+ chg = session.query(DBChange).filter_by(changesname=os.path.basename(upload.pkg.changes_file)).one()
+ chg.approved_for = unchecked.policy_queue_id
+
+ for f in upload.pkg.files:
+ # update the changes_pending_files row
+ f.queue = unchecked
+
+ # actually move files
+ upload.move_to_queue(unchecked)
+
+def _accept(upload, session):
+ if Options["No-Action"]:
+ return
+ (summary, short_summary) = upload.build_summaries()
+# upload.accept(summary, short_summary, targetqueue)
+ changes_to_unchecked(upload, session)
+
+def do_accept(upload, session):