From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 83FCD13838B for ; Thu, 11 Sep 2014 03:43:55 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 099E9E09F6; Thu, 11 Sep 2014 03:43:53 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 558A7E09E8 for ; Thu, 11 Sep 2014 03:43:52 +0000 (UTC) Received: from big_daddy.dol-sen.ca (S010600222de111ff.vc.shawcable.net [96.49.5.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: dolsen) by smtp.gentoo.org (Postfix) with ESMTPSA id 592B13401BA for ; Thu, 11 Sep 2014 03:43:51 +0000 (UTC) From: Brian Dolbec To: gentoo-catalyst@lists.gentoo.org Subject: [gentoo-catalyst] [PATCH 2/5] Move LockInUse from support.py to lock.py, fix bad execption raising, pyflakes cleanup Date: Wed, 10 Sep 2014 20:43:41 -0700 Message-Id: <1410407024-2445-3-git-send-email-dolsen@gentoo.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1410407024-2445-1-git-send-email-dolsen@gentoo.org> References: <1410407024-2445-1-git-send-email-dolsen@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-catalyst@lists.gentoo.org Reply-to: gentoo-catalyst@lists.gentoo.org X-Archives-Salt: 2dd311a8-a2f9-4a19-a316-d4678d5dac5e X-Archives-Hash: 635434ba383ee135cd879170020f90c3 --- catalyst/lock.py | 55 ++++++++++++++++++++++++++++++----------------------- catalyst/main.py | 3 ++- catalyst/support.py | 11 ----------- 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/catalyst/lock.py b/catalyst/lock.py index 2d10d2f..78968cb 100644 --- a/catalyst/lock.py +++ b/catalyst/lock.py @@ -3,14 +3,26 @@ import os import fcntl import errno import sys -import string import time -from catalyst.support import * +from catalyst.support import CatalystError, normpath def writemsg(mystr): sys.stderr.write(mystr) sys.stderr.flush() + +class LockInUse(Exception): + def __init__(self, message): + if message: + #(type,value)=sys.exc_info()[:2] + #if value!=None: + #print + #kprint traceback.print_exc(file=sys.stdout) + print + print "!!! catalyst lock file in use: "+message + print + + class LockDir: locking_method=fcntl.flock lock_dirs_in_use=[] @@ -109,7 +121,8 @@ class LockDir: def fcntl_lock(self,locktype): if self.myfd==None: if not os.path.exists(os.path.dirname(self.lockdir)): - raise DirectoryNotFound, os.path.dirname(self.lockdir) + raise CatalystError("DirectoryNotFound: %s" + % os.path.dirname(self.lockdir)) if not os.path.exists(self.lockfile): old_mask=os.umask(000) self.myfd = os.open(self.lockfile, os.O_CREAT|os.O_RDWR,0660) @@ -168,7 +181,7 @@ class LockDir: print "lockfile does not exist '%s'" % self.lockfile if (self.myfd != None): try: - os.close(myfd) + os.close(self.myfd) self.myfd=None except: pass @@ -251,12 +264,13 @@ class LockDir: self.add_hardlock_file_to_cleanup() if not os.path.exists(self.myhardlock): - raise FileNotFound, "Created lockfile is missing: %(filename)s" % {"filename":self.myhardlock} + raise CatalystError("FileNotFound: Created lockfile is missing: " + "%(filename)s" % {"filename":self.myhardlock}) try: - res = os.link(self.myhardlock, self.lockfile) - except SystemExit, e: + os.link(self.myhardlock, self.lockfile) + except SystemExit: raise - except Exception, e: + except Exception: # if "DEBUG" in self.settings: # print "lockfile(): Hardlink: Link failed." # print "Exception: ",e @@ -286,7 +300,7 @@ class LockDir: os.unlink(self.myhardlock) if os.path.exists(self.lockfile): os.unlink(self.lockfile) - except SystemExit, e: + except SystemExit: raise except: writemsg("Something strange happened to our hardlink locks.\n") @@ -314,7 +328,7 @@ class LockDir: try: myhls = os.stat(link) mylfs = os.stat(lock) - except SystemExit, e: + except SystemExit: raise except: myhls = None @@ -340,7 +354,7 @@ class LockDir: pass def hardlock_cleanup(self,path): - mypid = str(os.getpid()) + #mypid = str(os.getpid()) myhost = os.uname()[1] mydl = os.listdir(path) results = [] @@ -384,26 +398,26 @@ class LockDir: # We're sweeping through, unlinking everyone's locks. os.unlink(filename) results.append("Unlinked: " + filename) - except SystemExit, e: + except SystemExit: raise - except Exception,e: + except Exception: pass try: os.unlink(x) results.append("Unlinked: " + x) os.unlink(mylockname) results.append("Unlinked: " + mylockname) - except SystemExit, e: + except SystemExit: raise - except Exception,e: + except Exception: pass else: try: os.unlink(mylockname) results.append("Unlinked: " + mylockname) - except SystemExit, e: + except SystemExit: raise - except Exception,e: + except Exception: pass return results @@ -415,15 +429,8 @@ if __name__ == "__main__": print i,time.time() time.sleep(1) print - def normpath(mypath): - newpath = os.path.normpath(mypath) - if len(newpath) > 1: - if newpath[1] == "/": - newpath = "/"+newpath.lstrip("/") - return newpath print "Lock 5 starting" - import time Lock1=LockDir("/tmp/lock_path") Lock1.write_lock() print "Lock1 write lock" diff --git a/catalyst/main.py b/catalyst/main.py index 81d48b5..15664de 100644 --- a/catalyst/main.py +++ b/catalyst/main.py @@ -21,7 +21,8 @@ sys.path.append(__selfpath__ + "/modules") from . import __version__ import catalyst.config import catalyst.util -from catalyst.support import CatalystError, find_binary, LockInUse +from catalyst.lock import LockInUse +from catalyst.support import CatalystError, find_binary from catalyst.defaults import (confdefaults, option_messages, required_build_targets, valid_build_targets) from hash_utils import HashMap, HASH_DEFINITIONS diff --git a/catalyst/support.py b/catalyst/support.py index d5dbfec..feaa645 100644 --- a/catalyst/support.py +++ b/catalyst/support.py @@ -115,17 +115,6 @@ class CatalystError(Exception): print "!!! catalyst: "+message print -class LockInUse(Exception): - def __init__(self, message): - if message: - #(type,value)=sys.exc_info()[:2] - #if value!=None: - #print - #kprint traceback.print_exc(file=sys.stdout) - print - print "!!! catalyst lock file in use: "+message - print - def die(msg=None): warn(msg) sys.exit(1) -- 2.1.0