add_help=False,
)
- arg_parser.add_argument(
+ self._init_arg_parser(arg_parser)
+
+ self._perform_args(arg_parser)
+
+ # -------------------------------------------------------------------------
+ def init_arg_parser(self, arg_parser):
+
+ pass
+
+ # -------------------------------------------------------------------------
+ def _init_arg_parser(self, arg_parser):
+
+ self.init_arg_parser(arg_parser)
+
+ general_group = arg_parser.add_argument_group('General options')
+
+ general_group.add_argument(
"-N", "--no-error-mail", action='store_true', dest='no_error_mail',
help="Don't send error messages in case of some exceptions.",
)
- arg_parser.add_argument(
+ general_group.add_argument(
"-D", '--data', '--data-dir', metavar='DIR', dest='data_dir',
help="Data directory, default: {!r}.".format(self.data_dir),
)
- arg_parser.add_argument(
+ general_group.add_argument(
"-v", "--verbose", action="count", dest='verbose',
help='Increase the verbosity level',
)
- arg_parser.add_argument(
+ general_group.add_argument(
'-s', '--simulate', '--test', action='store_true', dest='simulate',
help="Simulation mode, nothing is really done.",
)
- arg_parser.add_argument(
+ general_group.add_argument(
"-C", '--cgi', action='store_true', dest='cgi',
help='Enforces behaviour as called as a CGI script.',
)
- arg_parser.add_argument(
+ general_group.add_argument(
"-h", "--help", action='help', dest='help',
help='Show this help message and exit'
)
- arg_parser.add_argument(
+ general_group.add_argument(
"--usage", action='store_true', dest='usage',
help="Display brief usage message and exit"
)
- arg_parser.add_argument(
+ general_group.add_argument(
"-V", '--version', action='version',
version='Version of %(prog)s: {}'.format(self.version),
help="Show program's version number and exit"
help="An optional query string like on HTTP GET requests."
)
+ # -------------------------------------------------------------------------
+ def _perform_args(self, arg_parser):
+
self.cmdline_args = arg_parser.parse_args()
if self.cmdline_args.usage:
except ValueError as e:
LOG.error(str(e))
+ self.perform_args(arg_parser)
+
+ # -------------------------------------------------------------------------
+ def perform_args(self, arg_parser):
+
+ pass
+
# -------------------------------------------------------------------------
def _get_query(self):
# Own modules
from . import __version__
-from .common import pp, to_bytes
+from .common import pp, to_bytes, to_bool
from .base_app import BaseHookError, BaseHookApp
self.forge_uri = self.default_forge_uri
self.http_timeout = self.default_http_timeout
self.modules = None
+ self_do_forge = True
self.description = textwrap.dedent('''\
Collects information about all used Puppet Modules from {url}
self.modules = ModuleInfoDict(
appname=self.appname, verbose=self.verbose, base_dir=self.base_dir)
+ # -----------------------------------------------------------
+ @property
+ def do_forge(self):
+ """Flag for simulation mode."""
+ return getattr(self, '_do_forge', True)
+
+ @do_forge.setter
+ def do_forge(self, value):
+ self._do_forge = to_bool(value)
+
+ # -------------------------------------------------------------------------
+ def init_arg_parser(self, arg_parser):
+
+ arg_parser.add_argument(
+ '--no-forge', action='store_true', dest='no_forge',
+ help="Don't get module information from Puppet forge.",
+ )
+
+ # -------------------------------------------------------------------------
+ def perform_args(self, arg_parser):
+
+ if self.cmdline_args.no_forge:
+ sys.stderr.write("\nDon't get module information from Puppet forge.\n\n")
+ self.do_forge = False
+
# -------------------------------------------------------------------------
def post_init(self):
res['max_http_timeout'] = self.max_http_timeout
res['default_puppet_root_env_dir'] = self.default_puppet_root_env_dir
res['open_args'] = self.open_args
+ res['do_forge'] = self.do_forge
return res
six.reraise(*sys.exc_info())
self.init_puppet_environments()
self.collect_local_modules()
- self.get_forge_information()
+ if self.do_forge:
+ self.get_forge_information()
if self.verbose > 2:
LOG.debug("Found modules:\n{}".format(pp(self.modules.as_list())))