示例#1
0
def cli(argv=None, conf_file=DEFAULT_CONF_FNAME, namespace=None):
    """
    parse cli args basically and returns a :class:`Configuration`.

    if namespace is given, it will be used as a arg parsing result, so no
    arg parsing will be done.
    """
    if namespace:
        options = namespace
    else:
        defaults = get_defaults(conf_file)
        options = parse_args(argv=argv, defaults=defaults)
        if not options.cmdargs:
            # we don't set the cmdargs default to be that from the
            # configuration file, because then any new arguments
            # will be appended: https://bugs.python.org/issue16399
            options.cmdargs = defaults['cmdargs']
    if conf_file and not os.path.isfile(conf_file):
        print '*' * 10
        print colorize("You should use a config file. Please use the " +
                       '{sBRIGHT}--write-config{sRESET_ALL}' +
                       " command line flag to help you create one.")
        print '*' * 10
        print
    return Configuration(options)
示例#2
0
def cli(argv=None, conf_file=DEFAULT_CONF_FNAME, namespace=None):
    """
    parse cli args basically and returns a :class:`Configuration`.

    if namespace is given, it will be used as a arg parsing result, so no
    arg parsing will be done.
    """
    if namespace:
        options = namespace
    else:
        defaults = get_defaults(conf_file)
        options = parse_args(argv=argv, defaults=defaults)
    if conf_file and not os.path.isfile(conf_file):
        print '*' * 10
        print colorize("You should use a config file. Please use the " +
                       '{sBRIGHT}--write-config{sRESET_ALL}' +
                       " command line flag to help you create one.")
        print '*' * 10
        print
    return Configuration(options)
示例#3
0
def cli(argv=None, conf_file=DEFAULT_CONF_FNAME, namespace=None):
    """
    parse cli args basically and returns a :class:`Configuration`.

    if namespace is given, it will be used as a arg parsing result, so no
    arg parsing will be done.
    """
    if namespace:
        options = namespace
    else:
        defaults = get_defaults(conf_file)
        options = parse_args(argv=argv, defaults=defaults)
    if conf_file and not os.path.isfile(conf_file):
        print '*' * 10
        print colorize("You should use a config file. Please use the " +
                       '{sBRIGHT}--write-config{sRESET_ALL}' +
                       " command line flag to help you create one.")
        print '*' * 10
        print
    return Configuration(options)
示例#4
0
 def _set_option(optname, getfunc, default):
     print
     if optname not in config:
         value = getfunc(default)
         if value is not None:
             config[optname] = value
         else:
             value = default
     else:
         print '%s already defined.' % optname
         value = config[optname]
     name = colorize("{fGREEN}%s{sRESET_ALL}" % optname)
     print "%s: %s" % (name, value)
示例#5
0
 def _set_option(optname, getfunc, default):
     print
     if optname not in config:
         value = getfunc(default)
         if value is not None:
             config[optname] = value
         else:
             value = default
     else:
         print '%s already defined.' % optname
         value = config[optname]
     name = colorize("{fGREEN}%s{sRESET_ALL}" % optname)
     print "%s: %s" % (name, value)
示例#6
0
def write_conf(conf_path):
    conf_dir = os.path.dirname(conf_path)
    if not os.path.isdir(conf_dir):
        os.makedirs(conf_dir)

    config = ConfigObj(conf_path)
    if not config.initial_comment:
        config.initial_comment = CONF_HELP.splitlines()

    def _set_option(optname, getfunc, default):
        print
        if optname not in config:
            value = getfunc(default)
            if value is not None:
                config[optname] = value
            else:
                value = default
        else:
            print '%s already defined.' % optname
            value = config[optname]
        name = colorize("{fGREEN}%s{sRESET_ALL}" % optname)
        print "%s: %s" % (name, value)

    _set_option('persist', _get_persist_dir, os.path.join(conf_dir, "persist"))

    _set_option('persist-size-limit', _get_persist_size_limit, 20.0)

    if mozinfo.os != 'mac' and mozinfo.bits == 64:
        _set_option('bits', _get_bits, 64)

    config.write()

    print
    print colorize('Config file {sBRIGHT}%s{sRESET_ALL} written.' % conf_path)
    print(
        "Note you can edit it manually, and there are other options you can"
        " configure. See %s." % CONFIG_FILE_HELP_URL)
示例#7
0
def write_conf(conf_path):
    conf_dir = os.path.dirname(conf_path)
    if not os.path.isdir(conf_dir):
        os.makedirs(conf_dir)

    config = ConfigObj(conf_path)
    if not config.initial_comment:
        config.initial_comment = CONF_HELP.splitlines()

    def _set_option(optname, getfunc, default):
        print
        if optname not in config:
            value = getfunc(default)
            if value is not None:
                config[optname] = value
            else:
                value = default
        else:
            print '%s already defined.' % optname
            value = config[optname]
        name = colorize("{fGREEN}%s{sRESET_ALL}" % optname)
        print "%s: %s" % (name, value)

    _set_option('persist', _get_persist_dir,
                os.path.join(conf_dir, "persist"))

    _set_option('persist-size-limit', _get_persist_size_limit, 20.0)

    if mozinfo.os != 'mac' and mozinfo.bits == 64:
        _set_option('bits', _get_bits, 64)

    config.write()

    print
    print colorize('Config file {sBRIGHT}%s{sRESET_ALL} written.' % conf_path)
    print("Note you can edit it manually, and there are other options you can"
          " configure. See %s." % CONFIG_FILE_HELP_URL)
示例#8
0
def test_colorize():
    assert log.colorize("stuff", allow_color=True) == "stuff"
    assert log.colorize("{fRED}stuff{sRESET_ALL}",
                        allow_color=True) == (Fore.RED + "stuff" +
                                              Style.RESET_ALL)
    assert log.colorize("{fRED}stuf{sRESET_ALL}", allow_color=False) == "stuf"
示例#9
0
def test_colorize():
    assert log.colorize("stuff", allow_color=True) == "stuff"
    assert log.colorize("{fRED}stuff{sRESET_ALL}", allow_color=True) == (
        Fore.RED + "stuff" + Style.RESET_ALL)
    assert log.colorize("{fRED}stuf{sRESET_ALL}", allow_color=False) == "stuf"