openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #15464
[Merge] lp:~m2j/openlp/cleanups into lp:openlp
Meinert Jordan has proposed merging lp:~m2j/openlp/cleanups into lp:openlp.
Requested reviews:
Andreas Preikschat (googol)
For more details, see:
https://code.launchpad.net/~m2j/openlp/cleanups/+merge/104232
pythonifying code:
- replace has_key() by key in dict
- remove len() method from sequence and mapping types when mapping to bool
--
https://code.launchpad.net/~m2j/openlp/cleanups/+merge/104232
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/theme/theme.py'
--- openlp/core/theme/theme.py 2011-12-27 10:33:55 +0000
+++ openlp/core/theme/theme.py 2012-05-01 11:06:21 +0000
@@ -209,7 +209,7 @@
val = int(element_text[1:], 16)
except ValueError: # nope
pass
- elif DELPHI_COLORS.has_key(element_text):
+ elif element_text in DELPHI_COLORS:
val = DELPHI_COLORS[element_text]
delphi_color_change = True
else:
=== modified file 'openlp/core/ui/mainwindow.py'
--- openlp/core/ui/mainwindow.py 2012-04-22 19:37:11 +0000
+++ openlp/core/ui/mainwindow.py 2012-05-01 11:06:21 +0000
@@ -730,7 +730,7 @@
if self.liveController.display.isVisible():
self.liveController.display.setFocus()
self.activateWindow()
- if len(self.arguments):
+ if self.arguments:
args = []
for a in self.arguments:
args.extend([a])
=== modified file 'openlp/core/ui/servicemanager.py'
--- openlp/core/ui/servicemanager.py 2012-04-23 19:19:13 +0000
+++ openlp/core/ui/servicemanager.py 2012-05-01 11:06:21 +0000
@@ -483,7 +483,7 @@
service_item = item[u'service_item'].get_service_repr()
# Get all the audio files, and ready them for embedding in the
# service file.
- if len(service_item[u'header'][u'background_audio']) > 0:
+ if service_item[u'header'][u'background_audio']:
for i, filename in \
enumerate(service_item[u'header'][u'background_audio']):
new_file = os.path.join(u'audio',
@@ -822,7 +822,7 @@
"""
Called by the SlideController to select the next service item.
"""
- if len(self.serviceManagerList.selectedItems()) == 0:
+ if not self.serviceManagerList.selectedItems():
return
selected = self.serviceManagerList.selectedItems()[0]
lookFor = 0
@@ -840,7 +840,7 @@
"""
Called by the SlideController to select the previous service item.
"""
- if len(self.serviceManagerList.selectedItems()) == 0:
+ if not self.serviceManagerList.selectedItems():
return
selected = self.serviceManagerList.selectedItems()[0]
prevItem = None
=== modified file 'openlp/core/ui/shortcutlistform.py'
--- openlp/core/ui/shortcutlistform.py 2011-12-27 10:33:55 +0000
+++ openlp/core/ui/shortcutlistform.py 2012-05-01 11:06:21 +0000
@@ -151,7 +151,7 @@
if action is None:
continue
shortcuts = self._actionShortcuts(action)
- if len(shortcuts) == 0:
+ if not shortcuts:
item.setText(1, u'')
item.setText(2, u'')
elif len(shortcuts) == 1:
@@ -195,7 +195,7 @@
return
shortcuts = self._actionShortcuts(action)
new_shortcuts = []
- if len(shortcuts) != 0:
+ if shortcuts:
new_shortcuts.append(shortcuts[0])
new_shortcuts.append(
QtGui.QKeySequence(self.alternatePushButton.text()))
@@ -241,7 +241,7 @@
self.primaryPushButton.setChecked(False)
self.alternatePushButton.setChecked(False)
else:
- if len(action.defaultShortcuts) != 0:
+ if action.defaultShortcuts:
primary_label_text = action.defaultShortcuts[0].toString()
if len(action.defaultShortcuts) == 2:
alternate_label_text = action.defaultShortcuts[1].toString()
@@ -313,7 +313,7 @@
self.refreshShortcutList()
primary_button_text = u''
alternate_button_text = u''
- if len(temp_shortcuts) != 0:
+ if temp_shortcuts:
primary_button_text = temp_shortcuts[0].toString()
if len(temp_shortcuts) == 2:
alternate_button_text = temp_shortcuts[1].toString()
@@ -363,7 +363,7 @@
return
shortcuts = self._actionShortcuts(action)
new_shortcuts = []
- if len(action.defaultShortcuts) != 0:
+ if action.defaultShortcuts:
new_shortcuts.append(action.defaultShortcuts[0])
# We have to check if the primary default shortcut is available. But
# we only have to check, if the action has a default primary
@@ -391,7 +391,7 @@
return
shortcuts = self._actionShortcuts(action)
new_shortcuts = []
- if len(shortcuts) != 0:
+ if shortcuts:
new_shortcuts.append(shortcuts[0])
if len(action.defaultShortcuts) == 2:
new_shortcuts.append(action.defaultShortcuts[1])
=== modified file 'openlp/core/ui/slidecontroller.py'
--- openlp/core/ui/slidecontroller.py 2012-04-22 19:37:11 +0000
+++ openlp/core/ui/slidecontroller.py 2012-05-01 11:06:21 +0000
@@ -555,7 +555,7 @@
Process the service item request queue. The key presses can arrive
faster than the processing so implement a FIFO queue.
"""
- if len(self.keypress_queue):
+ if self.keypress_queue:
while len(self.keypress_queue) and not self.keypress_loop:
self.keypress_loop = True
keypressCommand = self.keypress_queue.popleft()
@@ -694,7 +694,7 @@
if item.is_text():
if QtCore.QSettings().value(
self.parent().songsSettingsSection + u'/display songbar',
- QtCore.QVariant(True)).toBool() and len(self.slideList) > 0:
+ QtCore.QVariant(True)).toBool() and self.slideList:
self.songMenu.show()
if item.is_capable(ItemCapabilities.CanLoop) and \
len(item.get_frames()) > 1:
=== modified file 'openlp/core/ui/thememanager.py'
--- openlp/core/ui/thememanager.py 2012-04-02 13:46:41 +0000
+++ openlp/core/ui/thememanager.py 2012-05-01 11:06:21 +0000
@@ -444,7 +444,7 @@
self.firstTime()
files = SettingsManager.get_files(self.settingsSection, u'.png')
# No themes have been found so create one
- if len(files) == 0:
+ if not files:
theme = ThemeXML()
theme.theme_name = UiStrings().Default
self._writeTheme(theme, None, None)
=== modified file 'openlp/core/utils/__init__.py'
--- openlp/core/utils/__init__.py 2012-03-23 06:36:24 +0000
+++ openlp/core/utils/__init__.py 2012-05-01 11:06:21 +0000
@@ -267,7 +267,7 @@
if code != 0:
raise Exception(u'Error running bzr tags')
lines = output.splitlines()
- if len(lines) == 0:
+ if not lines:
tag = u'0.0.0'
revision = u'0'
else:
=== modified file 'openlp/core/utils/actions.py'
--- openlp/core/utils/actions.py 2012-04-04 07:26:51 +0000
+++ openlp/core/utils/actions.py 2012-05-01 11:06:21 +0000
@@ -90,7 +90,7 @@
def append(self, name):
weight = 0
- if len(self.actions) > 0:
+ if self.actions:
weight = self.actions[-1][0] + 1
self.add(name, weight)
@@ -156,7 +156,7 @@
def append(self, name, actions=None):
weight = 0
- if len(self.categories) > 0:
+ if self.categories:
weight = self.categories[-1].weight + 1
if actions:
self.add(name, weight, actions)
=== modified file 'openlp/plugins/alerts/forms/alertform.py'
--- openlp/plugins/alerts/forms/alertform.py 2012-04-21 22:29:08 +0000
+++ openlp/plugins/alerts/forms/alertform.py 2012-05-01 11:06:21 +0000
@@ -101,7 +101,7 @@
self.alertTextEdit.setText(u'')
def onNewClick(self):
- if len(self.alertTextEdit.text()) == 0:
+ if not self.alertTextEdit.text():
QtGui.QMessageBox.information(self,
translate('AlertsPlugin.AlertForm', 'New Alert'),
translate('AlertsPlugin.AlertForm', 'You haven\'t specified '
=== modified file 'openlp/plugins/bibles/bibleplugin.py'
--- openlp/plugins/bibles/bibleplugin.py 2012-04-22 19:37:11 +0000
+++ openlp/plugins/bibles/bibleplugin.py 2012-05-01 11:06:21 +0000
@@ -62,7 +62,7 @@
# unicode(UiStrings().Export))
# Set to invisible until we can export bibles
self.exportBibleItem.setVisible(False)
- if len(self.manager.old_bible_databases):
+ if self.manager.old_bible_databases:
self.toolsUpgradeItem.setVisible(True)
def finalise(self):
@@ -83,7 +83,7 @@
"""
Perform tasks on application startup
"""
- if len(self.manager.old_bible_databases):
+ if self.manager.old_bible_databases:
if QtGui.QMessageBox.information(self.formParent,
translate('OpenLP', 'Information'), translate('OpenLP',
'Bible format has changed.\nYou have to upgrade your '
=== modified file 'openlp/plugins/bibles/forms/bibleupgradeform.py'
--- openlp/plugins/bibles/forms/bibleupgradeform.py 2012-04-22 18:19:36 +0000
+++ openlp/plugins/bibles/forms/bibleupgradeform.py 2012-05-01 11:06:21 +0000
@@ -426,8 +426,7 @@
if meta[u'key'] == u'download_source':
web_bible = True
self.includeWebBible = True
- if meta.has_key(u'proxy_server'):
- proxy_server = meta[u'proxy_server']
+ proxy_server = meta.get(u'proxy_server')
if web_bible:
if meta_data[u'download_source'].lower() == u'crosswalk':
handler = CWExtract(proxy_server)
@@ -572,7 +571,7 @@
int(verse[u'verse']), unicode(verse[u'text']))
Receiver.send_message(u'openlp_process_events')
self.newbibles[number].session.commit()
- if self.success.has_key(number) and not self.success[number]:
+ if not self.success.get(number, True):
self.incrementProgressBar(unicode(translate(
'BiblesPlugin.UpgradeWizardForm',
'Upgrading Bible %s of %s: "%s"\nFailed')) %
@@ -586,7 +585,7 @@
'Upgrading Bible %s of %s: "%s"\n'
'Complete')) %
(number + 1, max_bibles, name))
- if self.newbibles.has_key(number):
+ if number in self.newbibles:
self.newbibles[number].session.close()
# Close the last bible's connection if possible.
if old_bible is not None:
@@ -599,7 +598,7 @@
successful_import = 0
failed_import = 0
for number, filename in enumerate(self.files):
- if self.success.has_key(number) and self.success[number]:
+ if self.success.get(number):
successful_import += 1
elif self.checkBox[number].checkState() == QtCore.Qt.Checked:
failed_import += 1
=== modified file 'openlp/plugins/bibles/lib/__init__.py'
--- openlp/plugins/bibles/lib/__init__.py 2012-04-21 22:29:08 +0000
+++ openlp/plugins/bibles/lib/__init__.py 2012-05-01 11:06:21 +0000
@@ -236,7 +236,7 @@
``separator_type``
The role and format of the separator.
"""
- if len(REFERENCE_SEPARATORS) == 0:
+ if not REFERENCE_SEPARATORS:
update_reference_separators()
return REFERENCE_SEPARATORS[separator_type]
@@ -247,7 +247,7 @@
``match_type``
The type of match is ``range_separator``, ``range`` or ``full``.
"""
- if len(REFERENCE_MATCHES) == 0:
+ if not REFERENCE_MATCHES:
update_reference_separators()
return REFERENCE_MATCHES[match_type]
=== modified file 'openlp/plugins/bibles/lib/http.py'
--- openlp/plugins/bibles/lib/http.py 2012-04-22 18:19:36 +0000
+++ openlp/plugins/bibles/lib/http.py 2012-05-01 11:06:21 +0000
@@ -106,7 +106,7 @@
verse_list = {}
# Cater for inconsistent mark up in the first verse of a chapter.
first_verse = verses.find(u'versenum')
- if first_verse and len(first_verse.contents):
+ if first_verse and first_verse.contents:
verse_list[1] = unicode(first_verse.contents[0])
for verse in verses(u'sup', u'versenum'):
raw_verse_num = verse.next
=== modified file 'openlp/plugins/bibles/lib/mediaitem.py'
--- openlp/plugins/bibles/lib/mediaitem.py 2012-04-21 22:29:08 +0000
+++ openlp/plugins/bibles/lib/mediaitem.py 2012-05-01 11:06:21 +0000
@@ -392,7 +392,7 @@
if bible in bibles:
find_and_set_in_combo_box(self.advancedVersionComboBox, bible)
self.initialiseAdvancedBible(unicode(bible))
- elif len(bibles):
+ elif bibles:
self.initialiseAdvancedBible(bibles[0])
bible = QtCore.QSettings().value(
self.settingsSection + u'/quick bible', QtCore.QVariant(
@@ -878,7 +878,7 @@
items = item
else:
items = self.listView.selectedItems()
- if len(items) == 0:
+ if not items:
return False
bible_text = u''
old_item = None
@@ -949,7 +949,7 @@
# Service Item: Title
service_item.title = create_separated_list(raw_title)
# Service Item: Theme
- if len(self.settings.bible_theme) == 0:
+ if not self.settings.bible_theme:
service_item.theme = None
else:
service_item.theme = self.settings.bible_theme
=== modified file 'openlp/plugins/custom/forms/editcustomform.py'
--- openlp/plugins/custom/forms/editcustomform.py 2012-04-02 00:19:16 +0000
+++ openlp/plugins/custom/forms/editcustomform.py 2012-05-01 11:06:21 +0000
@@ -254,7 +254,7 @@
Checks whether a custom is valid or not.
"""
# We must have a title.
- if len(self.titleEdit.displayText()) == 0:
+ if not self.titleEdit.displayText():
self.titleEdit.setFocus()
critical_error_message_box(
message=translate('CustomPlugin.EditCustomForm',
=== modified file 'openlp/plugins/custom/lib/mediaitem.py'
--- openlp/plugins/custom/lib/mediaitem.py 2012-04-21 22:29:08 +0000
+++ openlp/plugins/custom/lib/mediaitem.py 2012-05-01 11:06:21 +0000
@@ -258,7 +258,7 @@
search_length = 2
if len(text) > search_length:
self.onSearchTextButtonClicked()
- elif len(text) == 0:
+ elif not text:
self.onClearTextButtonClick()
def onClearTextButtonClick(self):
=== modified file 'openlp/plugins/songs/forms/editverseform.py'
--- openlp/plugins/songs/forms/editverseform.py 2012-04-02 14:23:25 +0000
+++ openlp/plugins/songs/forms/editverseform.py 2012-05-01 11:06:21 +0000
@@ -191,13 +191,13 @@
else:
log.debug(unicode(self.getVerse()[0]).split(u'\n'))
value = unicode(self.getVerse()[0]).split(u'\n')[1]
- if len(value) == 0:
+ if not value:
lines = unicode(self.getVerse()[0]).split(u'\n')
index = 2
- while index < len(lines) and len(value) == 0:
+ while index < len(lines) and not value:
value = lines[index]
index += 1
- if len(value) == 0:
+ if not value:
critical_error_message_box(
message=translate('SongsPlugin.EditSongForm',
'You need to type some text in to the verse.'))
=== modified file 'openlp/plugins/songs/forms/songmaintenanceform.py'
--- openlp/plugins/songs/forms/songmaintenanceform.py 2012-04-02 00:19:16 +0000
+++ openlp/plugins/songs/forms/songmaintenanceform.py 2012-05-01 11:06:21 +0000
@@ -108,7 +108,7 @@
item_id = self._getCurrentItemId(list_widget)
if item_id != -1:
item = self.manager.get_object(item_class, item_id)
- if item and len(item.songs) == 0:
+ if item and not item.songs:
if critical_error_message_box(dlg_title, del_text, self,
True) == QtGui.QMessageBox.Yes:
self.manager.delete_object(item_class, item.id)
@@ -191,7 +191,7 @@
``edit``
If we edit an item, this should be *True*.
"""
- if len(objects) > 0:
+ if objects:
# If we edit an existing object, we need to make sure that we do
# not return False when nothing has changed.
if edit:
=== modified file 'openlp/plugins/songs/lib/__init__.py'
--- openlp/plugins/songs/lib/__init__.py 2012-04-04 07:26:51 +0000
+++ openlp/plugins/songs/lib/__init__.py 2012-05-01 11:06:21 +0000
@@ -316,7 +316,7 @@
verse_type,
verse[0][u'label'],
verse[1],
- verse[0][u'lang'] if verse[0].has_key(u'lang') else None
+ verse[0].get(u'lang')
)
compare_order.append((u'%s%s' % (verse_type, verse[0][u'label'])
).upper())
=== modified file 'openlp/plugins/songs/lib/cclifileimport.py'
--- openlp/plugins/songs/lib/cclifileimport.py 2012-03-15 22:38:03 +0000
+++ openlp/plugins/songs/lib/cclifileimport.py 2012-05-01 11:06:21 +0000
@@ -211,7 +211,7 @@
elif verse_lines[0].startswith(u'('):
verse_type = VerseType.Tags[VerseType.Other]
verse_text = verse_lines[1]
- if len(verse_text) > 0:
+ if verse_text:
self.addVerse(verse_text, verse_type)
check_first_verse_line = False
# Handle multiple authors
=== modified file 'openlp/plugins/songs/lib/easyslidesimport.py'
--- openlp/plugins/songs/lib/easyslidesimport.py 2011-12-31 19:00:27 +0000
+++ openlp/plugins/songs/lib/easyslidesimport.py 2012-05-01 11:06:21 +0000
@@ -162,15 +162,12 @@
separatorlines = 0
for line in lines:
line = line.strip()
- if len(line) == 0:
+ if not line:
continue
elif line[1:7] == u'region':
# this is region separator, probably [region 2]
region = self._extractRegion(line)
- if regionlines.has_key(region):
- regionlines[region] = regionlines[region] + 1
- else:
- regionlines[region] = 1
+ regionlines[region] = 1 + regionlines.get(region, 0)
elif line[0] == u'[':
separatorlines = separatorlines + 1
# if the song has separators
@@ -206,7 +203,7 @@
for line in lines:
line = line.strip()
- if len(line) == 0:
+ if not line:
if separators:
# separators are used, so empty line means slide break
# inside verse
@@ -215,15 +212,11 @@
else:
# separators are not used, so empty line starts a new verse
vt = u'V'
- if verses[reg].has_key(vt):
- vn = len(verses[reg][vt].keys())+1
- else:
- vn = u'1'
+ vn = len(verses[reg].get(vt, {})) + 1
inst = 1
elif line[0:7] == u'[region':
reg = self._extractRegion(line)
- if not verses.has_key(reg):
- verses[reg] = {}
+ verses.setdefault(reg, {})
if not regionsInVerses:
vt = u'V'
vn = u'1'
@@ -238,28 +231,19 @@
if match:
marker = match.group(1).strip()
vn = match.group(2)
- if len(marker) == 0:
- vt = u'V'
- elif MarkTypes.has_key(marker):
- vt = MarkTypes[marker]
- else:
- vt = u'O'
+ vt = MarkTypes.get(marker, u'O') if marker else u'V'
if regionsInVerses:
region = defaultregion
inst = 1
if self._listHas(verses, [reg, vt, vn, inst]):
- inst = len(verses[reg][vt][vn])+1
+ inst = len(verses[reg][vt][vn]) + 1
else:
if not [reg, vt, vn, inst] in our_verse_order:
our_verse_order.append([reg, vt, vn, inst])
- if not verses[reg].has_key(vt):
- verses[reg][vt] = {}
- if not verses[reg][vt].has_key(vn):
- verses[reg][vt][vn] = {}
- if not verses[reg][vt][vn].has_key(inst):
- verses[reg][vt][vn][inst] = []
- words = self.tidyText(line)
- verses[reg][vt][vn][inst].append(words)
+ verses[reg].setdefault(vt, {})
+ verses[reg][vt].setdefault(vn, {})
+ verses[reg][vt][vn].setdefault(inst, [])
+ verses[reg][vt][vn][inst].append(self.tidyText(line))
# done parsing
versetags = []
@@ -286,11 +270,11 @@
try:
order = unicode(song.Sequence).strip().split(u',')
for tag in order:
- if len(tag) == 0:
+ if not tag:
continue
elif tag[0].isdigit():
tag = u'V' + tag
- elif SeqTypes.has_key(tag.lower()):
+ elif tag.lower() in SeqTypes:
tag = SeqTypes[tag.lower()]
else:
continue
@@ -307,9 +291,7 @@
def _listHas(self, lst, subitems):
for subitem in subitems:
- if isinstance(lst, dict) and lst.has_key(subitem):
- lst = lst[subitem]
- elif isinstance(lst, list) and subitem in lst:
+ if subitem in lst:
lst = lst[subitem]
else:
return False
=== modified file 'openlp/plugins/songs/lib/ewimport.py'
--- openlp/plugins/songs/lib/ewimport.py 2011-12-27 10:33:55 +0000
+++ openlp/plugins/songs/lib/ewimport.py 2012-05-01 11:06:21 +0000
@@ -62,15 +62,15 @@
if control:
# for delimiters, set control to False
if c == '{':
- if len(control_word) > 0:
+ if control_word:
depth += 1
control = False
elif c == '}':
- if len(control_word) > 0:
+ if control_word:
depth -= 1
control = False
elif c == '\\':
- new_control = (len(control_word) > 0)
+ new_control = bool(control_word)
control = False
elif c.isspace():
control = False
@@ -79,7 +79,7 @@
if len(control_word) == 3 and control_word[0] == '\'':
control = False
if not control:
- if len(control_word) == 0:
+ if not control_word:
if c == '{' or c == '}' or c == '\\':
clear_text.append(c)
else:
@@ -360,7 +360,7 @@
field_desc = self.fieldDescs[field_desc_index]
# Return None in case of 'blank' entries
if isinstance(field, str):
- if len(field.rstrip('\0')) == 0:
+ if not field.rstrip('\0'):
return None
elif field == 0:
return None
=== modified file 'openlp/plugins/songs/lib/mediaitem.py'
--- openlp/plugins/songs/lib/mediaitem.py 2012-04-21 22:29:08 +0000
+++ openlp/plugins/songs/lib/mediaitem.py 2012-05-01 11:06:21 +0000
@@ -295,9 +295,8 @@
log.debug(u'display results Book')
self.listView.clear()
for book in searchresults:
- songs = sorted(book.songs, key=lambda song: int(
- re.sub(r'[^0-9]', u' ', song.song_number).partition(' ')[0])
- if len(re.sub(r'[^\w]', ' ', song.song_number)) else 0)
+ songs = sorted(book.songs, key=lambda song:
+ int(re.match(r'[0-9]+', u'0' + song.song_number).group()))
for song in songs:
# Do not display temporary songs
if song.temporary:
@@ -331,7 +330,7 @@
search_length = 3
if len(text) > search_length:
self.onSearchTextButtonClicked()
- elif len(text) == 0:
+ elif not text:
self.onClearTextButtonClick()
def onImportClick(self):
@@ -491,7 +490,7 @@
else:
# Loop through the verse list and expand the song accordingly.
for order in song.verse_order.lower().split():
- if len(order) == 0:
+ if not order:
break
for verse in verseList:
if verse[0][u'type'][0].lower() == order[0] and \
@@ -530,7 +529,7 @@
u'authors': u', '.join(author_list)}
service_item.xml_version = self.openLyrics.song_to_xml(song)
# Add the audio file to the service item.
- if len(song.media_files) > 0:
+ if song.media_files:
service_item.add_capability(ItemCapabilities.HasBackgroundAudio)
service_item.background_audio = \
[m.file_name for m in song.media_files]
@@ -575,12 +574,12 @@
editId = song.id
break
# If there's any backing tracks, copy them over.
- if len(item.background_audio) > 0:
+ if item.background_audio:
self._updateBackgroundAudio(song, item)
if add_song and self.addSongFromService:
song = self.openLyrics.xml_to_song(item.xml_version)
# If there's any backing tracks, copy them over.
- if len(item.background_audio) > 0:
+ if item.background_audio:
self._updateBackgroundAudio(song, item)
editId = song.id
self.onSearchTextButtonClicked()
@@ -588,7 +587,7 @@
# Make sure we temporary import formatting tags.
song = self.openLyrics.xml_to_song(item.xml_version, True)
# If there's any backing tracks, copy them over.
- if len(item.background_audio) > 0:
+ if item.background_audio:
self._updateBackgroundAudio(song, item)
editId = song.id
temporary = True
=== modified file 'openlp/plugins/songs/lib/olp1import.py'
--- openlp/plugins/songs/lib/olp1import.py 2012-04-21 22:29:08 +0000
+++ openlp/plugins/songs/lib/olp1import.py 2012-05-01 11:06:21 +0000
@@ -122,8 +122,7 @@
cursor.execute(
u'SELECT settingsid FROM songs WHERE songid = %s' % song_id)
theme_id = cursor.fetchone()[0]
- if themes.has_key(theme_id):
- self.themeName = themes[theme_id]
+ self.themeName = themes.get(theme_id, u'')
verses = lyrics.split(u'\n\n')
for verse in verses:
if verse.strip():
@@ -191,7 +190,7 @@
# Detect charset by songs.
cursor.execute(u'SELECT name FROM sqlite_master '
u'WHERE type = \'table\' AND name = \'tracks\'')
- if len(cursor.fetchall()) > 0:
+ if cursor.fetchall():
cursor.execute(u'SELECT fulltrackname FROM tracks')
tracks = cursor.fetchall()
for track in tracks:
=== modified file 'openlp/plugins/songs/lib/opensongimport.py'
--- openlp/plugins/songs/lib/opensongimport.py 2012-04-02 20:53:21 +0000
+++ openlp/plugins/songs/lib/opensongimport.py 2012-05-01 11:06:21 +0000
@@ -174,7 +174,7 @@
if semicolon >= 0:
this_line = this_line[:semicolon]
this_line = this_line.strip()
- if not len(this_line):
+ if not this_line:
continue
# skip guitar chords and page and column breaks
if this_line.startswith(u'.') or this_line.startswith(u'---') \
@@ -197,15 +197,12 @@
# the verse tag
verse_tag = content
verse_num = u'1'
- if len(verse_tag) == 0:
- verse_index = 0
- else:
- verse_index = VerseType.from_loose_input(verse_tag)
+ verse_index = VerseType.from_loose_input(verse_tag) \
+ if verse_tag else 0
verse_tag = VerseType.Tags[verse_index]
inst = 1
if [verse_tag, verse_num, inst] in our_verse_order \
- and verses.has_key(verse_tag) \
- and verses[verse_tag].has_key(verse_num):
+ and verse_num in verses.get(verse_tag, {}):
inst = len(verses[verse_tag][verse_num]) + 1
continue
# number at start of line.. it's verse number
@@ -213,11 +210,9 @@
verse_num = this_line[0]
this_line = this_line[1:].strip()
our_verse_order.append([verse_tag, verse_num, inst])
- if not verses.has_key(verse_tag):
- verses[verse_tag] = {}
- if not verses[verse_tag].has_key(verse_num):
- verses[verse_tag][verse_num] = {}
- if not verses[verse_tag][verse_num].has_key(inst):
+ verses.setdefault(verse_tag, {})
+ verses[verse_tag].setdefault(verse_num, {})
+ if inst not in verses[verse_tag][verse_num]:
verses[verse_tag][verse_num][inst] = []
our_verse_order.append([verse_tag, verse_num, inst])
# Tidy text and remove the ____s from extended words
@@ -252,15 +247,14 @@
if match is not None:
verse_tag = match.group(1)
verse_num = match.group(2)
- if not len(verse_tag):
+ if not verse_tag:
verse_tag = VerseType.Tags[VerseType.Verse]
else:
# Assume it's no.1 if there are no digits
verse_tag = verse_def
verse_num = u'1'
verse_def = u'%s%s' % (verse_tag, verse_num)
- if verses.has_key(verse_tag) and \
- verses[verse_tag].has_key(verse_num):
+ if verse_num in verses.get(verse_tag, {}):
self.verseOrderList.append(verse_def)
else:
log.info(u'Got order %s but not in verse tags, dropping'
=== modified file 'openlp/plugins/songs/lib/songimport.py'
--- openlp/plugins/songs/lib/songimport.py 2012-04-03 17:58:42 +0000
+++ openlp/plugins/songs/lib/songimport.py 2012-05-01 11:06:21 +0000
@@ -61,9 +61,9 @@
"""
self.manager = manager
QtCore.QObject.__init__(self)
- if kwargs.has_key(u'filename'):
+ if u'filename' in kwargs:
self.importSource = kwargs[u'filename']
- elif kwargs.has_key(u'filenames'):
+ elif u'filenames' in kwargs:
self.importSource = kwargs[u'filenames']
else:
raise KeyError(u'Keyword arguments "filename[s]" not supplied.')
@@ -273,7 +273,7 @@
Author not checked here, if no author then "Author unknown" is
automatically added
"""
- if not self.title or not len(self.verses):
+ if not self.title or not self.verses:
return False
else:
return True
@@ -314,13 +314,10 @@
verse_def = new_verse_def
sxml.add_verse_to_lyrics(verse_tag, verse_def[1:], verse_text, lang)
song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
- if not len(self.verseOrderList) and \
- self.verseOrderListGeneratedUseful:
+ if not self.verseOrderList and self.verseOrderListGeneratedUseful:
self.verseOrderList = self.verseOrderListGenerated
- for i, current_verse_def in enumerate(self.verseOrderList):
- if verses_changed_to_other.has_key(current_verse_def):
- self.verseOrderList[i] = \
- verses_changed_to_other[current_verse_def]
+ self.verseOrderList = map(lambda v: verses_changed_to_other.get(v, v),
+ self.verseOrderList)
song.verse_order = u' '.join(self.verseOrderList)
song.copyright = self.copyright
song.comments = self.comments
=== modified file 'openlp/plugins/songs/lib/songshowplusimport.py'
--- openlp/plugins/songs/lib/songshowplusimport.py 2012-03-27 20:09:01 +0000
+++ openlp/plugins/songs/lib/songshowplusimport.py 2012-05-01 11:06:21 +0000
@@ -204,7 +204,7 @@
elif verse_type == "pre-chorus":
verse_tag = VerseType.Tags[VerseType.PreChorus]
else:
- if not self.otherList.has_key(verse_name):
+ if verse_name not in self.otherList:
if ignore_unique:
return None
self.otherCount = self.otherCount + 1
=== modified file 'openlp/plugins/songs/lib/xml.py'
--- openlp/plugins/songs/lib/xml.py 2012-04-21 22:29:08 +0000
+++ openlp/plugins/songs/lib/xml.py 2012-05-01 11:06:21 +0000
@@ -611,7 +611,7 @@
text += u'{%s}' % element.get(u'name')
# Some formattings may have only start tag.
# Handle this case if element has no children and contains no text.
- if len(element) == 0 and not element.text:
+ if not element and not element.text:
use_endtag = False
# Append text from element.
if element.text:
=== modified file 'openlp/plugins/songs/songsplugin.py'
--- openlp/plugins/songs/songsplugin.py 2012-04-22 19:37:11 +0000
+++ openlp/plugins/songs/songsplugin.py 2012-05-01 11:06:21 +0000
@@ -239,7 +239,7 @@
for sfile in os.listdir(db_dir):
if sfile.startswith(u'songs_') and sfile.endswith(u'.sqlite'):
song_dbs.append(os.path.join(db_dir, sfile))
- if len(song_dbs) == 0:
+ if not song_dbs:
return
progress = QtGui.QProgressDialog(self.formParent)
progress.setWindowModality(QtCore.Qt.WindowModal)
Follow ups