Initial version of a migration tool

bzr-revno: 261
This commit is contained in:
Tim Bentley 2009-01-01 11:18:16 +00:00
parent c83207838d
commit 329d2d46da
6 changed files with 284 additions and 0 deletions

View File

@ -0,0 +1,17 @@
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""

View File

@ -0,0 +1,35 @@
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""
import logging
class Display():
global log
log=logging.getLogger("Display Logger")
log.info("Display Class loaded")
@staticmethod
def output(string):
log.debug(string);
print (string)
@staticmethod
def sub_output(string):
if not string == None:
log.debug(" "+string);
print (" "+string)

View File

@ -0,0 +1,27 @@
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""
import logging
class MigrateBibles():
def __init__(self, display):
self.display = display
def process(self):
self.display.output("Bible process started");
self.display.output("Bible process finished");

View File

@ -0,0 +1,41 @@
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""
from openlp.core.utils import ConfigHelper
class MigrateFiles():
def __init__(self, display):
self.display = display
def process(self):
self.display.output("Files process started");
self._initial_setup()
self.display.output("Files process finished");
def _initial_setup(self):
self.display.output("Initial Setup started");
ConfigHelper.get_data_path()
self.display.sub_output("Config created");
ConfigHelper.get_config("bible", "data path")
self.display.sub_output("Config created");
ConfigHelper.get_config("videos", "data path")
self.display.sub_output("videos created");
ConfigHelper.get_config("images", "data path")
self.display.sub_output("images created");
ConfigHelper.get_config("presentations", "data path")
self.display.sub_output("presentations created");
self.display.output("Initial Setup finished");

View File

@ -0,0 +1,119 @@
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""
import os
import logging
import sqlite3
from openlp.core.lib import PluginConfig
class MigrateSongs():
def __init__(self, display):
self.display = display
self.config = PluginConfig("Songs")
self.data_path = self.config.get_data_path()
self.database_files = self.config.get_files("olp3")
def process(self):
self.display.output("Songs processing started");
for f in self.database_files:
self.v_1_9_0(f)
self.display.output("Songs processing finished");
def v_1_9_0(self, database):
self.display.output("Migration 1.9.0 Started for "+database);
self._v1_9_0_authors(database)
self._v1_9_0_topics(database)
self._v1_9_0_songbook(database)
conn = sqlite3.connect(self.data_path+"/"+database)
conn.text_factory = str
c = conn.cursor()
#cmd = "sqlite3 -echo "+ self.data_path+"/"+database + ' "create index if not exists sa1121 on songauthors (authorid ASC,songid ASC) ;"'
#print cmd
#f_i, f_o = os.popen4(cmd)
#out = f_o.readlines()
#print out
#self.display.output(f_o.readlines())
c.execute("""select * from songs where songtitle like '%Come now%'""")
conn.commit()
#self.display.sub_output("Index SA1 created " + database);
#c.execute("""create index if not exists sa2 on songauthors (songid ASC,authorid ASC) """)
#conn.commit()
#self.display.sub_output("Index SA2 created " + database);
conn.close()
self.display.output("Migration 1.9.0 Finished for " + database);
def _v1_9_0_authors(self, database):
self.display.sub_output("Authors Started for "+database);
cmd = "sqlite3 -echo "+ self.data_path+"/"+database + ' "alter table authors add column first_name varchar(40);"'
self.run_cmd(cmd)
self.display.sub_output("first name created")
cmd = "sqlite3 -echo "+ self.data_path+"/"+database + ' "alter table authors add column last_name varchar(40);"'
self.run_cmd(cmd)
self.display.sub_output("last name created")
cmd = "sqlite3 -echo "+ self.data_path+"/"+database + ' "create index if not exists author1 on authors (authorname ASC,authorid ASC);"'
self.run_cmd(cmd)
self.display.sub_output("index author1 created")
cmd = "sqlite3 -echo "+ self.data_path+"/"+database + ' "create index if not exists author2 on authors (last_name ASC,authorid ASC);"'
self.run_cmd(cmd)
self.display.sub_output("index author2 created")
cmd = "sqlite3 -echo "+ self.data_path+"/"+database + ' "create index if not exists author3 on authors (first_name ASC,authorid ASC);"'
self.run_cmd(cmd)
self.display.sub_output("index author3 created")
self.display.sub_output("Authors Completed");
def _v1_9_0_topics(self, database):
self.display.sub_output("Topics Started for "+database);
cmd = "sqlite3 -echo "+ self.data_path+"/"+database + ' "create table if not exists topics (topic_id integer Primary Key ASC AUTOINCREMENT);"'
self.run_cmd(cmd)
self.display.sub_output("Topic table created")
cmd = "sqlite3 -echo "+ self.data_path+"/"+database + ' "alter table topics add column topic_name varchar(40);"'
self.run_cmd(cmd)
self.display.sub_output("topicname added")
cmd = "sqlite3 -echo "+ self.data_path+"/"+database + ' "create index if not exists topic1 on topics (topic_name ASC,topic_id ASC);"'
self.run_cmd(cmd)
self.display.sub_output("index topic1 created")
self.display.sub_output("Topics Completed");
def _v1_9_0_songbook(self, database):
self.display.sub_output("SongBook Started for "+database);
cmd = "sqlite3 -echo "+ self.data_path+"/"+database + ' "create table if not exists songbook (songbook_id integer Primary Key ASC AUTOINCREMENT);"'
self.run_cmd(cmd)
self.display.sub_output("SongBook table created")
cmd = "sqlite3 -echo "+ self.data_path+"/"+database + ' "alter table songbook add column songbook_name varchar(40);"'
self.run_cmd(cmd)
self.display.sub_output("songbook_name added")
cmd = "sqlite3 -echo "+ self.data_path+"/"+database + ' "alter table songbook add column songbook_publisher varchar(40);"'
self.run_cmd(cmd)
self.display.sub_output("songbook_publisher added")
cmd = "sqlite3 -echo "+ self.data_path+"/"+database + ' "create index if not exists songbook1 on songbook (songbook_name ASC,songbook_id ASC);"'
self.run_cmd(cmd)
self.display.sub_output("index songbook1 created")
cmd = "sqlite3 -echo "+ self.data_path+"/"+database + ' "create index if not exists songbook2 on songbook (songbook_publisher ASC,songbook_id ASC);"'
self.run_cmd(cmd)
self.display.sub_output("index songbook2 created")
self.display.sub_output("SongBook Completed");
def run_cmd(self, cmd):
f_i, f_o = os.popen4(cmd)
out = f_o.readlines()
if len(out) > 0:
for o in range (0, len(out)):
self.display.sub_output(out[o])

45
openlpcnv.pyw Normal file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env python
import os
import sys
import logging
import time
import datetime
from openlp.migration.display import *
from openlp.migration.migratefiles import *
from openlp.migration.migratebibles import *
from openlp.migration.migratesongs import *
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M',
filename='openlp-migration.log',
filemode='w')
class Migration():
def __init__(self):
"""
"""
self.display = Display()
self.stime = time.strftime("%Y-%m-%d-%H%M%S", time.localtime())
self.display.output("OpenLp v1.9.0 Migration Utility Started" )
def process(self):
MigrateFiles(self.display).process()
MigrateSongs(self.display).process()
MigrateBibles(self.display).process()
def move_log_file(self):
fname = 'openlp-migration.log'
c = os.path.splitext(fname)
b = (c[0]+'-'+ str(self.stime) + c[1])
self.display.output("Logfile " +b + " generated")
self.display.output("Migration Utility Finished ")
os.rename(fname, b)
if __name__ == '__main__':
mig = Migration()
mig.process()
#mig.move_log_file()