From 42e0109b48fdaef6486a2d896cb60c62ebf335ff Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 16 Aug 2018 14:35:24 +0200 Subject: [PATCH] Adding command line parameter --no-write to not generate output files. --- pp_lib/check_puppet_env_app.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/pp_lib/check_puppet_env_app.py b/pp_lib/check_puppet_env_app.py index 351fd98..6c8ebb0 100644 --- a/pp_lib/check_puppet_env_app.py +++ b/pp_lib/check_puppet_env_app.py @@ -41,7 +41,7 @@ from .merge import merge_structure from .app import PpApplication -__version__ = '0.5.1' +__version__ = '0.5.2' LOG = logging.getLogger(__name__) @@ -68,6 +68,8 @@ class CheckPuppetEnvApp(PpApplication): 'errors': 'surrogateescape', } + dev_null = os.sep + os.path.join('dev', 'null') + # ------------------------------------------------------------------------- def __init__( self, appname=None, verbose=0, version=__version__, base_dir=None, @@ -87,6 +89,7 @@ class CheckPuppetEnvApp(PpApplication): self.modules = {} self.dependencies = [] self.rev_dep = {} + self.no_write = False super(CheckPuppetEnvApp, self).__init__( appname=appname, verbose=verbose, version=version, base_dir=base_dir, @@ -117,6 +120,7 @@ class CheckPuppetEnvApp(PpApplication): """ res = super(CheckPuppetEnvApp, self).as_dict(short=short) + res['dev_null'] = self.dev_null res['open_args'] = self.open_args return res @@ -149,9 +153,17 @@ class CheckPuppetEnvApp(PpApplication): os.path.join(self.base_dir, 'tmp')) ) + self.arg_parser.add_argument( + '-N', '--no-write', action="store_true", dest="no_write", + help="Do not generate output files.", + ) + # ------------------------------------------------------------------------- def perform_arg_parser(self): + if self.args.no_write: + self.no_write = True + puppet_root_env_dir = self.puppet_root_env_dir retval = 5 @@ -283,8 +295,19 @@ class CheckPuppetEnvApp(PpApplication): out_file = os.path.join(self.out_dir, outfile_base) LOG.info("Writing information about modules in {!r}...".format(out_file)) + if self.no_write: + LOG.debug("Don't writing into {!r}...".format(out_file)) + if self.verbose: + print() + print("Module information:") + print() + print('---') + print(yaml.dump(self.modules, width=240)) + print() + return with open(out_file, 'w', **self.open_args) as fh: + fh.write('---\n') fh.write(yaml.dump(self.modules, width=240)) # ------------------------------------------------------------------------- @@ -410,6 +433,10 @@ class CheckPuppetEnvApp(PpApplication): print(line) fh.write(line + '\n') + if self.no_write: + LOG.debug("Don't writing into {!r}...".format(out_file)) + out_file = self.dev_null + with open(out_file, 'w', **self.open_args) as fh: # File header -- 2.39.5