diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2015-07-01 12:54:27 -0400 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2015-07-01 12:54:27 -0400 |
commit | 453e36867eb79ec1989f241caf15552c04b49de4 (patch) | |
tree | a11823691c0e4dedf9617c2e99dccb2860ce12f7 /grs | |
parent | Clean up makedirs(). (diff) | |
download | grss-453e36867eb79ec1989f241caf15552c04b49de4.tar.gz grss-453e36867eb79ec1989f241caf15552c04b49de4.tar.bz2 grss-453e36867eb79ec1989f241caf15552c04b49de4.zip |
Clean up more exceptions.
Diffstat (limited to 'grs')
-rw-r--r-- | grs/Execute.py | 12 | ||||
-rw-r--r-- | grs/Populate.py | 11 | ||||
-rw-r--r-- | 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) |