예제 #1
0
def main():
    # Used in the config file and argument parser's help
    prog_name = 'example.py'

    config = ConfigParser.SafeConfigParser()

    # Read the spec and build a parser from it
    argsdict = read.from_yaml(open(SPEC_FILE).read())
    parser = export.to_argparser(prog_name, argsdict)

    # If the config file exists and we can read it, use it to set the
    # defaults
    if config.read(CONF_FILE):
        parser = argutils.set_parser_defaults(parser, config)

    args = parser.parse_args()

    if args.init:
        export.to_config_file(prog_name, argsdict, CONF_FILE)

    for _ in range(args.times):
        args.output.write(args.message + '\n')
예제 #2
0
파일: example.py 프로젝트: eclarke/argutils
def main():
    # Used in the config file and argument parser's help
    prog_name = "example.py"

    config = ConfigParser.SafeConfigParser()

    # Read the spec and build a parser from it
    argsdict = read.from_yaml(open(SPEC_FILE).read())
    parser = export.to_argparser(prog_name, argsdict)

    # If the config file exists and we can read it, use it to set the
    # defaults
    if config.read(CONF_FILE):
        parser = argutils.set_parser_defaults(parser, config)

    args = parser.parse_args()

    if args.init:
        export.to_config_file(prog_name, argsdict, CONF_FILE)

    for _ in range(args.times):
        args.output.write(args.message + "\n")
예제 #3
0
def test_to_config_file(argsdict, tmpdir, argsdict_cfg_str):
    cfg_out = tmpdir.join("out.cfg")
    with pytest.raises(SystemExit):
        cfg_str = export.to_config_file("Section", argsdict, str(cfg_out))
    assert cfg_out.read() == argsdict_cfg_str
예제 #4
0
def test_to_config_file(argsdict, tmpdir, argsdict_cfg_str):
    cfg_out = tmpdir.join("out.cfg")
    with pytest.raises(SystemExit):
        cfg_str = export.to_config_file("Section", argsdict, str(cfg_out))
    assert cfg_out.read() == argsdict_cfg_str