示例#1
0
    parser = argparse.ArgumentParser(
        description='fills the database')
    parser.add_argument('input_file', help='parsed and augmented dump')
    parser.add_argument('--clear-cities', help='clears the cities before'
                        ' entering new ones', action='store_true')
    parser.add_argument('--force-clear-cities', help='no prompt before clearing'
                       ' cities', action='store_true')
    parser.add_argument('--fast-priority-index', help='faster but the cities '
                        ' look less nice (less spread out) on the map',
                        action='store_true')
    parser.add_argument('--country', help='Will only keep cities in this'
                        ' country and ignore the rest')
    parser.add_argument('--max-cities', '-m', type=int)
    args = parser.parse_args()

    configure_logging()

    with session_scope() as session:
        nb_cities = session.query(City).count()

    if args.force_clear_cities and not args.clear_cities:
        print('You must specify the --clear-cities argument if you want to'
              ' use the --force-clear-cities argument')

    if nb_cities > 0:
        if args.clear_cities:
            # Here we are erasing already existing cities before inserting new
            # ones.
            if args.force_clear_cities or are_you_sure(
                    'Are you sure you want to erase all the existing cities?'):
                with session_scope() as session:
示例#2
0
    parser.add_argument('--region', help='Will only look for cities in this'
                        ' region.')
    parser.add_argument('--city', help='Will only look for that city.')
    parser.add_argument('--append', action='store_true', help='Will add'
                        ' unexisting cities to the already existing output'
                        ' file. Ignored if it doesn\'t exist.')
    parser.add_argument('--update-only', action='store_true',
                       help = 'We assume we already have cities in the output'
                        ' and we will only (re-)augment those, skipping all the'
                        ' others')
    parser.add_argument('--logging-level', choices =
                        ['debug', 'info', 'warning', 'error', 'critical'],
                        default='info')
    args = parser.parse_args()

    configure_logging(args.logging_level.upper())

    # validation of the passed arguments
    if args.append and args.update_only:
        raise Exception('can not use --append and --update-only at the'
                        ' same time')

    with open(args.input_file) as f:
        dump_in = pickle.load(f)

    if not (args.append or args.force or ask_before_overwrite(args.output_file)):
        sys.exit()

    if args.skip_wiki:
        logger.info('skipping wikipedia')
        for c in dump_in:
示例#3
0
    for code, name, unit, description, name_short in STATS:
        s = Stat(code=code,
                 name=name,
                 unit=unit,
                 description=description,
                 name_short=name_short)
        session.add(s)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Creates the database.'
                                     ' Only fills with the stat descriptions')
    parser.add_argument('--force-drop', action='store_true')
    args = parser.parse_args()

    configure_logging()

    db_name = DATABASE['name']

    with session_scope(url=DATABASE_STR_WITUOUT_TABLE) as session:
        session.execute('commit')
        try:
            session.execute('create database ' + db_name)
        except ProgrammingError:
            # the database already exists
            if args.force_drop or are_you_sure(
                    'The database "{}" already exists, do you wish to DROP it?'
                    .format(db_name)):
                session.execute('drop database ' + db_name)
                session.execute('create database ' + db_name)
            else:
示例#4
0
                        help='Will add'
                        ' unexisting cities to the already existing output'
                        ' file. Ignored if it doesn\'t exist.')
    parser.add_argument(
        '--update-only',
        action='store_true',
        help='We assume we already have cities in the output'
        ' and we will only (re-)augment those, skipping all the'
        ' others')
    parser.add_argument(
        '--logging-level',
        choices=['debug', 'info', 'warning', 'error', 'critical'],
        default='info')
    args = parser.parse_args()

    configure_logging(args.logging_level.upper())

    # validation of the passed arguments
    if args.append and args.update_only:
        raise Exception('can not use --append and --update-only at the'
                        ' same time')

    with open(args.input_file) as f:
        dump_in = pickle.load(f)

    if not (args.append or args.force
            or ask_before_overwrite(args.output_file)):
        sys.exit()

    if args.skip_wiki:
        logger.info('skipping wikipedia')