from .obj import PpBaseObjectError, PpBaseObject
-__version__ = '0.2.2'
+__version__ = '0.3.1'
LOG = logging.getLogger(__name__)
@type: bool
"""
+ self._quiet = False
+
self.env = {}
"""
@ivar: a dictionary with all application specifiv environment variables,
"""The length of the localized version of 'usage: '"""
return len(self.usage_term)
+ # -----------------------------------------------------------
+ @property
+ def quiet(self):
+ """Quiet execution of the application,
+ only warnings and errors are emitted."""
+ return self._quiet
+
+ @quiet.setter
+ def quiet(self, value):
+ self._quiet = bool(value)
+
# -------------------------------------------------------------------------
def exit(self, retval=-1, msg=None, trace=False):
"""
res = super(PpApplication, self).as_dict(short=short)
res['exit_value'] = self.exit_value
res['usage'] = self.usage
+ res['quiet'] = self.quiet
res['description'] = self.description
res['argparse_epilog'] = self.argparse_epilog
res['argparse_prefix_chars'] = self.argparse_prefix_chars
@return: None
"""
- root_logger = logging.getLogger()
- root_logger.setLevel(logging.INFO)
+ log_level = logging.INFO
if self.verbose:
- root_logger.setLevel(logging.DEBUG)
+ log_level = logging.DEBUG
+ elif self.quiet:
+ log_level = logging.WARNING
+
+ root_logger = logging.getLogger()
+ root_logger.setLevel(log_level)
# create formatter
format_str = ''
# create log handler for console output
lh_console = logging.StreamHandler(sys.stderr)
- if self.verbose:
- lh_console.setLevel(logging.DEBUG)
- else:
- lh_console.setLevel(logging.INFO)
+ lh_console.setLevel(log_level)
lh_console.setFormatter(formatter)
root_logger.addHandler(lh_console)
choices=['yes', 'no', 'auto'],
help="Use colored output for messages.",
)
- general_group.add_argument(
+
+ verbose_group = general_group.add_mutually_exclusive_group()
+
+ verbose_group.add_argument(
"-v", "--verbose",
action="count",
dest='verbose',
help='Increase the verbosity level',
)
+
+ verbose_group.add_argument(
+ "-q", "--quiet",
+ action="store_true",
+ dest='quiet',
+ help='Silent execution, only warnings and errors are emitted.',
+ )
+
general_group.add_argument(
"-h", "--help",
action='help',
if self.args.verbose is not None and self.args.verbose > self.verbose:
self.verbose = self.args.verbose
+ if self.args.quiet:
+ self.quiet = self.args.quiet
+
if self.args.color == 'yes':
self._terminal_has_colors = True
elif self.args.color == 'no':