diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2013-06-06 10:06:22 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2013-06-06 10:06:22 +0000 |
commit | 367470bdbba737b6253c270de36cd583e4a3421e (patch) | |
tree | 06557aa4066a953010788392f996a212ca321cd8 /morphlib/app.py | |
parent | 30f53a3023fe978bf757d84d36be712e5fa2a126 (diff) | |
download | morph-367470bdbba737b6253c270de36cd583e4a3421e.tar.gz |
Shorten create_if_not_exists logic
I find the loop easier to read since there's less redundancy.
Also less code to maintain.
Note that tmpdir is not explicitly created, since makedirs of one
of its subdirectories will handle that.
Diffstat (limited to 'morphlib/app.py')
-rw-r--r-- | morphlib/app.py | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/morphlib/app.py b/morphlib/app.py index 9ae177f5..fcf54118 100644 --- a/morphlib/app.py +++ b/morphlib/app.py @@ -223,18 +223,14 @@ class Morph(cliapp.Application): self.settings.dump_config(sys.stdout) sys.exit(0) - def create_dir_if_not_exists(dir): - if not os.path.exists(dir): - os.makedirs(dir) - tmpdir = self.settings['tempdir'] - create_dir_if_not_exists(tmpdir) - create_dir_if_not_exists(os.path.join(tmpdir, 'chunks')) - create_dir_if_not_exists(os.path.join(tmpdir, 'staging')) - create_dir_if_not_exists(os.path.join(tmpdir, 'failed')) - create_dir_if_not_exists(os.path.join(tmpdir, 'deployments')) - - create_dir_if_not_exists(self.settings['cachedir']) + for required_dir in (os.path.join(tmpdir, 'chunks'), + os.path.join(tmpdir, 'staging'), + os.path.join(tmpdir, 'failed'), + os.path.join(tmpdir, 'deployments'), + self.settings['cachedir']): + if not os.path.exists(required_dir): + os.makedirs(required_dir) cliapp.Application.process_args(self, args) |