示例#1
0
def update_db(config, new_version=None, tmp_dir=None, restore=False):
    obj_types = {
        "vistrail": io.open_bundle_from_db,
        # 'workflow': io.open_from_db,
        # 'log': io.open_from_db,
        # 'registry': io.open_from_db
    }
    if new_version is None:
        new_version = currentVersion
    if tmp_dir is None:
        tmp_dir = tempfile.mkdtemp(prefix="vt_db")
        print "creating tmpdir:", tmp_dir

    db_connection = io.open_db_connection(config)
    obj_id_lists = {}
    filenames = []
    if restore:
        for dirpath, dirname, files in os.walk(restore):
            for fname in files:
                if fname.endswith(".vt"):
                    filenames.append(os.path.join(restore, fname))
    else:
        for obj_type in obj_types:
            obj_id_lists[obj_type] = io.get_db_object_list(config, obj_type)

        # read data out of database
        thumbnail_dir = os.path.join(tmp_dir, "thumbs")
        os.mkdir(thumbnail_dir)
        for obj_type, obj_ids in obj_id_lists.iteritems():
            for (obj_id, _, _) in obj_ids:
                old_version = io.get_db_object_version(db_connection, obj_id, "vistrail")

                print "getting", obj_type, "id", obj_id
                local_tmp_dir = os.path.join(tmp_dir, str(obj_id))
                vt_name = os.path.join(tmp_dir, str(obj_id) + ".vt")
                try:
                    res = obj_types[obj_type](obj_type, db_connection, obj_id, thumbnail_dir)
                    filenames.append(vt_name)
                    os.mkdir(local_tmp_dir)
                except:
                    import traceback

                    print "Could not read:", traceback.format_exc()
                    continue
                io.save_vistrail_bundle_to_zip_xml(res, vt_name, local_tmp_dir)

        # drop the old database
        # recreate with the new version of the specs
        io.setup_db_tables(db_connection, None, old_version)

    # add the new data back
    for filename in filenames:
        (res, _) = io.open_vistrail_bundle_from_zip_xml(filename)
        try:
            io.save_vistrail_bundle_to_db(res, db_connection, "with_ids")
        except Exception, e:
            import traceback

            print filename, e, traceback.format_exc()
示例#2
0
def update_db(config, new_version=None, tmp_dir=None, restore=False):
    obj_types = {
        'vistrail': io.open_bundle_from_db,
        # 'workflow': io.open_from_db,
        # 'log': io.open_from_db,
        # 'registry': io.open_from_db
    }
    if new_version is None:
        new_version = currentVersion
    if tmp_dir is None:
        tmp_dir = tempfile.mkdtemp(prefix='vt_db')
        print 'creating tmpdir:', tmp_dir

    db_connection = io.open_db_connection(config)
    obj_id_lists = {}
    filenames = []
    if restore:
        for dirpath, dirname, files in os.walk(restore):
            for fname in files:
                if fname.lower().endswith('.vt'):
                    filenames.append(os.path.join(restore, fname))
    else:
        for obj_type in obj_types:
            obj_id_lists[obj_type] = io.get_db_object_list(config, obj_type)

        # read data out of database
        thumbnail_dir = os.path.join(tmp_dir, 'thumbs')
        os.mkdir(thumbnail_dir)
        for obj_type, obj_ids in obj_id_lists.iteritems():
            for (obj_id, _, _) in obj_ids:
                old_version = io.get_db_object_version(db_connection, obj_id,
                                                       'vistrail')

                print 'getting', obj_type, 'id', obj_id
                local_tmp_dir = os.path.join(tmp_dir, str(obj_id))
                vt_name = os.path.join(tmp_dir, str(obj_id) + '.vt')
                try:
                    res = obj_types[obj_type](obj_type, db_connection, obj_id,
                                              thumbnail_dir)
                    filenames.append(vt_name)
                    os.mkdir(local_tmp_dir)
                except:
                    import traceback
                    print "Could not read:", traceback.format_exc()
                    continue
                io.save_vistrail_bundle_to_zip_xml(res, vt_name, local_tmp_dir)

        # drop the old database
        # recreate with the new version of the specs
        io.setup_db_tables(db_connection, None, old_version)

    # add the new data back
    for filename in filenames:
        (res, _) = io.open_vistrail_bundle_from_zip_xml(filename)
        try:
            io.save_vistrail_bundle_to_db(res, db_connection, 'with_ids')
        except Exception, e:
            import traceback
            print filename, e, traceback.format_exc()
示例#3
0
def setup_tables(host, port, user, passwd, db):
    config = {'host': host, 
              'port': port,
              'user': user,
              'passwd': passwd,
              'db': db}

    try:
        db_connection = io.open_db_connection(config)
        io.setup_db_tables(db_connection)
    except Exception, e:
        print e
def setup_tables(host, port, user, passwd, db):
    config = {
        'host': host,
        'port': port,
        'user': user,
        'passwd': passwd,
        'db': db
    }

    try:
        db_connection = io.open_db_connection(config)
        io.setup_db_tables(db_connection)
    except Exception, e:
        print e