]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Adding command line parameter --no-write to not generate output files.
authorFrank Brehm <frank.brehm@pixelpark.com>
Thu, 16 Aug 2018 12:35:24 +0000 (14:35 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Thu, 16 Aug 2018 12:35:24 +0000 (14:35 +0200)
pp_lib/check_puppet_env_app.py

index 351fd98110fad46636b5ee645ff5ef4067f77f7c..6c8ebb01aed612d420368ccb90e37f3e9377edc0 100644 (file)
@@ -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