[sysadmin-bin] update_sites.py: move locking logic to the function try_lock
- From: Olav Vitters <ovitters src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] update_sites.py: move locking logic to the function try_lock
- Date: Mon, 28 Feb 2011 14:02:10 +0000 (UTC)
commit b17d87598312fc65b72b5a9fc2ed5b69dd757fca
Author: Olav Vitters <olav vitters nl>
Date: Mon Feb 28 15:02:05 2011 +0100
update_sites.py: move locking logic to the function try_lock
gnomeweb/update_sites.py | 28 +++++++++++++++++-----------
1 files changed, 17 insertions(+), 11 deletions(-)
---
diff --git a/gnomeweb/update_sites.py b/gnomeweb/update_sites.py
index ffea221..306d619 100755
--- a/gnomeweb/update_sites.py
+++ b/gnomeweb/update_sites.py
@@ -113,6 +113,21 @@ def update_modules(configfile, configdir, verbose):
url = checkout_url % { 'module' : module }
update_module(module, module, moduleroot, url, owner, verbose=verbose)
+def try_lock(lock_file, verbose=False):
+ # Ensure only one copy will be running
+ fpl = open(lock_file, 'w')
+ try:
+ fcntl.flock(fpl, fcntl.LOCK_EX | fcntl.LOCK_NB)
+ except IOError:
+ if verbose:
+ print "Already running"
+ return None
+ fpl.write("%d" % os.getpid())
+ fpl.flush()
+ if verbose:
+ print "Wrote PID to lock file (PID: %d)" % os.getpid()
+
+ return fpl
def update_module(module, checkfile, moduleroot, url, owner, branch='master', verbose=False):
# Compare timestamps
@@ -139,18 +154,9 @@ def update_module(module, checkfile, moduleroot, url, owner, branch='master', ve
# If we get here, the module has either not been built before, or we're building again
- # Ensure only one copy will be running
- fpl = open(lock_file, 'w')
- try:
- fcntl.flock(fpl, fcntl.LOCK_EX | fcntl.LOCK_NB)
- except IOError:
- if verbose:
- print "Already running"
+ lock = try_lock(lock_file, verbose)
+ if lock is None:
return False
- fpl.write("%d" % os.getpid())
- fpl.flush()
- if verbose:
- print "Wrote PID to lock file (PID: %d)" % os.getpid()
if t_build is None:
t_build = os.stat(lock_file)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]