示例#1
0
def fresh_upload_coll(db_name, coll_name, master_file_name, json_file_name):
    """Delete existing data and upload a fresh copy for a single collection.
    CLOBBERS ALL EXISTING CONTENT FOR THIS COLLECTION
      Arguments :
      db_name -- name of database to refresh
      coll_name -- name of collection to refresh
      master_file_name -- path to structure file from report tool (entire or single collection)
      json_file_name -- path to additional json file for this collection
    """
    got_client = inv.setup_internal_client(editor=True)
    if not got_client:
        inv.log_dest.error("Cannot connect to db")
        return
    db = inv.int_client[inv.get_inv_db_name()]

    delete_by_collection(db, db_name, coll_name)
    upload_collection_from_files(db, db_name, coll_name, master_file_name, json_file_name, fresh=True)
示例#2
0
def fresh_upload(master_file_name, list_file_name):
    """Delete existing data and upload a fresh copy.
    CLOBBERS ALL EXISTING CONTENT
      Arguments :
      master_file_name -- path to structure file from report tool (e.g. lmfdb_structure.json)
      list_file_name -- path to file containing names of all json files to upload (one per collection)
    """
    got_client = inv.setup_internal_client(editor=True)
    if not got_client:
        inv.log_dest.error("Cannot connect to db")
        return
    db = inv.int_client[inv.get_inv_db_name()]

    #DELETE all existing inventory!!!
    delete_all_tables(db)

    upload_from_files(db, master_file_name, list_file_name, fresh=True)
    recreate_rollback_table(db, MAX_SZ)
    except Exception as e:
        inv.log_dest.error("Error getting collection "+str(e))
        return {'err':True, 'id':0}
    #fields = inv.ALL_STRUC.rollback_human[inv.STR_CONTENT]

    try:
        coll.drop()
    except:
        #TODO Do something useful here?
        pass

    inv_db.create_collection(table_name, capped=True, size=sz)

if __name__ == "__main__":

    got_client = inv.setup_internal_client(editor=True)
    if not got_client:
        exit()
    db = inv.int_client[inv.get_inv_db_name()]

    master_file_name = "./lmfdb/lmfdb_report_tool-master/intermediates/lmfdb_structure.json"
    list_file_name = "descr.txt"
    fresh_upload(master_file_name, list_file_name)

    tbls = inv.get_inv_table_names()
    for tbl in tbls:
        print(tbl)
        for item in db[tbl].find():
            try:
                print('   '+item['name'])
                print('       '+str(item['data']))