Gentoo Archives: gentoo-commits

From: "Anthony G. Basile" <blueness@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/grss:master commit in: grs/
Date: Wed, 01 Jul 2015 16:52:13
Message-Id: 1435769667.453e36867eb79ec1989f241caf15552c04b49de4.blueness@gentoo
1 commit: 453e36867eb79ec1989f241caf15552c04b49de4
2 Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
3 AuthorDate: Wed Jul 1 16:54:27 2015 +0000
4 Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org>
5 CommitDate: Wed Jul 1 16:54:27 2015 +0000
6 URL: https://gitweb.gentoo.org/proj/grss.git/commit/?id=453e3686
7
8 Clean up more exceptions.
9
10 grs/Execute.py | 12 ++++++------
11 grs/Populate.py | 11 +++--------
12 grs/Seed.py | 13 +++----------
13 3 files changed, 12 insertions(+), 24 deletions(-)
14
15 diff --git a/grs/Execute.py b/grs/Execute.py
16 index 533d269..15fe562 100644
17 --- a/grs/Execute.py
18 +++ b/grs/Execute.py
19 @@ -19,17 +19,17 @@ class Execute():
20 pid = os.getpid()
21 f.write('SENDING SIGTERM to pid = %d\n' % pid)
22 f.close()
23 - os.kill(pid, signal.SIGTERM)
24 + try:
25 + os.kill(pid, signal.SIGTERM)
26 + os.kill(pid, signal.SIGKILL)
27 + except ProcessLookupError:
28 + pass
29
30 f = open(logfile, 'a')
31 args = shlex.split(cmd)
32 extra_env = dict(os.environ, **extra_env)
33
34 - try:
35 - proc = subprocess.Popen(args, stdout=f, stderr=f, env=extra_env)
36 - except FileNotFoundError:
37 - f.write('Illegal cmd %s\n' % cmd)
38 - signalexit()
39 + proc = subprocess.Popen(args, stdout=f, stderr=f, env=extra_env)
40
41 try:
42 proc.wait(timeout)
43
44 diff --git a/grs/Populate.py b/grs/Populate.py
45 index 75b7ed8..f01c424 100644
46 --- a/grs/Populate.py
47 +++ b/grs/Populate.py
48 @@ -68,23 +68,18 @@ class Populate():
49
50 def clean_subdirs(self, dirpath):
51 path = os.path.join(self.portage_configroot, dirpath)
52 - try:
53 + if os.path.isdir(path)
54 uid = os.stat(path).st_uid
55 gid = os.stat(path).st_gid
56 mode = os.stat(path).st_mode
57 shutil.rmtree(path)
58 - os.mkdir(path)
59 + os.makedirs(path, mode=mode, exist_ok=False)
60 os.chown(path, uid, gid)
61 - os.chmod(path, mode)
62 - except FileNotFoundError:
63 - pass
64
65
66 def clean(self):
67 self.clean_subdirs('tmp')
68 self.clean_subdirs('var/tmp')
69 self.clean_subdirs('var/log')
70 - try:
71 + if os.path.isfile(self.resolv_conf):
72 os.unlink(self.resolv_conf)
73 - except FileNotFoundError:
74 - pass
75
76 diff --git a/grs/Seed.py b/grs/Seed.py
77 index 76034cc..4ac95ed 100644
78 --- a/grs/Seed.py
79 +++ b/grs/Seed.py
80 @@ -56,16 +56,9 @@ class Seed():
81
82 # Download a stage tarball if we don't have one
83 if not os.path.isfile(self.filepath):
84 - try:
85 - request = urllib.request.urlopen(self.stage_uri)
86 - with open(self.filepath, 'wb') as f:
87 - shutil.copyfileobj(request, f)
88 - except: #any exception will do here
89 - pid = os.getpid()
90 - with open(self.logfile, 'r') as f:
91 - f.write('SENDING SIGTERM to pid = %d\n' % pid)
92 - f.close()
93 - os.kill(pid, signal.SIGTERM)
94 + request = urllib.request.urlopen(self.stage_uri)
95 + with open(self.filepath, 'wb') as f:
96 + shutil.copyfileobj(request, f)
97
98 # Because python's tarfile sucks
99 cmd = 'tar --xattrs -xf %s -C %s' % (self.filepath, self.portage_configroot)