openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #00590
[Merge] lp:~j-corwin/openlp/migration into lp:openlp
Jonathan Corwin has proposed merging lp:~j-corwin/openlp/migration into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
openlpcnv.pyw updated to perform all required steps, including the sqlite -> sqlite3 conversion and the encoding.
Works on both Linux and Windows.
On Windows, gets the v1 database from the v1 location. Requires SQLite ODBC driver from
http://www.ch-werner.de/sqliteodbc/
--
https://code.launchpad.net/~j-corwin/openlp/migration/+merge/13537
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/migration/migratesongs.py'
--- openlp/migration/migratesongs.py 2009-09-25 23:06:54 +0000
+++ openlp/migration/migratesongs.py 2009-10-18 15:30:25 +0000
@@ -170,12 +170,12 @@
else:
author = self.session.query(Author).get(bb[0])
song.authors.append(author)
- try:
- self.session.add(song)
- self.session.commit()
- except:
- self.session.rollback()
- print u'Errow thrown = ', sys.exc_info()[1]
+ try:
+ self.session.add(song)
+ self.session.commit()
+ except:
+ self.session.rollback()
+ print u'Error thrown = ', sys.exc_info()[1]
def _v1_9_0_cleanup(self, database):
self.display.sub_output(u'Update Internal Data ' + database)
=== modified file 'openlpcnv.pyw'
--- openlpcnv.pyw 2009-09-25 00:43:42 +0000
+++ openlpcnv.pyw 2009-10-18 15:30:25 +0000
@@ -26,12 +26,26 @@
import os
import logging
import time
+import subprocess
+import codecs
+import sys
+from datetime import date
+if os.name == u'nt':
+ import win32api
+ import win32con
+ from win32com.client import Dispatch
from openlp.migration.display import *
from openlp.migration.migratefiles import *
from openlp.migration.migratebibles import *
from openlp.migration.migratesongs import *
+###############################################################################
+# For Windows, requires SQLite ODBC Driver to be installed
+# (uses sqlite.exe and sqlite3.exe)
+# http://www.ch-werner.de/sqliteodbc/
+###############################################################################
+
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M',
@@ -69,8 +83,71 @@
self.display.output(u'Migration Utility Finished ')
os.rename(fname, b)
+ def convert_file(self, inname, outname):
+ """
+ Convert a file from another encoding into UTF-8.
+
+ ``inname``
+ The name of the file to be opened and converted.
+
+ ``outname``
+ The output file name.
+ """
+ infile = codecs.open(inname, 'r', encoding='CP1252')
+ writefile = codecs.open(outname, 'w', encoding='utf-8')
+ for line in infile:
+ #replace the quotes with quotes
+ #TODO fix double quotes
+ #line = line.replace(u'\'\'', u'@')
+ writefile.write(line)
+ infile.close()
+ writefile.close()
+
+ def convert_sqlite2_to_3(self, olddb, newdb):
+ if os.name == u'nt':
+ hKey = win32api.RegOpenKey(win32con.HKEY_LOCAL_MACHINE, u'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\SQLite ODBC Driver')
+ value, type = win32api.RegQueryValueEx (hKey, "UninstallString")
+ sqlitepath, temp = os.path.split(value)
+ sqliteexe = os.path.join(sqlitepath, u'sqlite.exe')
+ else:
+ sqliteexe = u'sqlite'
+ cmd = sqliteexe + u' "' + olddb + u'" .dump'
+ if os.name == u'nt':
+ subprocess.call(cmd, stdout=open(u'./sqlite.dmp', 'w'))
+ else:
+ subprocess.call(cmd, stdout=open(u'./sqlite.dmp', 'w'), shell=True)
+ self.convert_file(u'sqlite.dmp', u'sqlite3.dmp')
+ if os.name == u'nt':
+ sqlite3exe = os.path.join(sqlitepath, u'sqlite3.exe')
+ else:
+ sqlite3exe = u'sqlite3'
+ if os.path.isfile(newdb):
+ saveddb = newdb + self.stime
+ os.rename(newdb, saveddb)
+ cmd = sqlite3exe + ' "' + newdb + '"'
+ if os.name == u'nt':
+ subprocess.call(cmd, stdin=open('sqlite3.dmp', 'r'))
+ else:
+ subprocess.call(cmd, stdin=open('sqlite3.dmp', 'r'), shell=True)
+ os.remove(u'sqlite.dmp')
+ os.remove(u'sqlite3.dmp')
+
if __name__ == '__main__':
mig = Migration()
+ config = PluginConfig(u'Songs')
+ newpath = config.get_data_path()
+ if os.name == u'nt':
+ if not os.path.isdir(newpath):
+ os.makedirs(newpath)
+ ALL_USERS_APPLICATION_DATA = 35
+ shell = Dispatch("Shell.Application")
+ folder = shell.Namespace(ALL_USERS_APPLICATION_DATA)
+ folderitem = folder.Self
+ olddb = os.path.join(folderitem.path, u'openlp.org', u'Data', u'songs.olp')
+ else:
+ olddb = os.path.join(newpath, u'songs.olp')
+ newdb = os.path.join(newpath, u'songs.sqlite')
+ mig.convert_sqlite2_to_3(olddb, newdb)
mig.process()
#mig.move_log_file()
Follow ups