commit: 453e36867eb79ec1989f241caf15552c04b49de4 Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org> AuthorDate: Wed Jul 1 16:54:27 2015 +0000 Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org> CommitDate: Wed Jul 1 16:54:27 2015 +0000 URL: https://gitweb.gentoo.org/proj/grss.git/commit/?id=453e3686
Clean up more exceptions. grs/Execute.py | 12 ++++++------ grs/Populate.py | 11 +++-------- grs/Seed.py | 13 +++---------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/grs/Execute.py b/grs/Execute.py index 533d269..15fe562 100644 --- a/grs/Execute.py +++ b/grs/Execute.py @@ -19,17 +19,17 @@ class Execute(): pid = os.getpid() f.write('SENDING SIGTERM to pid = %d\n' % pid) f.close() - os.kill(pid, signal.SIGTERM) + try: + os.kill(pid, signal.SIGTERM) + os.kill(pid, signal.SIGKILL) + except ProcessLookupError: + pass f = open(logfile, 'a') args = shlex.split(cmd) extra_env = dict(os.environ, **extra_env) - try: - proc = subprocess.Popen(args, stdout=f, stderr=f, env=extra_env) - except FileNotFoundError: - f.write('Illegal cmd %s\n' % cmd) - signalexit() + proc = subprocess.Popen(args, stdout=f, stderr=f, env=extra_env) try: proc.wait(timeout) diff --git a/grs/Populate.py b/grs/Populate.py index 75b7ed8..f01c424 100644 --- a/grs/Populate.py +++ b/grs/Populate.py @@ -68,23 +68,18 @@ class Populate(): def clean_subdirs(self, dirpath): path = os.path.join(self.portage_configroot, dirpath) - try: + if os.path.isdir(path) uid = os.stat(path).st_uid gid = os.stat(path).st_gid mode = os.stat(path).st_mode shutil.rmtree(path) - os.mkdir(path) + os.makedirs(path, mode=mode, exist_ok=False) os.chown(path, uid, gid) - os.chmod(path, mode) - except FileNotFoundError: - pass def clean(self): self.clean_subdirs('tmp') self.clean_subdirs('var/tmp') self.clean_subdirs('var/log') - try: + if os.path.isfile(self.resolv_conf): os.unlink(self.resolv_conf) - except FileNotFoundError: - pass diff --git a/grs/Seed.py b/grs/Seed.py index 76034cc..4ac95ed 100644 --- a/grs/Seed.py +++ b/grs/Seed.py @@ -56,16 +56,9 @@ class Seed(): # Download a stage tarball if we don't have one if not os.path.isfile(self.filepath): - try: - request = urllib.request.urlopen(self.stage_uri) - with open(self.filepath, 'wb') as f: - shutil.copyfileobj(request, f) - except: #any exception will do here - pid = os.getpid() - with open(self.logfile, 'r') as f: - f.write('SENDING SIGTERM to pid = %d\n' % pid) - f.close() - os.kill(pid, signal.SIGTERM) + request = urllib.request.urlopen(self.stage_uri) + with open(self.filepath, 'wb') as f: + shutil.copyfileobj(request, f) # Because python's tarfile sucks cmd = 'tar --xattrs -xf %s -C %s' % (self.filepath, self.portage_configroot)