From 0f5954359cae1985d96662dc0b41136702829cfe Mon Sep 17 00:00:00 2001 From: pran1990 Date: Fri, 30 May 2014 15:17:02 -0700 Subject: [PATCH] Move some file creation code from main to utils As part of engine creation, we create files for audit and repair cfg. Move this to utils. Change-Id: I9d5075cb854ab5585fddcb58013ffa2530add970 --- entropy/__main__.py | 8 +------- entropy/utils.py | 9 +++++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/entropy/__main__.py b/entropy/__main__.py index cd641da..b310874 100644 --- a/entropy/__main__.py +++ b/entropy/__main__.py @@ -103,13 +103,7 @@ def start_engine(args): } utils.write_yaml(cfg, engine_cfg) # create cfg files - for filename in ['audit_cfg', 'repair_cfg']: - try: - with open(cfg_data[filename]): - pass - except IOError: - with open(cfg_data[filename], 'a'): - pass + utils.create_files([cfg_data['audit_cfg'], cfg_data['repair_cfg']]) LOG.info('Added %s to engine cfg', args.name) entropy_engine = Engine(args.name, **cfg_data) entropy_engine.run() diff --git a/entropy/utils.py b/entropy/utils.py index c419f50..55f7cf0 100644 --- a/entropy/utils.py +++ b/entropy/utils.py @@ -223,3 +223,12 @@ class StopWatch(object): self._stopped_at = wallclock() self._state = self._STOPPED return self + + +def create_files(list_of_files): + if not list_of_files: + return + for filename in list_of_files: + if not os.path.isfile(filename): + with open(filename, 'w'): + pass