def get_connection(self): if self._conn_id is not None \ and DBLocator.connections.has_key(self._conn_id): connection = DBLocator.connections[self._conn_id] if io.ping_db_connection(connection): return connection else: if self._conn_id is None: if DBLocator.cache_connections.has_key(self._hash): connection = DBLocator.cache_connections[self._hash] if io.ping_db_connection(connection): debug.log("Reusing cached connection") return connection if len(DBLocator.connections.keys()) == 0: self._conn_id = 1 else: self._conn_id = max(DBLocator.connections.keys()) + 1 config = {'host': self._host, 'port': self._port, 'db': self._db, 'user': self._user, 'passwd': self._passwd} #print "config:", config connection = io.open_db_connection(config) DBLocator.connections[self._conn_id] = connection DBLocator.cache_connections[self._hash] = connection return connection
def get_connection(self): if self._conn_id is not None \ and DBLocator.connections.has_key(self._conn_id): connection = DBLocator.connections[self._conn_id] if io.ping_db_connection(connection): return connection else: if self._conn_id is None: if DBLocator.cache_connections.has_key(self._hash): connection = DBLocator.cache_connections[self._hash] if io.ping_db_connection(connection): debug.log("Reusing cached connection") return connection if len(DBLocator.connections.keys()) == 0: self._conn_id = 1 else: self._conn_id = max(DBLocator.connections.keys()) + 1 config = { 'host': self._host, 'port': self._port, 'db': self._db, 'user': self._user, 'passwd': self._passwd } #print "config:", config connection = io.open_db_connection(config) DBLocator.connections[self._conn_id] = connection DBLocator.cache_connections[self._hash] = connection return connection
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 convert_sql_to_xml(filename, id): config = {'host': 'vistrails.sci.utah.edu', 'port': 3306, 'user': '******', 'passwd': '8edLj4', 'db': 'vistrails'} try: db_connection = io.open_db_connection(config) vistrail = io.open_vistrail_from_db(db_connection, id) io.save_vistrail_to_xml(vistrail, filename) io.close_db_connection(db_connection) except MySQLdb.Error, e: print e
def convert_sql_to_xml(filename, id): config = {'host': 'localhost', 'port': 3306, 'user': '******', 'passwd': 'vistrailspwd', 'db': 'vistrails'} try: dbConnection = io.open_db_connection(config) vistrail = io.open_vistrail_from_db(dbConnection, id) io.setDBParameters(vistrail, config) io.save_vistrail_to_xml(vistrail, filename) io.close_db_connection(dbConnection) except MySQLdb.Error, 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
def convert_sql_to_xml(filename, id): config = { 'host': 'vistrails.sci.utah.edu', 'port': 3306, 'user': '******', 'passwd': '8edLj4', 'db': 'vistrails' } try: db_connection = io.open_db_connection(config) vistrail = io.open_vistrail_from_db(db_connection, id) io.save_vistrail_to_xml(vistrail, filename) io.close_db_connection(db_connection) except MySQLdb.Error, e: print e
def update_db(config, new_version=None, tmp_dir=None): 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 obj_id_lists = {} for obj_type in obj_types: obj_id_lists[obj_type] = io.get_db_object_list(config, obj_type) # read data out of database filenames = [] thumbnail_dir = os.path.join(tmp_dir, 'thumbs') os.mkdir(thumbnail_dir) db_connection = io.open_db_connection(config) 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') filenames.append(vt_name) os.mkdir(local_tmp_dir) res = obj_types[obj_type](obj_type, db_connection, obj_id, thumbnail_dir) 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) io.save_vistrail_bundle_to_db(res, db_connection, 'with_ids') io.close_db_connection(db_connection)
def update_db(config, new_version=None, tmp_dir=None): 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 obj_id_lists = {} for obj_type in obj_types: obj_id_lists[obj_type] = io.get_db_object_list(config, obj_type) # read data out of database filenames = [] thumbnail_dir = os.path.join(tmp_dir, "thumbs") os.mkdir(thumbnail_dir) db_connection = io.open_db_connection(config) 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") filenames.append(vt_name) os.mkdir(local_tmp_dir) res = obj_types[obj_type](obj_type, db_connection, obj_id, thumbnail_dir) 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) io.save_vistrail_bundle_to_db(res, db_connection, "with_ids") io.close_db_connection(db_connection)
def convert_xml_to_sql(filename): config = {'host': 'localhost', 'port': 3306, 'user': '******', 'passwd': 'vistrailspwd', 'db': 'vistrails'} try: vistrail = io.open_vistrail_from_xml(filename) dbConnection = io.open_db_connection(config) print dbConnection.get_server_info() print dbConnection.get_host_info() print dbConnection.stat() print str(dbConnection) io.save_vistrail_to_db(vistrail, dbConnection) io.close_db_connection(dbConnection) print 'db_id: ', vistrail.db_id except Exception, e: print e
def convert_xml_to_sql(filename): config = { 'host': 'localhost', 'port': 3306, 'user': '******', 'passwd': 'vistrailspwd', 'db': 'vistrails' } try: vistrail = io.open_vistrail_from_xml(filename) dbConnection = io.open_db_connection(config) print dbConnection.get_server_info() print dbConnection.get_host_info() print dbConnection.stat() print str(dbConnection) io.save_vistrail_to_db(vistrail, dbConnection) io.close_db_connection(dbConnection) print 'db_id: ', vistrail.db_id except Exception, e: print e
def delete_from_db(config, obj_type, obj_id): db_connection = io.open_db_connection(config) io.delete_entity_from_db(db_connection, obj_type, obj_id) io.close_db_connection(db_connection)