Ejemplo n.º 1
0
def rb_list_get():
    """
    Список всех имеющихся справочников
    :return:
    """
    rb_list = RefBookRegistry.list()
    result = [
        d.meta
        for d in rb_list
    ]
    result.sort(key=lambda meta: meta.code)
    return result
Ejemplo n.º 2
0
def autofix():
    parser = argparse.ArgumentParser()
    parser.add_argument('--all',
                        action='store_const',
                        const=True,
                        default=False)
    parser.add_argument('--host', default=None)
    parser.add_argument('--port', default=None)
    parser.add_argument('--db', default=nvesta_db)
    parser.add_argument('--list',
                        action='store_const',
                        const=True,
                        default=False)
    parser.add_argument('version')

    args = parser.parse_args(sys.argv[1:])

    mongo = pymongo.MongoClient(
        host=args.host,
        port=args.port,
    )

    RefBookRegistry.bootstrap(mongo[args.db])

    refbooks = RefBookRegistry.list()
    to_fix = set(rb for rb in refbooks if not rb.meta.version)
    if args.list:
        for rb in to_fix:
            print(u"%s -- %s" % (rb.code, rb.name))
    elif args.all:
        for rb in refbooks:
            if rb in to_fix:
                rb.fixate(args.version)
            else:
                rb._fix_meta(args.version)
    else:
        parser.print_help()