Merge lp:~googol-deactivatedaccount/openlp/bug-816186 into lp:openlp

Proposed by Andreas Preikschat
Status: Merged
Approved by: Tim Bentley
Approved revision: 1702
Merged at revision: 1702
Proposed branch: lp:~googol-deactivatedaccount/openlp/bug-816186
Merge into: lp:openlp
Diff against target: 115 lines (+27/-13)
2 files modified
openlp/plugins/songs/forms/songimportform.py (+2/-1)
openlp/plugins/songs/lib/olp1import.py (+25/-12)
To merge this branch: bzr merge lp:~googol-deactivatedaccount/openlp/bug-816186
Reviewer Review Type Date Requested Status
Tim Bentley Approve
Raoul Snyman Approve
Review via email: mp+70548@code.launchpad.net

Commit message

- fixed bug #816186 (1.2 version songs loose themes when imported into 1.9.6)
- fixed comments
- fixed wrong use of list comprehension

Description of the change

Hello,

1) fixed bug #816186 (1.2 version songs loose themes when imported into 1.9.6)
Only themes will be "imported" which are already present in the theme manager. So if you import your songs first and then your themes, then it was for nothing. The other way around did not appear to be the correct way (what is when you don't use all themes in v2?)

However, I targeted this bug for the documentation series (they should add a note to import themes first and then the songs).

2) Clean ups + list comprehension fix

To post a comment you must log in.
Revision history for this message
Raoul Snyman (raoul-snyman) :
review: Approve
Revision history for this message
Tim Bentley (trb143) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'openlp/plugins/songs/forms/songimportform.py'
--- openlp/plugins/songs/forms/songimportform.py 2011-06-20 21:57:34 +0000
+++ openlp/plugins/songs/forms/songimportform.py 2011-08-05 11:30:33 +0000
@@ -699,7 +699,8 @@
699 elif source_format == SongFormat.OpenLP1:699 elif source_format == SongFormat.OpenLP1:
700 # Import an openlp.org database700 # Import an openlp.org database
701 importer = self.plugin.importSongs(SongFormat.OpenLP1,701 importer = self.plugin.importSongs(SongFormat.OpenLP1,
702 filename=unicode(self.openLP1FilenameEdit.text())702 filename=unicode(self.openLP1FilenameEdit.text()),
703 plugin=self.plugin
703 )704 )
704 elif source_format == SongFormat.OpenLyrics:705 elif source_format == SongFormat.OpenLyrics:
705 # Import OpenLyrics songs706 # Import OpenLyrics songs
706707
=== modified file 'openlp/plugins/songs/lib/olp1import.py'
--- openlp/plugins/songs/lib/olp1import.py 2011-06-12 16:02:52 +0000
+++ openlp/plugins/songs/lib/olp1import.py 2011-08-05 11:30:33 +0000
@@ -57,6 +57,8 @@
57 The database providing the data to import.57 The database providing the data to import.
58 """58 """
59 SongImport.__init__(self, manager, **kwargs)59 SongImport.__init__(self, manager, **kwargs)
60 self.available_themes = \
61 kwargs[u'plugin'].formparent.themeManagerContents.getThemes()
6062
61 def do_import(self):63 def do_import(self):
62 """64 """
@@ -70,27 +72,34 @@
70 encoding = self.get_encoding()72 encoding = self.get_encoding()
71 if not encoding:73 if not encoding:
72 return74 return
73 # Connect to the database75 # Connect to the database.
74 connection = sqlite.connect(self.import_source, mode=0444,76 connection = sqlite.connect(self.import_source, mode=0444,
75 encoding=(encoding, 'replace'))77 encoding=(encoding, 'replace'))
76 cursor = connection.cursor()78 cursor = connection.cursor()
77 # Determine if we're using a new or an old DB79 # Determine if we're using a new or an old DB.
78 cursor.execute(u'SELECT name FROM sqlite_master '80 cursor.execute(u'SELECT name FROM sqlite_master '
79 u'WHERE type = \'table\' AND name = \'tracks\'')81 u'WHERE type = \'table\' AND name = \'tracks\'')
80 new_db = len(cursor.fetchall()) > 082 new_db = len(cursor.fetchall()) > 0
81 # "cache" our list of authors83 # "cache" our list of authors.
82 cursor.execute(u'-- types int, unicode')84 cursor.execute(u'-- types int, unicode')
83 cursor.execute(u'SELECT authorid, authorname FROM authors')85 cursor.execute(u'SELECT authorid, authorname FROM authors')
84 authors = cursor.fetchall()86 authors = cursor.fetchall()
85 if new_db:87 if new_db:
86 # "cache" our list of tracks88 # "cache" our list of tracks.
87 cursor.execute(u'-- types int, unicode')89 cursor.execute(u'-- types int, unicode')
88 cursor.execute(u'SELECT trackid, fulltrackname FROM tracks')90 cursor.execute(u'SELECT trackid, fulltrackname FROM tracks')
89 tracks = cursor.fetchall()91 tracks = cursor.fetchall()
90 # Import the songs92 # "cache" our list of themes.
91 cursor.execute(u'-- types int, unicode, unicode, unicode')93 cursor.execute(u'-- types int, unicode')
94 cursor.execute(u'SELECT settingsid, settingsname FROM settings')
95 themes = {}
96 for theme_id, theme_name in cursor.fetchall():
97 if theme_name in self.available_themes:
98 themes[theme_id] = theme_name
99 # Import the songs.
100 cursor.execute(u'-- types int, unicode, unicode, unicode, int')
92 cursor.execute(u'SELECT songid, songtitle, lyrics || \'\' AS lyrics, '101 cursor.execute(u'SELECT songid, songtitle, lyrics || \'\' AS lyrics, '
93 u'copyrightinfo FROM songs')102 u'copyrightinfo, settingsid FROM songs')
94 songs = cursor.fetchall()103 songs = cursor.fetchall()
95 self.import_wizard.progressBar.setMaximum(len(songs))104 self.import_wizard.progressBar.setMaximum(len(songs))
96 for song in songs:105 for song in songs:
@@ -101,8 +110,12 @@
101 self.title = song[1]110 self.title = song[1]
102 lyrics = song[2].replace(u'\r\n', u'\n')111 lyrics = song[2].replace(u'\r\n', u'\n')
103 self.add_copyright(song[3])112 self.add_copyright(song[3])
113 if themes.has_key(song[4]):
114 self.theme_name = themes[song[4]]
104 verses = lyrics.split(u'\n\n')115 verses = lyrics.split(u'\n\n')
105 [self.add_verse(verse.strip()) for verse in verses if verse.strip()]116 for verse in verses:
117 if verse.strip():
118 self.add_verse(verse.strip())
106 cursor.execute(u'-- types int')119 cursor.execute(u'-- types int')
107 cursor.execute(u'SELECT authorid FROM songauthors '120 cursor.execute(u'SELECT authorid FROM songauthors '
108 u'WHERE songid = %s' % song_id)121 u'WHERE songid = %s' % song_id)
@@ -137,12 +150,12 @@
137 """150 """
138 Detect character encoding of an openlp.org 1.x song database.151 Detect character encoding of an openlp.org 1.x song database.
139 """152 """
140 # Connect to the database153 # Connect to the database.
141 connection = sqlite.connect(self.import_source, mode=0444)154 connection = sqlite.connect(self.import_source, mode=0444)
142 cursor = connection.cursor()155 cursor = connection.cursor()
143156
144 detector = UniversalDetector()157 detector = UniversalDetector()
145 # detect charset by authors158 # Detect charset by authors.
146 cursor.execute(u'SELECT authorname FROM authors')159 cursor.execute(u'SELECT authorname FROM authors')
147 authors = cursor.fetchall()160 authors = cursor.fetchall()
148 for author in authors:161 for author in authors:
@@ -150,7 +163,7 @@
150 if detector.done:163 if detector.done:
151 detector.close()164 detector.close()
152 return detector.result[u'encoding']165 return detector.result[u'encoding']
153 # detect charset by songs166 # Detect charset by songs.
154 cursor.execute(u'SELECT songtitle, copyrightinfo, '167 cursor.execute(u'SELECT songtitle, copyrightinfo, '
155 u'lyrics || \'\' AS lyrics FROM songs')168 u'lyrics || \'\' AS lyrics FROM songs')
156 songs = cursor.fetchall()169 songs = cursor.fetchall()
@@ -160,7 +173,7 @@
160 if detector.done:173 if detector.done:
161 detector.close()174 detector.close()
162 return detector.result[u'encoding']175 return detector.result[u'encoding']
163 # detect charset by songs176 # Detect charset by songs.
164 cursor.execute(u'SELECT name FROM sqlite_master '177 cursor.execute(u'SELECT name FROM sqlite_master '
165 u'WHERE type = \'table\' AND name = \'tracks\'')178 u'WHERE type = \'table\' AND name = \'tracks\'')
166 if len(cursor.fetchall()) > 0:179 if len(cursor.fetchall()) > 0: