#!/usr/bin/env python # TODO: Need a real migration tool import ConfigParser, os, string, sys, StringIO, time, threading # Set up a module path that covers the global lib and all plugins BASE_PATH = os.path.normpath(os.path.join(\ os.path.abspath(sys.argv[0]), os.pardir, os.pardir)) sys.path.insert(0, os.path.join(BASE_PATH, 'lib')) import logging, logging.config import dbagg import dbagg.web import dbagg.scan import dbagg.storage.sqlite import dbagg.storage.mysql main_log = logging.getLogger("") main_log.info("Starting up."); import sqlite sl_conn = sqlite.connect("data/agg", autocommit=1) sl_sources = dbagg.storage.sqlite.SQLiteSourceCollection(sl_conn) sl_items = dbagg.storage.sqlite.SQLiteItemCollection(sl_conn) import MySQLdb ms_conn = MySQLdb.connect(host="localhost", user="dbagg", \ passwd="dbagg", db="dbagg") ms_sources = dbagg.storage.mysql.SourceCollection(ms_conn) ms_items = dbagg.storage.mysql.ItemCollection(ms_conn) #for source in sl_sources: # print "Migrating source #%s - %s" % (source.id, source.title) # ms_sources._store_source(source) #for item in sl_items: # print "Migrating item #%s - %s" % (item.id, item.title) # ms_items._store_item(item) sl_cursor = sl_conn.cursor() ms_cursor = ms_conn.cursor() sl_cursor.execute("SELECT id,source,name,value FROM sources_meta") for data in sl_cursor.fetchall(): print "(%s) %s=%s" % (data.id, data.name, data.value) ms_cursor.execute("INSERT INTO sources_meta VALUES (%s,%s,%s,%s)", (data.id, data.source, data.name, data.value)) sl_cursor = sl_conn.cursor() ms_cursor = ms_conn.cursor() sl_cursor.execute("SELECT id,item,name,value FROM items_meta") for data in sl_cursor.fetchall(): print "(%s) %s=%s" % (data.id, data.name, data.value) ms_cursor.execute("INSERT INTO items_meta VALUES (%s,%s,%s,%s)", (data.id, data.item, data.name, data.value))