diff --git a/cnvdb.py b/cnvdb.py new file mode 100644 index 000000000..4bf4af2f8 --- /dev/null +++ b/cnvdb.py @@ -0,0 +1,23 @@ +import codecs + + +class Convert(): + def __init__(self): + pass + + def process(self, inname, outname): + infile = codecs.open(inname, 'r', encoding='iso-8859-1') + writefile = codecs.open(outname, 'w', encoding='utf-8') + count = 0 + for line in infile: + writefile.write(line) + if count < 150: + print line + count += 1 + infile.close() + writefile.close() + + +if __name__ == '__main__': + mig = Convert() + mig.process(u'/home/timali/.local/share/openlp/songs/songs.dmp',u'/home/timali/.local/share/openlp/songs/songs.dmp2') diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index e6897a56b..ae49ab2e6 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -231,11 +231,6 @@ class SlideController(QtGui.QWidget): QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSlideSelected) QtCore.QObject.connect(self.PreviewListView, QtCore.SIGNAL(u'activated(QModelIndex)'), self.onSlideSelected) - QtCore.QObject.connect(self.PreviewListView, - QtCore.SIGNAL(u'entered(QModelIndex)'), self.onTest) - - def onTest(self , item): - print "found", item def onSlideSelectedFirst(self): """ diff --git a/openlp/migration/display.py b/openlp/migration/display.py index 7abf54e5e..311674efb 100644 --- a/openlp/migration/display.py +++ b/openlp/migration/display.py @@ -22,14 +22,14 @@ class Display(): global log log=logging.getLogger(u'Display Logger') log.info(u'Display Class loaded') - + @staticmethod def output(string): log.debug(string); print (string) - + @staticmethod def sub_output(string): if not string == None: - log.debug(u' "+string); - print (u' "+string) \ No newline at end of file + log.debug(u' '+string); + print (u' '+string) diff --git a/openlp/migration/migratefiles.py b/openlp/migration/migratefiles.py index 665735c03..f55f08f4a 100644 --- a/openlp/migration/migratefiles.py +++ b/openlp/migration/migratefiles.py @@ -24,18 +24,18 @@ class MigrateFiles(): def process(self): self.display.output(u'Files process started'); self._initial_setup() - self.display.output(u'Files process finished'); - + self.display.output(u'Files process finished'); + def _initial_setup(self): self.display.output(u'Initial Setup started'); ConfigHelper.get_data_path() - self.display.sub_output(u'Config created'); - ConfigHelper.get_config(u'bible", u'data path') - self.display.sub_output(u'Config created'); - ConfigHelper.get_config(u'videos", u'data path') - self.display.sub_output(u'videos created'); - ConfigHelper.get_config(u'images", u'data path') - self.display.sub_output(u'images created'); - ConfigHelper.get_config(u'presentations", u'data path') - self.display.sub_output(u'presentations created'); - self.display.output(u'Initial Setup finished'); \ No newline at end of file + self.display.sub_output(u'Config created'); + ConfigHelper.get_config(u'bible', u'data path') + self.display.sub_output(u'Config created'); + ConfigHelper.get_config(u'videos', u'data path') + self.display.sub_output(u'videos created'); + ConfigHelper.get_config(u'images', u'data path') + self.display.sub_output(u'images created'); + ConfigHelper.get_config(u'presentations', u'data path') + self.display.sub_output(u'presentations created'); + self.display.output(u'Initial Setup finished'); diff --git a/openlp/migration/migratesongs.py b/openlp/migration/migratesongs.py index e5af0bc4e..144c1a9ed 100644 --- a/openlp/migration/migratesongs.py +++ b/openlp/migration/migratesongs.py @@ -16,6 +16,7 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ import os +import sys import logging import sqlite3 from openlp.core.lib import PluginConfig @@ -24,20 +25,81 @@ from sqlalchemy import * from sqlalchemy.sql import select from sqlalchemy import create_engine from sqlalchemy.orm import scoped_session, sessionmaker, mapper, relation, clear_mappers - +from openlp.plugins.songs.lib.models import metadata, session, \ + engine, songs_table, Song, Author, Topic, Book from openlp.plugins.songs.lib.tables import * from openlp.plugins.songs.lib.classes import * -clear_mappers() -mapper(Author, authors_table) -mapper(Book, song_books_table) -mapper(Song, songs_table, properties={ - 'authors': relation(Author, backref='songs', - secondary=authors_songs_table), - 'book': relation(Book, backref='songs'), - 'topics': relation(Topic, backref='songs', - secondary=songs_topics_table)}) -mapper(Topic, topics_table) +def init_models(url): + engine = create_engine(url) + metadata.bind = engine + session = scoped_session(sessionmaker(autoflush=True, autocommit=False, + bind=engine)) + mapper(Author, authors_table) + mapper(TAuthor, temp_authors_table) + mapper(Book, song_books_table) + mapper(Song, songs_table, + properties={'authors': relation(Author, backref='songs', + secondary=authors_songs_table), + 'book': relation(Book, backref='songs'), + 'topics': relation(Topic, backref='songs', + secondary=songs_topics_table)}) + mapper(TSong, temp_songs_table) + mapper(TSongAuthor, temp_authors_songs_table) + mapper(Topic, topics_table) + return session + +temp_authors_table = Table(u'authors_temp', metadata, + Column(u'authorid', types.Integer, primary_key=True), + Column(u'authorname', String(40)) +) + +temp_songs_table = Table(u'songs_temp', metadata, + Column(u'songid', types.Integer, primary_key=True), + Column(u'songtitle', String(60)), + Column(u'lyrics', types.UnicodeText), + Column(u'copyrightinfo', String(255)), + Column(u'settingsid', types.Integer) +) + +# Definition of the "authors_songs" table +temp_authors_songs_table = Table(u'songauthors_temp', metadata, + Column(u'authorid', types.Integer, primary_key=True), + Column(u'songid', types.Integer) +) +class BaseModel(object): + """ + BaseModel provides a base object with a set of generic functions + """ + + @classmethod + def populate(cls, **kwargs): + """ + Creates an instance of a class and populates it, returning the instance + """ + me = cls() + keys = kwargs.keys() + for key in keys: + me.__setattr__(key, kwargs[key]) + return me + +class TAuthor(BaseModel): + """ + Author model + """ + pass + +class TSong(BaseModel): + """ + Author model + """ + pass + +class TSongAuthor(BaseModel): + """ + Author model + """ + pass class MigrateSongs(): def __init__(self, display): @@ -55,186 +117,61 @@ class MigrateSongs(): def v_1_9_0(self, database): self.display.output(u'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) - self._v1_9_0_songauthors(database) - self._v1_9_0_songtopics(database) - self._v1_9_0_songs(database) + self._v1_9_0_old(database) + self._v1_9_0_new(database) + self._v1_9_0_cleanup(database) self.display.output(u'Migration 1.9.0 Finished for ' + database) - def _v1_9_0_authors(self, database): - self.display.sub_output(u'Authors Started for ' + database) + def _v1_9_0_old(self, database): + self.display.sub_output(u'Rename Tables ' + database) conn = sqlite3.connect(self.data_path + os.sep + database) - conn.execute(u'""alter table authors rename to authors_temp;""') + conn.execute(u'alter table authors rename to authors_temp;') conn.commit() - self.display.sub_output(u'old author renamed to author_temp') - conn.execute(u'""create table authors ( - id integer primary key ASC AUTOINCREMENT, - first_name varchar(128), - last_name varchar(128), - display_name varchar(255) - );""') + conn.execute(u'alter table songs rename to songs_temp;') conn.commit() - self.display.sub_output(u'authors table created') - conn.execute(u'""create index if not exists author1 on authors - (display_name ASC,id ASC);""') + conn.execute(u'alter table songauthors rename to songauthors_temp;') conn.commit() - self.display.sub_output(u'index author1 created') - conn.execute(u'""create index if not exists author2 on authors - (last_name ASC,id ASC);""') - conn.commit() - self.display.sub_output(u'index author2 created') - conn.execute(u'""create index if not exists author3 on authors - (first_name ASC,id ASC);""') - conn.commit() - self.display.sub_output(u'index author3 created') - self.display.sub_output(u'Author Data Migration started') - conn.execute(u'""insert into authors (id, display_name) - select authorid, authorname from authors_temp;""') - conn.commit() - self.display.sub_output(u'authors populated') - c = conn.cursor() - text = c.execute(u'""select * from authors""') .fetchall() - for author in text: - dispname = author[3] - dispname = dispname.replace(u''", u'') - pos = dispname.rfind(u' ') - authorfirstname = dispname[:pos] - authorlastname = dispname[pos + 1:len(dispname)] - s = "update authors set first_name = '" \ - + authorfirstname + "', last_name = '" + authorlastname \ - + "' where id = " + unicode(author[0]) - c.execute(s) - conn.commit() - self.display.sub_output(u'Author Data Migration Completed') - conn.execute(u'""drop table authors_temp;""') - conn.commit() - conn.close() - self.display.sub_output(u'author_temp dropped') - self.display.sub_output(u'Authors Completed') - def _v1_9_0_songbook(self, database): - self.display.sub_output(u'SongBook Started for ' + database) - conn = sqlite3.connect(self.data_path + os.sep + database) - conn.execute(u'""create table if not exists song_books ( - id integer Primary Key ASC AUTOINCREMENT, - name varchar(128), - publisher varchar(128) - );""') - conn.commit() - self.display.sub_output(u'songbook table created') - conn.execute(u'""create index if not exists songbook1 on song_books (name ASC,id ASC);""') - conn.commit() - self.display.sub_output(u'index songbook1 created') - conn.execute(u'""create index if not exists songbook2 on song_books (publisher ASC,id ASC);""') - conn.commit() - conn.close() - self.display.sub_output(u'index songbook2 created') - self.display.sub_output(u'SongBook Completed') + def _v1_9_0_new(self, database): + self.display.sub_output(u'Create new Tables ' + database) + self.db_url = u'sqlite:///' + self.data_path + u'/songs.sqlite' + print self.db_url + self.session = init_models(self.db_url) + if not songs_table.exists(): + metadata.create_all() + results = self.session.query(TSong).order_by(TSong.songid).all() + for songs_temp in results: + song = Song() + song.title = songs_temp.songtitle + song.lyrics = songs_temp.lyrics.replace(u'\r\n', u'\n') + song.copyright = songs_temp.copyrightinfo + song.search_title = u'' + song.search_lyrics = u'' + print songs_temp.songtitle + aa = self.session.execute(u'select * from songauthors_temp where songid =' + unicode(songs_temp.songid) ) + for row in aa: + a = row['authorid'] + author = Author() + authors_temp = self.session.query(TAuthor).get(a) + author.display_name = authors_temp.authorname + song.authors.append(author) + try: + self.session.add(song) + self.session.commit() + except: + self.session.rollback() + print u'Errow thrown = ', sys.exc_info()[1] - def _v1_9_0_songs(self, database): - self.display.sub_output(u'Songs Started for ' + database) + def _v1_9_0_cleanup(self, database): + self.display.sub_output(u'Update Internal Data ' + database) conn = sqlite3.connect(self.data_path + os.sep + database) - conn.execute(u'""alter table songs rename to songs_temp;""') - conn.commit() - conn.execute(u'""create table if not exists songs ( - id integer Primary Key ASC AUTOINCREMENT, - song_book_id integer, - title varchar(255), - lyrics text, - verse_order varchar(128), - copyright varchar(255), - comments text, - ccli_number varchar(64), - song_number varchar(64), - theme_name varchar(128), - search_title varchar(255), - search_lyrics text - );""') - conn.commit() - self.display.sub_output(u'songs table created') - conn.execute(u'""create index if not exists songs1 on songs - (search_lyrics ASC,id ASC);""') - conn.commit() - self.display.sub_output(u'index songs1 created') - conn.execute(u'""create index if not exists songs2 on songs - (search_title ASC,id ASC);""') - conn.commit() - self.display.sub_output(u'index songs2 created') - conn.execute(u'""insert into songs (id, title, lyrics, copyright, - search_title, search_lyrics, song_book_id) - select songid, songtitle, lyrics, copyrightinfo, + conn.execute("""update songs set search_title = replace(replace(replace(replace(replace(replace(replace(replace( - replace(songtitle, '&', 'and'), ',', ''), ';', ''), ':', ''), - '(u', ''), ')', ''), '{', ''), '}',''),'?',''), + replace(title, '&', 'and'), ',', ''), ';', ''), ':', ''), + '(u', ''), ')', ''), '{', ''), '}',''),'?','');""") + conn.execute("""update songs set search_lyrics = replace(replace(replace(replace(replace(replace(replace(replace( replace(lyrics, '&', 'and'), ',', ''), ';', ''), ':', ''), - '(u', ''), ')', ''), '{', ''), '}',''),'?',''), - 0 - from songs_temp;""') + '(u', ''), ')', ''), '{', ''), '}',''),'?','') + ;""") conn.commit() - self.display.sub_output(u'songs populated') - conn.execute(u'""drop table songs_temp;""') - conn.commit() - conn.close() - self.display.sub_output(u'songs_temp dropped') - self.display.sub_output(u'Songs Completed') - - def _v1_9_0_topics(self, database): - self.display.sub_output(u'Topics Started for ' + database) - conn = sqlite3.connect(self.data_path+os.sep+database) - conn.text_factory = str - conn.execute(u'""create table if not exists topics - (id integer Primary Key ASC AUTOINCREMENT, - name varchar(128));""') - conn.commit() - self.display.sub_output(u'Topic table created') - conn.execute(u'""create index if not exists topic1 on topics (name ASC,id ASC);""') - conn.commit() - conn.close() - self.display.sub_output(u'index topic1 created') - - self.display.sub_output(u'Topics Completed') - - def _v1_9_0_songauthors(self, database): - self.display.sub_output(u'SongAuthors Started for ' + database); - conn = sqlite3.connect(self.data_path + os.sep + database) - conn.execute(u'""create table if not exists authors_songs - (author_id integer, - song_id integer);""') - conn.commit() - self.display.sub_output(u'authors_songs table created') - conn.execute(u'""insert into authors_songs (author_id, song_id) - select authorid, songid from songauthors;""') - conn.commit() - self.display.sub_output(u'authors_songs populated') - conn.execute(u'""drop table songauthors;""') - conn.commit() - self.display.sub_output(u'songauthors dropped') - conn.close() - self.display.sub_output(u'SongAuthors Completed') - - def _v1_9_0_songtopics(self, database): - self.display.sub_output(u'Songtopics Started for ' + database); - conn = sqlite3.connect(self.data_path+os.sep+database) - conn.execute(u'""create table if not exists song_topics - (song_id integer, - topic_id integer);""') - conn.commit() - self.display.sub_output(u'songtopics table created') - conn.execute(u'""create index if not exists songtopic1 on song_topics (topic_id ASC,song_id ASC);""') - conn.commit() - self.display.sub_output(u'index songtopic1 created') - conn.execute(u'""create index if not exists songtopic2 on song_topics (song_id ASC,topic_id ASC);""') - conn.commit() - conn.close() - self.display.sub_output(u'index songtopic2 created') - self.display.sub_output(u'SongTopics Completed') - - def run_cmd(self, cmd): - filein, fileout = os.popen4(cmd) - out = fileout.readlines() - if len(out) > 0: - for o in range (0, len(out)): - self.display.sub_output(out[o]) \ No newline at end of file diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index fe0f02156..b1f868a5c 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -45,7 +45,6 @@ class BibleList(QtGui.QListWidget): if dropAction == QtCore.Qt.CopyAction: self.close() - class BibleMediaItem(MediaManagerItem): """ This is the custom media manager item for Bibles. diff --git a/openlp/plugins/presentations/lib/impresscom.py b/openlp/plugins/presentations/lib/impresscom.py index a2a7ade6c..d522ae1d0 100644 --- a/openlp/plugins/presentations/lib/impresscom.py +++ b/openlp/plugins/presentations/lib/impresscom.py @@ -1,4 +1,4 @@ -from win32com.client import Dispatch +#from win32com.client import Dispatch # OOo API documentation: # http://api.openoffice.org/docs/common/ref/com/sun/star/presentation/XSlideShowController.html @@ -33,26 +33,26 @@ class ImpressCOMApp(object): self._app.Terminate() self._app = None self._sm = None - + class ImpressCOMPres(object): def __init__(self, oooApp, filename): self.oooApp = oooApp self.filename = filename self.open() - + def getPres(self): if self._pres == None: self.open() return self._pres - + pres = property(getPres) - + def open(self): - self.comp = self.oooApp.app.loadComponentFromURL(u'file:///" + self.filename, "_blank", 0, []) + self.comp = self.oooApp.app.loadComponentFromURL(u'file:///' + self.filename, '_blank', 0, []) self.presdoc = self.comp.getPresentation() self.presdoc.start() self._pres = self.presdoc.getController() - + def close(self): self.pres.deactivate() self.presdoc.end() @@ -63,7 +63,7 @@ class ImpressCOMPres(object): def isActive(self): return self.pres.isRunning() and self.pres.isActive() - + def resume(self): return self.pres.resume() @@ -72,7 +72,7 @@ class ImpressCOMPres(object): def blankScreen(self): self.pres.blankScreen(0) - + def stop(self): self.pres.deactivate() # self.presdoc.end() @@ -83,7 +83,7 @@ class ImpressCOMPres(object): def getSlideNumber(self): return self.pres.getCurrentSlideIndex - + def setSlideNumber(self, slideno): self.pres.gotoSlideIndex(slideno) @@ -112,7 +112,7 @@ class ImpressCOMSlide(object): if __name__ == '__main__': ooo = ImpressCOMApp() - show = ImpressCOMPres(ooo, "c:/test1.ppt') + show = ImpressCOMPres(ooo, u'c:/test1.ppt') show.go() show.resume() - show.nextStep() \ No newline at end of file + show.nextStep() diff --git a/openlp/plugins/songs/lib/tables.py b/openlp/plugins/songs/lib/tables.py index 59605a4b7..dea61861f 100644 --- a/openlp/plugins/songs/lib/tables.py +++ b/openlp/plugins/songs/lib/tables.py @@ -16,7 +16,7 @@ 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 sqlalchemy import * from sqlalchemy import Column, Table, ForeignKey, types from openlp.plugins.songs.lib.meta import metadata @@ -68,4 +68,15 @@ authors_songs_table = Table(u'authors_songs', metadata, songs_topics_table = Table(u'songs_topics', metadata, Column(u'song_id', types.Integer, ForeignKey(u'songs.id'), primary_key=True), Column(u'topic_id', types.Integer, ForeignKey(u'topics.id'), primary_key=True) -) \ No newline at end of file +) +Index(u'authors_id',authors_table.c.id) +Index(u'authors_display_name_id',authors_table.c.display_name, authors_table.c.id) +Index(u'song_books_id',song_books_table.c.id) +Index(u'songs_id',songs_table.c.id) +Index(u'songs_lyrics_id',songs_table.c.search_lyrics, songs_table.c.id) +Index(u'songs_title_id',songs_table.c.search_title, songs_table.c.id) +Index(u'topics_id',topics_table.c.id) +Index(u'authors_songs_author',authors_songs_table.c.author_id, authors_songs_table.c.song_id) +Index(u'authors_songs_song',authors_songs_table.c.song_id, authors_songs_table.c.author_id) +Index(u'topics_song_topic', songs_topics_table.c.topic_id, songs_topics_table.c.song_id) +Index(u'topics_song_song',songs_topics_table.c.song_id, songs_topics_table.c.topic_id) diff --git a/openlpcnv.pyw b/openlpcnv.pyw index 0b011b83c..333b4281e 100755 --- a/openlpcnv.pyw +++ b/openlpcnv.pyw @@ -1,6 +1,6 @@ #!/usr/bin/env python -import os +import os import sys import logging import time @@ -21,25 +21,25 @@ class Migration(): def __init__(self): """ """ - self.display = Display() - self.stime = time.strftime(u'%Y-%m-%d-%H%M%S", time.localtime()) - self.display.output(u'OpenLp v1.9.0 Migration Utility Started" ) - + self.display = Display() + self.stime = time.strftime(u'%Y-%m-%d-%H%M%S', time.localtime()) + self.display.output(u'OpenLp v1.9.0 Migration Utility Started') + def process(self): - MigrateFiles(self.display).process() + #MigrateFiles(self.display).process() MigrateSongs(self.display).process() - MigrateBibles(self.display).process() - + #MigrateBibles(self.display).process() + def move_log_file(self): fname = 'openlp-migration.log' c = os.path.splitext(fname) b = (c[0]+'-'+ unicode(self.stime) + c[1]) - self.display.output(u'Logfile " +b + " generated') + self.display.output(u'Logfile " +b + " generated') self.display.output(u'Migration Utility Finished ') - os.rename(fname, b) + os.rename(fname, b) + - if __name__ == '__main__': mig = Migration() mig.process() - #mig.move_log_file() \ No newline at end of file + #mig.move_log_file()