Commit 6e1d274f authored by Sebastien Luttringer's avatar Sebastien Luttringer
Browse files

replace quiet and debug by verbosity

old command line option are still present but no more in config file
this allow to override easily on command line config parameters
parent 0f9e8a4d
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -459,11 +459,16 @@ def arg_parser_init():
    parser = argparse.ArgumentParser()
    parser.add_argument("-V", "--version", action="version",
                        version=installsystems.version)
    # exclusive group on debug/quiet
    # exclusive group on verbosity
    g = parser.add_mutually_exclusive_group()
    g.add_argument("-d", "--debug", action="store_true",
    g.add_argument("-v", "--verbosity", default=1,
                   type=int, choices=[0,1,2],
                   help="define verbosity level (0: quiet, 1:normal, 2:debug)")
    g.add_argument("-d", "--debug", dest="verbosity",
                   action="store_const", const=2,
                   help="active debug mode")
    g.add_argument("-q", "--quiet", action="store_true",
    g.add_argument("-q", "--quiet", dest="verbosity",
                   action="store_const", const=0,
                   help="active quiet mode")
    # common options
    parser.add_argument("-c", "--config", default="installsystems",
@@ -711,21 +716,19 @@ def main():
        arg_parser = arg_parser_init()
        # first partial parsing, to get early debug and config path
        options = arg_parser.parse_known_args()[0]
        # set early command line debug and quiet mode
        installsystems.debug = options.debug
        installsystems.quiet = options.quiet
        # set early command line verbosity and color
        installsystems.verbosity = options.verbosity
        installsystems.printer.NOCOLOR = options.no_color
        # load main config file options
        config_parser = MainConfigFile(options.config, "installsystems")
        options = config_parser.parse()
        # second partial parsing, command line option overwrite config file
        options = arg_parser.parse_known_args(namespace=options)[0]
        # set debug and quiet mode
        installsystems.debug = options.debug
        installsystems.quiet = options.quiet
        # set verbosity and color
        installsystems.verbosity = options.verbosity
        installsystems.printer.NOCOLOR = options.no_color
        # no warning if we are not in debug mode
        if not installsystems.debug:
        if installsystems.verbosity < 2:
            warnings.filterwarnings("ignore")
        # except for install command we parse all args!
        # install command is responsible of parsing
+3 −2
Original line number Diff line number Diff line
@@ -3,12 +3,12 @@

# list local repositories
_local_repo() {
   COMPREPLY=("${COMPREPLY[@]}" $(compgen -W "$(is --no-color --no-sync repo --local)"  -- "$cur"))
   COMPREPLY=("${COMPREPLY[@]}" $(compgen -W "$(is --quiet --no-color --no-sync repo --local)"  -- "$cur"))
}

# list all defined repositories
_repo() {
   COMPREPLY=("${COMPREPLY[@]}" $(compgen -W "$(is --no-color --no-sync repo)"  -- "$cur"))
   COMPREPLY=("${COMPREPLY[@]}" $(compgen -W "$(is --quiet --no-color --no-sync repo)"  -- "$cur"))
}

# list all images available in any online repositories
@@ -44,6 +44,7 @@ _is() {
       'search' 'version' 'diff' 'prepare_chroot' 'unprepare_chroot')
   opts=('-h'  '--help'
   '-V'  '--version'
   '-v'  '--verbosity'
   '-d'  '--debug'
   '-q'  '--quiet'
   '-R'  '--repo-config'
+1 −2
Original line number Diff line number Diff line
@@ -8,7 +8,6 @@ InstallSystems module

canonical_name="installsystems"
version = "5"
debug = False
quiet = False
verbosity = 1 # 0: quiet, 1: normal, 2: debug

__all__ = []
+19 −3
Original line number Diff line number Diff line
@@ -53,8 +53,7 @@ class MainConfigFile(ConfigFile):
    '''

    valid_options = {
        "debug": bool,
        "quiet": bool,
        "verbosity": [0,1,2],
        "no_cache": bool,
        "no_color": bool,
        "timeout": int,
@@ -99,16 +98,33 @@ class MainConfigFile(ConfigFile):
            if option not in self.valid_options.keys():
                warn("Invalid option %s in %s, skipped" % (option, self.path))
                continue
            # we expect a string like
            if not isinstance(option, basestring):
                raise TypeError("Invalid config parser option %s type" % option)
            # smartly cast option's value
            if self.valid_options[option] is bool:
                value = value.strip().lower() not in ("false", "no", "0", "")
            # in case of valid option is a list, we take the type of the first
            # argument of the list to convert value into it
            # as a consequence, all element of a list must be of the same type!
            # empty list are forbidden !
            elif isinstance(self.valid_options[option], list):
                ctype = type(self.valid_options[option][0])
                try:
                    value = ctype(value)
                except ValueError:
                    warn("Invalid option %s type (must be %s), skipped" %
                         (option, ctype))
                    continue
                if value not in self.valid_options[option]:
                    warn("Invalid value %s in option %s (must be in %s), skipped" %
                         (value, option, self.valid_options[option]))
                    continue
            else:
                try:
                    value = self.valid_options[option](value)
                except ValueError:
                    warn("Invalid option %s type. Must be %s" %
                    warn("Invalid option %s type (must be %s), skipped" %
                         (option, self.valid_options[option]))
                    continue
            setattr(namespace, option, value)
+5 −5
Original line number Diff line number Diff line
@@ -72,14 +72,14 @@ def err(message, fd=sys.stderr, endl=os.linesep):

def fatal(message, quit=True, fd=sys.stderr, endl=os.linesep):
    out("#light##red#Fatal:#reset# #red#%s#reset#" % message, fd, endl)
    if sys.exc_info()[0] is not None and installsystems.debug:
    if sys.exc_info()[0] is not None and installsystems.verbosity > 1:
        raise
    if quit:
        os._exit(21)

def error(message, quit=True, fd=sys.stderr, endl=os.linesep):
    out("#light##red#Error:#reset# #red#%s#reset#" % message, fd, endl)
    if sys.exc_info()[0] is not None and installsystems.debug:
    if sys.exc_info()[0] is not None and installsystems.verbosity > 1:
        raise
    if quit:
        exit(42)
@@ -88,11 +88,11 @@ def warn(message, fd=sys.stderr, endl=os.linesep):
    out("#light##yellow#Warning:#reset# #yellow#%s#reset#" % message, fd, endl)

def info(message, fd=sys.stderr, endl=os.linesep):
    if not installsystems.quiet:
    if installsystems.verbosity > 0:
        out("#light#Info%s:#reset# %s" % message, fd, endl)

def debug(message, fd=sys.stderr, endl=os.linesep):
    if installsystems.debug:
    if installsystems.verbosity > 1:
        out("#light##black#%s#reset#" % message, fd, endl)

def arrowlevel(inc=None, level=None):
@@ -105,7 +105,7 @@ def arrowlevel(inc=None, level=None):
    return old_level

def arrow(message, inclevel=None, level=None, fd=sys.stdout, endl=os.linesep):
    if installsystems.quiet:
    if installsystems.verbosity == 0:
        return
    # define new level
    old_level = arrowlevel(inc=inclevel, level=level)
Loading