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
1=== modified file 'openlp/plugins/songs/forms/songimportform.py'
2--- openlp/plugins/songs/forms/songimportform.py 2011-06-20 21:57:34 +0000
3+++ openlp/plugins/songs/forms/songimportform.py 2011-08-05 11:30:33 +0000
4@@ -699,7 +699,8 @@
5 elif source_format == SongFormat.OpenLP1:
6 # Import an openlp.org database
7 importer = self.plugin.importSongs(SongFormat.OpenLP1,
8- filename=unicode(self.openLP1FilenameEdit.text())
9+ filename=unicode(self.openLP1FilenameEdit.text()),
10+ plugin=self.plugin
11 )
12 elif source_format == SongFormat.OpenLyrics:
13 # Import OpenLyrics songs
14
15=== modified file 'openlp/plugins/songs/lib/olp1import.py'
16--- openlp/plugins/songs/lib/olp1import.py 2011-06-12 16:02:52 +0000
17+++ openlp/plugins/songs/lib/olp1import.py 2011-08-05 11:30:33 +0000
18@@ -57,6 +57,8 @@
19 The database providing the data to import.
20 """
21 SongImport.__init__(self, manager, **kwargs)
22+ self.available_themes = \
23+ kwargs[u'plugin'].formparent.themeManagerContents.getThemes()
24
25 def do_import(self):
26 """
27@@ -70,27 +72,34 @@
28 encoding = self.get_encoding()
29 if not encoding:
30 return
31- # Connect to the database
32+ # Connect to the database.
33 connection = sqlite.connect(self.import_source, mode=0444,
34 encoding=(encoding, 'replace'))
35 cursor = connection.cursor()
36- # Determine if we're using a new or an old DB
37+ # Determine if we're using a new or an old DB.
38 cursor.execute(u'SELECT name FROM sqlite_master '
39 u'WHERE type = \'table\' AND name = \'tracks\'')
40 new_db = len(cursor.fetchall()) > 0
41- # "cache" our list of authors
42+ # "cache" our list of authors.
43 cursor.execute(u'-- types int, unicode')
44 cursor.execute(u'SELECT authorid, authorname FROM authors')
45 authors = cursor.fetchall()
46 if new_db:
47- # "cache" our list of tracks
48+ # "cache" our list of tracks.
49 cursor.execute(u'-- types int, unicode')
50 cursor.execute(u'SELECT trackid, fulltrackname FROM tracks')
51 tracks = cursor.fetchall()
52- # Import the songs
53- cursor.execute(u'-- types int, unicode, unicode, unicode')
54+ # "cache" our list of themes.
55+ cursor.execute(u'-- types int, unicode')
56+ cursor.execute(u'SELECT settingsid, settingsname FROM settings')
57+ themes = {}
58+ for theme_id, theme_name in cursor.fetchall():
59+ if theme_name in self.available_themes:
60+ themes[theme_id] = theme_name
61+ # Import the songs.
62+ cursor.execute(u'-- types int, unicode, unicode, unicode, int')
63 cursor.execute(u'SELECT songid, songtitle, lyrics || \'\' AS lyrics, '
64- u'copyrightinfo FROM songs')
65+ u'copyrightinfo, settingsid FROM songs')
66 songs = cursor.fetchall()
67 self.import_wizard.progressBar.setMaximum(len(songs))
68 for song in songs:
69@@ -101,8 +110,12 @@
70 self.title = song[1]
71 lyrics = song[2].replace(u'\r\n', u'\n')
72 self.add_copyright(song[3])
73+ if themes.has_key(song[4]):
74+ self.theme_name = themes[song[4]]
75 verses = lyrics.split(u'\n\n')
76- [self.add_verse(verse.strip()) for verse in verses if verse.strip()]
77+ for verse in verses:
78+ if verse.strip():
79+ self.add_verse(verse.strip())
80 cursor.execute(u'-- types int')
81 cursor.execute(u'SELECT authorid FROM songauthors '
82 u'WHERE songid = %s' % song_id)
83@@ -137,12 +150,12 @@
84 """
85 Detect character encoding of an openlp.org 1.x song database.
86 """
87- # Connect to the database
88+ # Connect to the database.
89 connection = sqlite.connect(self.import_source, mode=0444)
90 cursor = connection.cursor()
91
92 detector = UniversalDetector()
93- # detect charset by authors
94+ # Detect charset by authors.
95 cursor.execute(u'SELECT authorname FROM authors')
96 authors = cursor.fetchall()
97 for author in authors:
98@@ -150,7 +163,7 @@
99 if detector.done:
100 detector.close()
101 return detector.result[u'encoding']
102- # detect charset by songs
103+ # Detect charset by songs.
104 cursor.execute(u'SELECT songtitle, copyrightinfo, '
105 u'lyrics || \'\' AS lyrics FROM songs')
106 songs = cursor.fetchall()
107@@ -160,7 +173,7 @@
108 if detector.done:
109 detector.close()
110 return detector.result[u'encoding']
111- # detect charset by songs
112+ # Detect charset by songs.
113 cursor.execute(u'SELECT name FROM sqlite_master '
114 u'WHERE type = \'table\' AND name = \'tracks\'')
115 if len(cursor.fetchall()) > 0: