forked from openlp/openlp
Start work on the openlp.org 1.x importer.
Add a couple of fixes to the song import. Add a few fixes to the OpenSong importer.
This commit is contained in:
parent
2d9b39986a
commit
2901c79ed6
@ -52,7 +52,6 @@ class OpenLP1SongImport(SongImport):
|
|||||||
The database providing the data to import.
|
The database providing the data to import.
|
||||||
"""
|
"""
|
||||||
SongImport.__init__(self, manager)
|
SongImport.__init__(self, manager)
|
||||||
self.manager = manager
|
|
||||||
self.import_source = kwargs[u'filename']
|
self.import_source = kwargs[u'filename']
|
||||||
|
|
||||||
def do_import(self):
|
def do_import(self):
|
||||||
@ -61,71 +60,38 @@ class OpenLP1SongImport(SongImport):
|
|||||||
"""
|
"""
|
||||||
connection = sqlite.connect(self.import_source)
|
connection = sqlite.connect(self.import_source)
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
cursor.execute(u'SELECT COUNT(authorid) FROM authors')
|
||||||
|
count = int(cursor.fetchone()[0])
|
||||||
|
cursor.execute(u'SELECT COUNT(songid) FROM songs')
|
||||||
|
count = int(cursor.fetchone()[0])
|
||||||
|
self.import_wizard.importProgressBar.setMaximum(count)
|
||||||
|
|
||||||
# for song in source_songs:
|
old_cursor.execute(u'SELECT authorid AS id, authorname AS displayname FROM authors')
|
||||||
# new_song = Song()
|
rows = old_cursor.fetchall()
|
||||||
# new_song.title = song.title
|
if not debug and verbose:
|
||||||
# if has_media_files:
|
print 'done.'
|
||||||
# new_song.alternate_title = song.alternate_title
|
author_map = {}
|
||||||
# else:
|
for row in rows:
|
||||||
# old_titles = song.search_title.split(u'@')
|
display_name = unicode(row[1], u'cp1252')
|
||||||
# if len(old_titles) > 1:
|
names = display_name.split(u' ')
|
||||||
# new_song.alternate_title = old_titles[1]
|
first_name = names[0]
|
||||||
# else:
|
last_name = u' '.join(names[1:])
|
||||||
# new_song.alternate_title = u''
|
if last_name is None:
|
||||||
# new_song.search_title = song.search_title
|
last_name = u''
|
||||||
# new_song.song_number = song.song_number
|
sql_insert = u'INSERT INTO authors '\
|
||||||
# new_song.lyrics = song.lyrics
|
'(id, first_name, last_name, display_name) '\
|
||||||
# new_song.search_lyrics = song.search_lyrics
|
'VALUES (NULL, ?, ?, ?)'
|
||||||
# new_song.verse_order = song.verse_order
|
sql_params = (first_name, last_name, display_name)
|
||||||
# new_song.copyright = song.copyright
|
if debug:
|
||||||
# new_song.comments = song.comments
|
print '...', display_sql(sql_insert, sql_params)
|
||||||
# new_song.theme_name = song.theme_name
|
elif verbose:
|
||||||
# new_song.ccli_number = song.ccli_number
|
print '... importing "%s"' % display_name
|
||||||
# if song.authors:
|
new_cursor.execute(sql_insert, sql_params)
|
||||||
# for author in song.authors:
|
author_map[row[0]] = new_cursor.lastrowid
|
||||||
# existing_author = self.master_manager.get_object_filtered(
|
if debug:
|
||||||
# Author, Author.display_name == author.display_name)
|
print ' >>> authors.authorid =', row[0], 'authors.id =', author_map[row[0]]
|
||||||
# if existing_author:
|
|
||||||
# new_song.authors.append(existing_author)
|
|
||||||
# else:
|
cursor.execute(u'SELECT songid AS id, songtitle AS title, '
|
||||||
# new_song.authors.append(Author.populate(
|
u'lyrics || \'\' AS lyrics, copyrightinfo AS copyright FROM songs')
|
||||||
# first_name=author.first_name,
|
rows = cursor.fetchall()
|
||||||
# last_name=author.last_name,
|
|
||||||
# display_name=author.display_name))
|
|
||||||
# else:
|
|
||||||
# au = self.master_manager.get_object_filtered(Author,
|
|
||||||
# Author.display_name == u'Author Unknown')
|
|
||||||
# if au:
|
|
||||||
# new_song.authors.append(au)
|
|
||||||
# else:
|
|
||||||
# new_song.authors.append(Author.populate(
|
|
||||||
# display_name=u'Author Unknown'))
|
|
||||||
# if song.book:
|
|
||||||
# existing_song_book = self.master_manager.get_object_filtered(
|
|
||||||
# Book, Book.name == song.book.name)
|
|
||||||
# if existing_song_book:
|
|
||||||
# new_song.book = existing_song_book
|
|
||||||
# else:
|
|
||||||
# new_song.book = Book.populate(name=song.book.name,
|
|
||||||
# publisher=song.book.publisher)
|
|
||||||
# if song.topics:
|
|
||||||
# for topic in song.topics:
|
|
||||||
# existing_topic = self.master_manager.get_object_filtered(
|
|
||||||
# Topic, Topic.name == topic.name)
|
|
||||||
# if existing_topic:
|
|
||||||
# new_song.topics.append(existing_topic)
|
|
||||||
# else:
|
|
||||||
# new_song.topics.append(Topic.populate(name=topic.name))
|
|
||||||
## if has_media_files:
|
|
||||||
## if song.media_files:
|
|
||||||
## for media_file in song.media_files:
|
|
||||||
## existing_media_file = \
|
|
||||||
## self.master_manager.get_object_filtered(MediaFile,
|
|
||||||
## MediaFile.file_name == media_file.file_name)
|
|
||||||
## if existing_media_file:
|
|
||||||
## new_song.media_files.append(existing_media_file)
|
|
||||||
## else:
|
|
||||||
## new_song.media_files.append(MediaFile.populate(
|
|
||||||
## file_name=media_file.file_name))
|
|
||||||
# self.master_manager.save_object(new_song)
|
|
||||||
|
@ -125,6 +125,9 @@ class OpenSongImport(SongImport):
|
|||||||
if ext.lower() == u'.zip':
|
if ext.lower() == u'.zip':
|
||||||
log.debug(u'Zipfile found %s', filename)
|
log.debug(u'Zipfile found %s', filename)
|
||||||
z = ZipFile(filename, u'r')
|
z = ZipFile(filename, u'r')
|
||||||
|
self.import_wizard.importProgressBar.setMaximum(
|
||||||
|
self.import_wizard.importProgressBar.maximum() +
|
||||||
|
len(z.infolist()))
|
||||||
for song in z.infolist():
|
for song in z.infolist():
|
||||||
if self.stop_import_flag:
|
if self.stop_import_flag:
|
||||||
break
|
break
|
||||||
@ -138,6 +141,7 @@ class OpenSongImport(SongImport):
|
|||||||
self.do_import_file(songfile)
|
self.do_import_file(songfile)
|
||||||
if self.commit:
|
if self.commit:
|
||||||
self.finish()
|
self.finish()
|
||||||
|
self.set_defaults()
|
||||||
if self.stop_import_flag:
|
if self.stop_import_flag:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@ -148,6 +152,7 @@ class OpenSongImport(SongImport):
|
|||||||
self.do_import_file(file)
|
self.do_import_file(file)
|
||||||
if self.commit:
|
if self.commit:
|
||||||
self.finish()
|
self.finish()
|
||||||
|
self.set_defaults()
|
||||||
if not self.commit:
|
if not self.commit:
|
||||||
self.finish()
|
self.finish()
|
||||||
|
|
||||||
|
@ -52,6 +52,11 @@ class SongImport(QtCore.QObject):
|
|||||||
"""
|
"""
|
||||||
self.manager = manager
|
self.manager = manager
|
||||||
self.stop_import_flag = False
|
self.stop_import_flag = False
|
||||||
|
self.set_defaults()
|
||||||
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||||
|
QtCore.SIGNAL(u'songs_stop_import'), self.stop_import)
|
||||||
|
|
||||||
|
def set_defaults(self):
|
||||||
self.title = u''
|
self.title = u''
|
||||||
self.song_number = u''
|
self.song_number = u''
|
||||||
self.alternate_title = u''
|
self.alternate_title = u''
|
||||||
@ -71,8 +76,6 @@ class SongImport(QtCore.QObject):
|
|||||||
'SongsPlugin.SongImport', 'copyright'))
|
'SongsPlugin.SongImport', 'copyright'))
|
||||||
self.copyright_symbol = unicode(translate(
|
self.copyright_symbol = unicode(translate(
|
||||||
'SongsPlugin.SongImport', '\xa9'))
|
'SongsPlugin.SongImport', '\xa9'))
|
||||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
||||||
QtCore.SIGNAL(u'songs_stop_import'), self.stop_import)
|
|
||||||
|
|
||||||
def stop_import(self):
|
def stop_import(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user