Exemple #1
0
def main():
    parser = cmd.initialize_arg_parser()
    args = parser.parse_args()
    prosaic_home = args.home
    cfgpath = join(prosaic_home, 'prosaic.conf')
    tmplpath = join(prosaic_home, 'templates')

    log = logging.getLogger('prosaic')
    log.addHandler(logging.StreamHandler(stream=sys.stderr))

    if args.verbose:
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.ERROR)

    if not exists(prosaic_home):
        log.debug('Initializing prosaic home folder...')
        mkdir(prosaic_home)

    if not exists(tmplpath):
        log.debug('Copying initial templates...')
        prosaic_install_path = dirname(sys.modules['prosaic'].__file__)
        template_source = join(prosaic_install_path, 'templates')
        copytree(template_source, tmplpath)

    if not exists(cfgpath):
        log.debug('Initializing default config...')
        with open(cfgpath, 'w') as f:
            f.write(cfg.DEFAULT_CONFIG)

    config = cfg.read_config(cfgpath)

    m.migrate(m.Database(**config['database']))

    # TODO decouple argument parsing from command execution
    return parser.dispatch(args, config)
Exemple #2
0
def main():
    parser = cmd.initialize_arg_parser()
    args = parser.parse_args()
    prosaic_home = args.home
    cfgpath = join(prosaic_home, 'prosaic.conf')
    tmplpath = join(prosaic_home, 'templates')

    log = logging.getLogger('prosaic')
    log.addHandler(logging.StreamHandler(stream=sys.stderr))

    if args.verbose:
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.ERROR)

    if not exists(prosaic_home):
        log.debug('Initializing prosaic home folder...')
        mkdir(prosaic_home)

    if not exists(tmplpath):
        log.debug('Copying initial templates...')
        prosaic_install_path = dirname(sys.modules['prosaic'].__file__)
        template_source = join(prosaic_install_path, 'templates')
        copytree(template_source, tmplpath)

    if not exists(cfgpath):
        log.debug('Initializing default config...')
        with open(cfgpath, 'w') as f:
            f.write(cfg.DEFAULT_CONFIG)

    config = cfg.read_config(cfgpath)

    m.migrate(m.Database(**config['database']))

    # TODO decouple argument parsing from command execution
    return parser.dispatch(args, config)
Exemple #3
0
 def test_initialization_and_reading(self, cleanup):
     sys.argv = ['prosaic', 'corpus', 'ls', '--home', TEST_PROSAIC_HOME]
     main()
     config = cfg.read_config(join(TEST_PROSAIC_HOME, 'prosaic.conf'))
     assert cfg.DEFAULT_DB == config['database']
     assert cfg.DEFAULT_TEMPLATE == config['default_template']
Exemple #4
0
 def test_initialization_and_reading(self, cleanup):
     sys.argv = ['prosaic', 'corpus', 'ls', '--home', TEST_PROSAIC_HOME]
     main()
     config = cfg.read_config(join(TEST_PROSAIC_HOME, 'prosaic.conf'))
     assert cfg.DEFAULT_DB == config['database']
     assert cfg.DEFAULT_TEMPLATE == config['default_template']