Gentoo Archives: gentoo-commits

From: Brian Dolbec <dolsen@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/catalyst:master commit in: catalyst/
Date: Thu, 26 Feb 2015 04:12:07
Message-Id: 1420091885.cd9ed84add5379f07f46faea102f24ec51754f54.dolsen@gentoo
1 commit: cd9ed84add5379f07f46faea102f24ec51754f54
2 Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
3 AuthorDate: Sun Jan 20 01:50:26 2013 +0000
4 Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
5 CommitDate: Thu Jan 1 05:58:05 2015 +0000
6 URL: http://sources.gentoo.org/gitweb/?p=proj/catalyst.git;a=commit;h=cd9ed84a
7
8 Move LockInUse from support.py to lock.py, fix bad execption raising, pyflakes cleanup
9
10 ---
11 catalyst/lock.py | 55 ++++++++++++++++++++++++++++++-----------------------
12 catalyst/main.py | 3 ++-
13 catalyst/support.py | 11 -----------
14 3 files changed, 33 insertions(+), 36 deletions(-)
15
16 diff --git a/catalyst/lock.py b/catalyst/lock.py
17 index 2d10d2f..78968cb 100644
18 --- a/catalyst/lock.py
19 +++ b/catalyst/lock.py
20 @@ -3,14 +3,26 @@ import os
21 import fcntl
22 import errno
23 import sys
24 -import string
25 import time
26 -from catalyst.support import *
27 +from catalyst.support import CatalystError, normpath
28
29 def writemsg(mystr):
30 sys.stderr.write(mystr)
31 sys.stderr.flush()
32
33 +
34 +class LockInUse(Exception):
35 + def __init__(self, message):
36 + if message:
37 + #(type,value)=sys.exc_info()[:2]
38 + #if value!=None:
39 + #print
40 + #kprint traceback.print_exc(file=sys.stdout)
41 + print
42 + print "!!! catalyst lock file in use: "+message
43 + print
44 +
45 +
46 class LockDir:
47 locking_method=fcntl.flock
48 lock_dirs_in_use=[]
49 @@ -109,7 +121,8 @@ class LockDir:
50 def fcntl_lock(self,locktype):
51 if self.myfd==None:
52 if not os.path.exists(os.path.dirname(self.lockdir)):
53 - raise DirectoryNotFound, os.path.dirname(self.lockdir)
54 + raise CatalystError("DirectoryNotFound: %s"
55 + % os.path.dirname(self.lockdir))
56 if not os.path.exists(self.lockfile):
57 old_mask=os.umask(000)
58 self.myfd = os.open(self.lockfile, os.O_CREAT|os.O_RDWR,0660)
59 @@ -168,7 +181,7 @@ class LockDir:
60 print "lockfile does not exist '%s'" % self.lockfile
61 if (self.myfd != None):
62 try:
63 - os.close(myfd)
64 + os.close(self.myfd)
65 self.myfd=None
66 except:
67 pass
68 @@ -251,12 +264,13 @@ class LockDir:
69
70 self.add_hardlock_file_to_cleanup()
71 if not os.path.exists(self.myhardlock):
72 - raise FileNotFound, "Created lockfile is missing: %(filename)s" % {"filename":self.myhardlock}
73 + raise CatalystError("FileNotFound: Created lockfile is missing: "
74 + "%(filename)s" % {"filename":self.myhardlock})
75 try:
76 - res = os.link(self.myhardlock, self.lockfile)
77 - except SystemExit, e:
78 + os.link(self.myhardlock, self.lockfile)
79 + except SystemExit:
80 raise
81 - except Exception, e:
82 + except Exception:
83 # if "DEBUG" in self.settings:
84 # print "lockfile(): Hardlink: Link failed."
85 # print "Exception: ",e
86 @@ -286,7 +300,7 @@ class LockDir:
87 os.unlink(self.myhardlock)
88 if os.path.exists(self.lockfile):
89 os.unlink(self.lockfile)
90 - except SystemExit, e:
91 + except SystemExit:
92 raise
93 except:
94 writemsg("Something strange happened to our hardlink locks.\n")
95 @@ -314,7 +328,7 @@ class LockDir:
96 try:
97 myhls = os.stat(link)
98 mylfs = os.stat(lock)
99 - except SystemExit, e:
100 + except SystemExit:
101 raise
102 except:
103 myhls = None
104 @@ -340,7 +354,7 @@ class LockDir:
105 pass
106
107 def hardlock_cleanup(self,path):
108 - mypid = str(os.getpid())
109 + #mypid = str(os.getpid())
110 myhost = os.uname()[1]
111 mydl = os.listdir(path)
112 results = []
113 @@ -384,26 +398,26 @@ class LockDir:
114 # We're sweeping through, unlinking everyone's locks.
115 os.unlink(filename)
116 results.append("Unlinked: " + filename)
117 - except SystemExit, e:
118 + except SystemExit:
119 raise
120 - except Exception,e:
121 + except Exception:
122 pass
123 try:
124 os.unlink(x)
125 results.append("Unlinked: " + x)
126 os.unlink(mylockname)
127 results.append("Unlinked: " + mylockname)
128 - except SystemExit, e:
129 + except SystemExit:
130 raise
131 - except Exception,e:
132 + except Exception:
133 pass
134 else:
135 try:
136 os.unlink(mylockname)
137 results.append("Unlinked: " + mylockname)
138 - except SystemExit, e:
139 + except SystemExit:
140 raise
141 - except Exception,e:
142 + except Exception:
143 pass
144 return results
145
146 @@ -415,15 +429,8 @@ if __name__ == "__main__":
147 print i,time.time()
148 time.sleep(1)
149 print
150 - def normpath(mypath):
151 - newpath = os.path.normpath(mypath)
152 - if len(newpath) > 1:
153 - if newpath[1] == "/":
154 - newpath = "/"+newpath.lstrip("/")
155 - return newpath
156
157 print "Lock 5 starting"
158 - import time
159 Lock1=LockDir("/tmp/lock_path")
160 Lock1.write_lock()
161 print "Lock1 write lock"
162
163 diff --git a/catalyst/main.py b/catalyst/main.py
164 index 81d48b5..15664de 100644
165 --- a/catalyst/main.py
166 +++ b/catalyst/main.py
167 @@ -21,7 +21,8 @@ sys.path.append(__selfpath__ + "/modules")
168 from . import __version__
169 import catalyst.config
170 import catalyst.util
171 -from catalyst.support import CatalystError, find_binary, LockInUse
172 +from catalyst.lock import LockInUse
173 +from catalyst.support import CatalystError, find_binary
174 from catalyst.defaults import (confdefaults, option_messages,
175 required_build_targets, valid_build_targets)
176 from hash_utils import HashMap, HASH_DEFINITIONS
177
178 diff --git a/catalyst/support.py b/catalyst/support.py
179 index d5dbfec..feaa645 100644
180 --- a/catalyst/support.py
181 +++ b/catalyst/support.py
182 @@ -115,17 +115,6 @@ class CatalystError(Exception):
183 print "!!! catalyst: "+message
184 print
185
186 -class LockInUse(Exception):
187 - def __init__(self, message):
188 - if message:
189 - #(type,value)=sys.exc_info()[:2]
190 - #if value!=None:
191 - #print
192 - #kprint traceback.print_exc(file=sys.stdout)
193 - print
194 - print "!!! catalyst lock file in use: "+message
195 - print
196 -
197 def die(msg=None):
198 warn(msg)
199 sys.exit(1)