1 |
commit: dd3d5a4138662836243e1686167708f98fe2bf0b |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue Oct 6 14:02:42 2015 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Oct 6 14:02:42 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=dd3d5a41 |
7 |
|
8 |
lint: clean up bare exception handling |
9 |
|
10 |
It's a bad idea to use a bare except clause as you end up including |
11 |
things like SystemExit, KeyboardInterrupt, and GeneratorExit, none |
12 |
of which we actually want to catch. Some of the cases in the code |
13 |
were explicitly catching & passing SystemExit back up which proves |
14 |
this point. |
15 |
|
16 |
catalyst/base/stagebase.py | 2 +- |
17 |
catalyst/lock.py | 26 ++++---------------------- |
18 |
catalyst/main.py | 2 +- |
19 |
catalyst/support.py | 15 +++++---------- |
20 |
targets/stage1/build.py | 2 +- |
21 |
5 files changed, 12 insertions(+), 35 deletions(-) |
22 |
|
23 |
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py |
24 |
index 409fcab..e393c5b 100644 |
25 |
--- a/catalyst/base/stagebase.py |
26 |
+++ b/catalyst/base/stagebase.py |
27 |
@@ -1015,7 +1015,7 @@ class StageBase(TargetBase, ClearBase, GenBase): |
28 |
target is fully initialized |
29 |
""" |
30 |
self.snapshot_lock_object.unlock() |
31 |
- except: |
32 |
+ except Exception: |
33 |
pass |
34 |
if ouch: |
35 |
""" |
36 |
|
37 |
diff --git a/catalyst/lock.py b/catalyst/lock.py |
38 |
index 01b1aa8..d6653f7 100644 |
39 |
--- a/catalyst/lock.py |
40 |
+++ b/catalyst/lock.py |
41 |
@@ -130,8 +130,6 @@ class LockDir(object): |
42 |
try: |
43 |
if os.stat(self.lockfile).st_gid != self.gid: |
44 |
os.chown(self.lockfile,os.getuid(),self.gid) |
45 |
- except SystemExit, e: |
46 |
- raise |
47 |
except OSError, e: |
48 |
if e[0] == 2: #XXX: No such file or directory |
49 |
return self.fcntl_locking(locktype) |
50 |
@@ -185,7 +183,7 @@ class LockDir(object): |
51 |
try: |
52 |
os.close(self.myfd) |
53 |
self.myfd=None |
54 |
- except: |
55 |
+ except Exception: |
56 |
pass |
57 |
return False |
58 |
|
59 |
@@ -194,8 +192,6 @@ class LockDir(object): |
60 |
self.myfd = os.open(self.lockfile, os.O_WRONLY,0660) |
61 |
unlinkfile = 1 |
62 |
self.locking_method(self.myfd,fcntl.LOCK_UN) |
63 |
- except SystemExit, e: |
64 |
- raise e |
65 |
except Exception, e: |
66 |
#if self.myfd is not None: |
67 |
#print "fcntl_unlock() trying to close", self.myfd |
68 |
@@ -213,7 +209,7 @@ class LockDir(object): |
69 |
InUse=False |
70 |
try: |
71 |
self.locking_method(self.myfd,fcntl.LOCK_EX|fcntl.LOCK_NB) |
72 |
- except: |
73 |
+ except Exception: |
74 |
print "Read lock may be in effect. skipping lockfile delete..." |
75 |
InUse=True |
76 |
# We won the lock, so there isn't competition for it. |
77 |
@@ -227,8 +223,6 @@ class LockDir(object): |
78 |
self.myfd=None |
79 |
# if "DEBUG" in self.settings: |
80 |
# print "Unlinked lockfile..." |
81 |
- except SystemExit, e: |
82 |
- raise e |
83 |
except Exception, e: |
84 |
# We really don't care... Someone else has the lock. |
85 |
# So it is their problem now. |
86 |
@@ -273,8 +267,6 @@ class LockDir(object): |
87 |
print_traceback=True) |
88 |
try: |
89 |
os.link(self.myhardlock, self.lockfile) |
90 |
- except SystemExit: |
91 |
- raise |
92 |
except Exception: |
93 |
# if "DEBUG" in self.settings: |
94 |
# print "lockfile(): Hardlink: Link failed." |
95 |
@@ -305,9 +297,7 @@ class LockDir(object): |
96 |
os.unlink(self.myhardlock) |
97 |
if os.path.exists(self.lockfile): |
98 |
os.unlink(self.lockfile) |
99 |
- except SystemExit: |
100 |
- raise |
101 |
- except: |
102 |
+ except Exception: |
103 |
writemsg("Something strange happened to our hardlink locks.\n") |
104 |
|
105 |
def add_hardlock_file_to_cleanup(self): |
106 |
@@ -335,9 +325,7 @@ class LockDir(object): |
107 |
try: |
108 |
myhls = os.stat(link) |
109 |
mylfs = os.stat(lock) |
110 |
- except SystemExit: |
111 |
- raise |
112 |
- except: |
113 |
+ except Exception: |
114 |
myhls = None |
115 |
mylfs = None |
116 |
|
117 |
@@ -406,8 +394,6 @@ class LockDir(object): |
118 |
# We're sweeping through, unlinking everyone's locks. |
119 |
os.unlink(filename) |
120 |
results.append("Unlinked: " + filename) |
121 |
- except SystemExit: |
122 |
- raise |
123 |
except Exception: |
124 |
pass |
125 |
try: |
126 |
@@ -415,16 +401,12 @@ class LockDir(object): |
127 |
results.append("Unlinked: " + x) |
128 |
os.unlink(mylockname) |
129 |
results.append("Unlinked: " + mylockname) |
130 |
- except SystemExit: |
131 |
- raise |
132 |
except Exception: |
133 |
pass |
134 |
else: |
135 |
try: |
136 |
os.unlink(mylockname) |
137 |
results.append("Unlinked: " + mylockname) |
138 |
- except SystemExit: |
139 |
- raise |
140 |
except Exception: |
141 |
pass |
142 |
return results |
143 |
|
144 |
diff --git a/catalyst/main.py b/catalyst/main.py |
145 |
index 04f689e..4e83414 100644 |
146 |
--- a/catalyst/main.py |
147 |
+++ b/catalyst/main.py |
148 |
@@ -95,7 +95,7 @@ def parse_config(myconfig): |
149 |
myconfig = catalyst.config.ConfigParser(config_file) |
150 |
myconf.update(myconfig.get_values()) |
151 |
|
152 |
- except: |
153 |
+ except Exception: |
154 |
print "!!! catalyst: Unable to parse configuration file, "+myconfig |
155 |
sys.exit(1) |
156 |
|
157 |
|
158 |
diff --git a/catalyst/support.py b/catalyst/support.py |
159 |
index 90c59eb..f184ed7 100644 |
160 |
--- a/catalyst/support.py |
161 |
+++ b/catalyst/support.py |
162 |
@@ -22,9 +22,7 @@ DESIRED_RLIMIT = 0 |
163 |
try: |
164 |
import resource |
165 |
max_fd_limit=resource.getrlimit(resource.RLIMIT_NOFILE)[DESIRED_RLIMIT] |
166 |
-except SystemExit, e: |
167 |
- raise |
168 |
-except: |
169 |
+except Exception: |
170 |
# hokay, no resource module. |
171 |
max_fd_limit=256 |
172 |
|
173 |
@@ -48,7 +46,7 @@ def read_from_clst(path): |
174 |
myline = '' |
175 |
try: |
176 |
myf = open(path, "r") |
177 |
- except: |
178 |
+ except Exception: |
179 |
return -1 |
180 |
#raise CatalystError("Could not open file " + path) |
181 |
for line in myf.readlines(): |
182 |
@@ -136,10 +134,7 @@ def cmd(mycmd, myexc="", env=None, debug=False, fail_func=None): |
183 |
|
184 |
if debug: |
185 |
print "***** cmd(); args =", args |
186 |
- try: |
187 |
- proc = Popen(args, env=env) |
188 |
- except: |
189 |
- raise |
190 |
+ proc = Popen(args, env=env) |
191 |
if proc.wait() != 0: |
192 |
if fail_func: |
193 |
print "CMD(), NON-Zero command return. Running fail_func()" |
194 |
@@ -243,7 +238,7 @@ def read_makeconf(mymakeconffile): |
195 |
try: |
196 |
import portage.util |
197 |
return portage.util.getconfig(mymakeconffile, tolerant=1, allow_sourcing=True) |
198 |
- except: |
199 |
+ except Exception: |
200 |
try: |
201 |
import portage_util |
202 |
return portage_util.getconfig(mymakeconffile, tolerant=1, allow_sourcing=True) |
203 |
@@ -252,7 +247,7 @@ def read_makeconf(mymakeconffile): |
204 |
mylines=myf.readlines() |
205 |
myf.close() |
206 |
return parse_makeconf(mylines) |
207 |
- except: |
208 |
+ except Exception: |
209 |
raise CatalystError("Could not parse make.conf file " + |
210 |
mymakeconffile, print_traceback=True) |
211 |
else: |
212 |
|
213 |
diff --git a/targets/stage1/build.py b/targets/stage1/build.py |
214 |
index be1bc4d..fa4fd13 100755 |
215 |
--- a/targets/stage1/build.py |
216 |
+++ b/targets/stage1/build.py |
217 |
@@ -33,7 +33,7 @@ for idx in range(0, len(pkgs)): |
218 |
buildpkgs[bidx] = pkgs[idx] |
219 |
if buildpkgs[bidx][0:1] == "*": |
220 |
buildpkgs[bidx] = buildpkgs[bidx][1:] |
221 |
- except: |
222 |
+ except Exception: |
223 |
pass |
224 |
|
225 |
for b in buildpkgs: |