From c2a0944e6be51fa20b63037b780a84192d4ba311 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Tue, 3 Nov 2009 19:01:53 +0000 Subject: [PATCH] More truth testing cleanup - plugins --- openlp.pyw | 2 +- openlp/plugins/bibles/bibleplugin.py | 2 +- openlp/plugins/bibles/forms/bibleimportform.py | 4 ++-- openlp/plugins/bibles/lib/bibleDBimpl.py | 2 +- openlp/plugins/bibles/lib/common.py | 2 +- openlp/plugins/bibles/lib/manager.py | 15 ++++++++------- openlp/plugins/bibles/lib/mediaitem.py | 8 ++++---- openlp/plugins/custom/lib/mediaitem.py | 8 ++++---- openlp/plugins/media/lib/mediaitem.py | 2 +- .../presentations/lib/impresscontroller.py | 4 ++-- openlp/plugins/presentations/lib/mediaitem.py | 4 ++-- .../presentations/lib/messagelistener.py | 2 +- .../presentations/lib/pptviewcontroller.py | 2 +- openlp/plugins/remotes/remoteclient-cli.py | 2 +- openlp/plugins/remotes/remoteplugin.py | 2 +- openlp/plugins/songs/forms/editsongform.py | 12 ++++++------ .../plugins/songs/forms/songmaintenanceform.py | 9 +++++---- openlp/plugins/songs/lib/mediaitem.py | 18 ++++++++++-------- openlp/plugins/songs/lib/songxml.py | 18 +++++++++--------- 19 files changed, 61 insertions(+), 57 deletions(-) diff --git a/openlp.pyw b/openlp.pyw index aaf1867e4..fffed8726 100755 --- a/openlp.pyw +++ b/openlp.pyw @@ -137,7 +137,7 @@ def main(): log.addHandler(logfile) # Parse command line options and deal with them. (options, args) = parser.parse_args() - if options.debug is not None: + if options.debug: log.setLevel(logging.DEBUG) else: log.setLevel(logging.INFO) diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index d797b44cc..ef0308925 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -85,7 +85,7 @@ class BiblePlugin(Plugin): self.ExportBibleItem.setVisible(False) def onBibleNewClick(self): - if self.media_item is not None: + if self.media_item: self.media_item.onNewClick() def about(self): diff --git a/openlp/plugins/bibles/forms/bibleimportform.py b/openlp/plugins/bibles/forms/bibleimportform.py index 1a4084424..de7397355 100644 --- a/openlp/plugins/bibles/forms/bibleimportform.py +++ b/openlp/plugins/bibles/forms/bibleimportform.py @@ -199,7 +199,7 @@ class BibleImportForm(QtGui.QDialog, Ui_BibleImportDialog): def onImportButtonClicked(self): message = self.trUtf8(u'Bible import completed') - if self.biblemanager is not None: + if self.biblemanager: if not self.bible_type is None and \ len(self.BibleNameEdit.displayText()) > 0: self.MessageLabel.setText(self.trUtf8(u'Import Started')) @@ -208,7 +208,7 @@ class BibleImportForm(QtGui.QDialog, Ui_BibleImportDialog): self.ProgressBar.setValue(0) self.biblemanager.process_dialog(self) status, msg = self.importBible() - if msg is not None: + if msg: message = msg self.MessageLabel.setText(message) self.ProgressBar.setValue(self.barmax) diff --git a/openlp/plugins/bibles/lib/bibleDBimpl.py b/openlp/plugins/bibles/lib/bibleDBimpl.py index 756828197..fd67294c6 100644 --- a/openlp/plugins/bibles/lib/bibleDBimpl.py +++ b/openlp/plugins/bibles/lib/bibleDBimpl.py @@ -160,7 +160,7 @@ class BibleDBImpl(BibleCommon): everse) #Look up book name or abbreviation book = self.get_bible_book(bookname) - if book is not None: + if book: bookname = book.name log.debug(u'bookname corrected to %s' % bookname) verses = self.session.query(Verse).join(Book).filter( diff --git a/openlp/plugins/bibles/lib/common.py b/openlp/plugins/bibles/lib/common.py index a7c39dca9..8cc4e461e 100644 --- a/openlp/plugins/bibles/lib/common.py +++ b/openlp/plugins/bibles/lib/common.py @@ -97,7 +97,7 @@ class BibleCommon(object): The URL of a proxy server used to access the Internet. """ log.debug(u'get_web_text %s %s', proxyurl, urlstring) - if proxyurl is not None: + if proxyurl: proxy_support = urllib2.ProxyHandler({'http': self.proxyurl}) http_support = urllib2.HTTPHandler() opener = urllib2.build_opener(proxy_support, http_support) diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index b18c8b4d8..575f5cb66 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -97,7 +97,7 @@ class BibleManager(object): # look to see if lazy load bible exists and get create getter. meta = self.bible_db_cache[bname].get_meta(u'proxy') proxy = None - if meta is not None: + if meta: proxy = meta.value # tell The Server where to get the verses from. nhttp.set_proxy(proxy) @@ -173,14 +173,14 @@ class BibleManager(object): nbible.save_meta(u'WEB', biblesource) # store the web id of the bible nbible.save_meta(u'bibleid', bibleid) - if proxyurl is not None and proxyurl != u'': + if proxyurl and proxyurl != u'': # store the proxy URL nbible.save_meta(u'proxy', proxyurl) nhttp.set_proxy(proxyurl) - if proxyid is not None and proxyid != u'': + if proxyid and proxyid != u'': # store the proxy userid nbible.save_meta(u'proxyid', proxyid) - if proxypass is not None and proxypass != u'': + if proxypass and proxypass != u'': # store the proxy password nbible.save_meta(u'proxypass', proxypass) return True @@ -247,7 +247,7 @@ class BibleManager(object): log.debug(u'get_bibles') bible_list = [] for bible_name, bible_object in self.bible_db_cache.iteritems(): - if self.bible_http_cache[bible_name] is not None: + if self.bible_http_cache[bible_name]: bible_name = u'%s (%s)' % (bible_name, self.web) bible_list.append(bible_name) return bible_list @@ -338,13 +338,14 @@ class BibleManager(object): # check to see if book/chapter exists fow HTTP bibles and load cache # if necessary web, bible = self.is_bible_web(bible) - if self.bible_http_cache[bible] is not None: + if self.bible_http_cache[bible]: book = self.bible_db_cache[bible].get_bible_book(bookname) if book is None: log.debug(u'get_verse_text : new book') for chapter in range(schapter, echapter + 1): self.media.setQuickMessage( - unicode(self.media.trUtf8(u'Downloading %s: %s')) % (bookname, chapter)) + unicode(self.media.trUtf8(u'Downloading %s: %s')) % + (bookname, chapter)) search_results = \ self.bible_http_cache[bible].get_bible_chapter( bible, bookname, chapter) diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index d44f18a6f..a8106d4f6 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -380,7 +380,7 @@ class BibleMediaItem(MediaManagerItem): bible, text) else: self.searchByReference(bible, text) - if self.search_results is not None: + if self.search_results: self.displayResults(bible) def generateSlideData(self, service_item): @@ -518,9 +518,9 @@ class BibleMediaItem(MediaManagerItem): bible_verse.setData(QtCore.Qt.UserRole, QtCore.QVariant(bible_text)) self.ListView.addItem(bible_verse) - cr = self.ListView.setCurrentRow(count) - if cr is not None: - cr.setSelected(True) + row = self.ListView.setCurrentRow(count) + if row: + row.setSelected(True) def searchByReference(self, bible, search): log.debug(u'searchByReference %s, %s', bible, search) diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index 93f1bfb95..2f64ac0a7 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -90,14 +90,14 @@ class CustomMediaItem(MediaManagerItem): def onRemoteEdit(self, item_id): valid = self.parent.custommanager.get_custom(item_id) - if valid is not None: + if valid: self.fromServiceManager = item_id self.parent.edit_custom_form.loadCustom(item_id) self.parent.edit_custom_form.exec_() def onEditClick(self): item = self.ListView.currentItem() - if item is not None: + if item: item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] self.parent.edit_custom_form.loadCustom(item_id) self.parent.edit_custom_form.exec_() @@ -105,7 +105,7 @@ class CustomMediaItem(MediaManagerItem): def onDeleteClick(self): item = self.ListView.currentItem() - if item is not None: + if item: item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] self.parent.custommanager.delete_custom(item_id) row = self.ListView.row(item) @@ -137,7 +137,7 @@ class CustomMediaItem(MediaManagerItem): for verse in verseList: raw_slides.append(verse[1]) raw_footer.append(title + u' '+ credit) - if theme is not None: + if theme: service_item.title = title for slide in raw_slides: service_item.add_from_text(slide[:30], slide) diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 31e0ba7bd..708307868 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -96,7 +96,7 @@ class MediaMediaItem(MediaManagerItem): def onDeleteClick(self): item = self.ListView.currentItem() - if item is not None: + if item: row = self.ListView.row(item) self.ListView.takeItem(row) self.parent.config.set_list( diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index 0d1daef9c..992b4c1ad 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -225,8 +225,8 @@ class ImpressController(PresentationController): Triggerent by new object being added to SlideController orOpenLP being shut down """ - if self.document is not None: - if self.presentation is not None: + if self.document: + if self.presentation: self.presentation.end() self.presentation = None self.document.dispose() diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index 844e4373a..cb4bfd320 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -121,7 +121,7 @@ class PresentationMediaItem(MediaManagerItem): def onDeleteClick(self): item = self.ListView.currentItem() - if item is not None: + if item: row = self.ListView.row(item) self.ListView.takeItem(row) self.parent.config.set_list( @@ -146,7 +146,7 @@ class PresentationMediaItem(MediaManagerItem): cont.load_presentation(filename) i = 1 img = cont.get_slide_preview_file(i) - while img is not None: + while img: service_item.add_from_command(path, name, img) i = i + 1 img = cont.get_slide_preview_file(i) diff --git a/openlp/plugins/presentations/lib/messagelistener.py b/openlp/plugins/presentations/lib/messagelistener.py index feb3d33a4..5008c1e17 100644 --- a/openlp/plugins/presentations/lib/messagelistener.py +++ b/openlp/plugins/presentations/lib/messagelistener.py @@ -86,7 +86,7 @@ class MessageListener(object): def slide(self, message): self.activate() - if message is not None: + if message: self.controller.goto_slide(message[0]+1) self.controller.poll_slidenumber() diff --git a/openlp/plugins/presentations/lib/pptviewcontroller.py b/openlp/plugins/presentations/lib/pptviewcontroller.py index bbb4d360f..b9f6ce264 100644 --- a/openlp/plugins/presentations/lib/pptviewcontroller.py +++ b/openlp/plugins/presentations/lib/pptviewcontroller.py @@ -78,7 +78,7 @@ class PptviewController(PresentationController): """ Loads the PPTVIEWLIB library """ - if self.process is not None: + if self.process: return log.debug(u'start PPTView') self.process = cdll.LoadLibrary(r'openlp\plugins\presentations\lib\pptviewlib\pptviewlib.dll') diff --git a/openlp/plugins/remotes/remoteclient-cli.py b/openlp/plugins/remotes/remoteclient-cli.py index 2bffa1136..2585b4596 100755 --- a/openlp/plugins/remotes/remoteclient-cli.py +++ b/openlp/plugins/remotes/remoteclient-cli.py @@ -69,7 +69,7 @@ def main(): elif options.address is None: parser.print_help() parser.error("IP address missing") - elif options.slidenext is not None: + elif options.slidenext: options.event = u'next_slide' options.message = u'' text = format_message(options) diff --git a/openlp/plugins/remotes/remoteplugin.py b/openlp/plugins/remotes/remoteplugin.py index 9fa37b46e..3a350cd0c 100644 --- a/openlp/plugins/remotes/remoteplugin.py +++ b/openlp/plugins/remotes/remoteplugin.py @@ -55,7 +55,7 @@ class RemotesPlugin(Plugin): def finalise(self): log.debug(u'finalise') self.remove_toolbox_item() - if self.server is not None: + if self.server: self.server.close() def get_settings_tab(self): diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 7522477b2..b6b54a381 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -183,7 +183,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): # Not Found id = 0 self.SongbookCombo.setCurrentIndex(id) - if self.song.theme_name is not None and len(self.song.theme_name) > 0: + if self.song.theme_name: id = self.ThemeSelectionComboItem.findText( unicode(self.song.theme_name), QtCore.Qt.MatchExactly) if id == -1: @@ -193,20 +193,20 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.ThemeSelectionComboItem.setCurrentIndex(id) if len(title) > 1: self.AlternativeEdit.setText(title[1]) - if self.song.copyright is not None: + if self.song.copyright: self.CopyrightEditItem.setText(self.song.copyright) else: self.CopyrightEditItem.setText(u'') self.VerseListWidget.clear() - if self.song.verse_order is not None: + if self.song.verse_order: self.VerseOrderEdit.setText(self.song.verse_order) else: self.VerseOrderEdit.setText(u'') - if self.song.comments is not None: + if self.song.comments: self.CommentsEdit.setPlainText(self.song.comments) else: self.CommentsEdit.setPlainText(u'') - if self.song.ccli_number is not None: + if self.song.ccli_number: self.CCLNumberEdit.setText(self.song.ccli_number) else: self.CCLNumberEdit.setText(u'') @@ -311,7 +311,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): def onVerseEditButtonClicked(self): item = self.VerseListWidget.currentItem() - if item is not None: + if item: tempText = item.text() self.verse_form.setVerse(tempText) self.verse_form.exec_() diff --git a/openlp/plugins/songs/forms/songmaintenanceform.py b/openlp/plugins/songs/forms/songmaintenanceform.py index 4c83b41e5..703551f9c 100644 --- a/openlp/plugins/songs/forms/songmaintenanceform.py +++ b/openlp/plugins/songs/forms/songmaintenanceform.py @@ -68,7 +68,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): def _getCurrentItemId(self, ListWidget): item = ListWidget.currentItem() - if item is not None: + if item: item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] return item_id else: @@ -79,9 +79,10 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): item_id = self._getCurrentItemId(list_widget) if item_id != -1: item = get_func(item_id) - if item is not None and len(item.songs) == 0: + if item and len(item.songs) == 0: if QtGui.QMessageBox.warning(self, dlg_title, del_text, - QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.No | QtGui.QMessageBox.Yes) + QtGui.QMessageBox.StandardButtons( + QtGui.QMessageBox.No | QtGui.QMessageBox.Yes) ) == QtGui.QMessageBox.Yes: del_func(item.id) reset_func() @@ -96,7 +97,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): self.AuthorsListWidget.clear() authors = self.songmanager.get_authors() for author in authors: - if author.display_name is not None and author.display_name != u'': + if author.display_name: author_name = QtGui.QListWidgetItem(author.display_name) else: author_name = QtGui.QListWidgetItem( diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 08005b326..daeb61a1a 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -53,11 +53,13 @@ class SongMediaItem(MediaManagerItem): self.edit_song_form = EditSongForm(self.parent.songmanager, self) self.song_maintenance_form = SongMaintenanceForm( self.parent.songmanager, self) - #fromPreview holds the id of the item if the song editor needs to trigger a preview - #without closing. It is set to -1 if this function is inactive + # fromPreview holds the id of the item if the song editor needs to + # trigger a preview without closing. It is set to -1 if this + # function is inactive. self.fromPreview = -1 - #fromServiceManager holds the id of the item if the song editor needs to trigger posting - #to the servicemanager without closing. It is set to -1 if this function is inactive + # fromServiceManager holds the id of the item if the song editor needs + # to trigger posting to the servicemanager without closing. It is set + # to -1 if this function is inactive. self.fromServiceManager = -1 def initPluginNameVisible(self): @@ -244,14 +246,14 @@ class SongMediaItem(MediaManagerItem): def onRemoteEdit(self, songid): valid = self.parent.songmanager.get_song(songid) - if valid is not None: + if valid: self.fromServiceManager = songid self.edit_song_form.loadSong(songid, False) self.edit_song_form.exec_() def onEditClick(self, preview=False): item = self.ListView.currentItem() - if item is not None: + if item: item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] self.fromPreview = -1 if preview: @@ -264,7 +266,7 @@ class SongMediaItem(MediaManagerItem): def onDeleteClick(self): item = self.ListView.currentItem() - if item is not None: + if item: item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0] self.parent.songmanager.delete_song(item_id) row = self.ListView.row(item) @@ -295,7 +297,7 @@ class SongMediaItem(MediaManagerItem): songXML=SongXMLParser(song.lyrics) verseList = songXML.get_verses() for verse in verseList: - if verse[1] is not None: + if verse[1]: service_item.add_from_text(verse[1][:30], verse[1]) else: verses = song.lyrics.split(u'\n\n') diff --git a/openlp/plugins/songs/lib/songxml.py b/openlp/plugins/songs/lib/songxml.py index deec2e21e..705a223f6 100644 --- a/openlp/plugins/songs/lib/songxml.py +++ b/openlp/plugins/songs/lib/songxml.py @@ -85,7 +85,7 @@ class _OpenSong(XmlRootClass): def from_buffer(self, xmlContent): """Initialize from buffer(string) with xml content""" self._reset() - if xmlContent is not None: + if xmlContent: self._setFromXml(xmlContent, 'song') def get_author_list(self): @@ -95,7 +95,7 @@ class _OpenSong(XmlRootClass): return as a string """ res = [] - if self.author is not None: + if self.author: lst = self.author.split(u' and ') for l in lst: res.append(l.strip()) @@ -108,9 +108,9 @@ class _OpenSong(XmlRootClass): return as a string """ res = [] - if self.theme is not None: + if self.theme: res.append(self.theme) - if self.alttheme is not None: + if self.alttheme: res.append(self.alttheme) s = u', u'.join(res) return s @@ -264,13 +264,13 @@ class Song(object): """Initialize from buffer(string) of xml lines in opensong format""" self._reset() opensong = _OpenSong(xmlcontent) - if opensong.title is not None: + if opensong.title: self.set_title(opensong.title) - if opensong.copyright is not None: + if opensong.copyright: self.set_copyright(opensong.copyright) - if opensong.presentation is not None: + if opensong.presentation: self.set_verse_order(opensong.presentation) - if opensong.ccli is not None: + if opensong.ccli: self.set_song_cclino(opensong.ccli) self.set_author_list(opensong.get_author_list()) self.set_category_array(opensong.get_category_array()) @@ -402,7 +402,7 @@ class Song(object): def _split_to_list(self, aString): """Split a string into a list - comma separated""" res = [] - if aString is not None: + if aString: lst = aString.split(u',') for l in lst: # remove whitespace