From 731609f689a8c55d2b0ce74d3a5f5d621bf7a75f Mon Sep 17 00:00:00 2001 From: brent s Date: Wed, 8 Nov 2017 23:12:36 -0500 Subject: [PATCH] fixing bug with replace mode --- aif/scripts/post/hostscan.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/aif/scripts/post/hostscan.py b/aif/scripts/post/hostscan.py index e8eaf58..3e4491c 100755 --- a/aif/scripts/post/hostscan.py +++ b/aif/scripts/post/hostscan.py @@ -101,6 +101,9 @@ class hostscanner(object): return() def write(self): + if self.args['writemode'] == 'replace': + if os.path.isfile(self.args['output']) and self.args['output'] != sys.stdout: + os.move(self.args['output'], os.path.join(self.args['output'], '.bak')) for h in self.keys.keys(): for i in self.keys[h]: _s = '# Automatically added via hostscan.py\n{0} {1} {2}\n'.format(i['host'], @@ -109,11 +112,7 @@ class hostscanner(object): if self.args['output'] == sys.stdout: print(_s, end = '') else: - if self.args['writemode'] == 'append': - _wm = 'a' - else: - _wm = 'w' - with open(self.args['output'], _wm) as f: + with open(self.args['output'], 'a') as f: f.write(_s) os.chmod(self.args['output'], 0o644) os.chown(self.args['output'],