1 |
commit: b07cf871939ce5dfea8e8a145ebca39c95e07439 |
2 |
Author: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Jul 1 16:08:11 2015 +0000 |
4 |
Commit: Anthony G. Basile <blueness <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Jul 1 16:08:11 2015 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/grss.git/commit/?id=b07cf871 |
7 |
|
8 |
Clean up makedirs(). |
9 |
|
10 |
makedirs() exist_ok=True. Use it to avoid FileExistsError. We |
11 |
are now logging exceptions vi stderr in Daemon.py, so let exceptions |
12 |
propagate up for debugging. |
13 |
|
14 |
grs/Kernel.py | 3 ++- |
15 |
grs/Log.py | 5 +---- |
16 |
grs/MountDirectories.py | 6 ++---- |
17 |
grs/Populate.py | 5 +---- |
18 |
grs/Seed.py | 5 +++-- |
19 |
5 files changed, 9 insertions(+), 15 deletions(-) |
20 |
|
21 |
diff --git a/grs/Kernel.py b/grs/Kernel.py |
22 |
index 7dd76fa..16d2247 100644 |
23 |
--- a/grs/Kernel.py |
24 |
+++ b/grs/Kernel.py |
25 |
@@ -96,7 +96,8 @@ class Kernel(): |
26 |
|
27 |
cwd = os.getcwd() |
28 |
os.chdir(image_dir) |
29 |
- os.unlink(tarball_path) |
30 |
+ if os.path.isfile(tarball_path): |
31 |
+ os.unlink(tarball_path) |
32 |
cmd = 'tar -Jcf %s .' % tarball_path |
33 |
Execute(cmd, timeout=600, logfile=self.logfile) |
34 |
os.chdir(cwd) |
35 |
|
36 |
diff --git a/grs/Log.py b/grs/Log.py |
37 |
index 91141e8..2a7ef9d 100644 |
38 |
--- a/grs/Log.py |
39 |
+++ b/grs/Log.py |
40 |
@@ -11,10 +11,7 @@ class Log(): |
41 |
|
42 |
def __init__(self, logfile = CONST.LOGFILE): |
43 |
self.logfile = logfile |
44 |
- try: |
45 |
- os.makedirs(os.path.dirname(self.logfile)) |
46 |
- except FileExistsError: |
47 |
- pass |
48 |
+ os.makedirs(os.path.dirname(self.logfile), exist_ok=True) |
49 |
open(self.logfile, 'a').close() |
50 |
|
51 |
|
52 |
|
53 |
diff --git a/grs/MountDirectories.py b/grs/MountDirectories.py |
54 |
index 43cd91a..16edc32 100644 |
55 |
--- a/grs/MountDirectories.py |
56 |
+++ b/grs/MountDirectories.py |
57 |
@@ -83,8 +83,7 @@ class MountDirectories(): |
58 |
# Here source_directory is assumet to be an abspath |
59 |
# and we create it if it doesn't exist |
60 |
source_directory = mount[0] |
61 |
- if not os.path.isdir(source_directory): |
62 |
- os.makedirs(source_directory) |
63 |
+ os.makedirs(source_directory, mode=0o755, exist_ok=True) |
64 |
target_directory = mount[1] |
65 |
elif isinstance(mount, dict): |
66 |
tmp = list(mount.values()) |
67 |
@@ -94,8 +93,7 @@ class MountDirectories(): |
68 |
tmp = list(mount.keys()) |
69 |
target_directory = tmp[0] |
70 |
target_directory = os.path.join(self.portage_configroot, target_directory) |
71 |
- if not os.path.isdir(target_directory): |
72 |
- os.makedirs(target_directory) |
73 |
+ os.makedirs(target_directory, mode=0o755, exist_ok=True) |
74 |
if isinstance(mount, str): |
75 |
cmd = 'mount --bind /%s %s' % (source_directory, target_directory) |
76 |
elif isinstance(mount, list): |
77 |
|
78 |
diff --git a/grs/Populate.py b/grs/Populate.py |
79 |
index 504283c..75b7ed8 100644 |
80 |
--- a/grs/Populate.py |
81 |
+++ b/grs/Populate.py |
82 |
@@ -34,10 +34,7 @@ class Populate(): |
83 |
Execute(cmd, timeout=60, logfile = self. logfile) |
84 |
|
85 |
# Add any extra files |
86 |
- try: |
87 |
- os.makedirs(self.etc) |
88 |
- except FileExistsError: |
89 |
- pass |
90 |
+ os.makedirs(self.etc, mode=0o755, exist_ok=True) |
91 |
with open(self.resolv_conf, 'w') as f: |
92 |
f.write('nameserver %s' % self.nameserver) |
93 |
|
94 |
|
95 |
diff --git a/grs/Seed.py b/grs/Seed.py |
96 |
index 0da8354..76034cc 100644 |
97 |
--- a/grs/Seed.py |
98 |
+++ b/grs/Seed.py |
99 |
@@ -50,8 +50,9 @@ class Seed(): |
100 |
if os.path.isdir(directory): |
101 |
shutil.move(directory, '%s.0' % directory) |
102 |
# Now that all prevous directory are out of the way, |
103 |
- # create a new empty directory |
104 |
- os.makedirs(directory) |
105 |
+ # create a new empty directory. Fail if the directory |
106 |
+ # is still around. |
107 |
+ os.makedirs(directory, mode=0o755, exist_ok=False) |
108 |
|
109 |
# Download a stage tarball if we don't have one |
110 |
if not os.path.isfile(self.filepath): |