From 15038a918490f6896140c405210d17b04f15f6a9 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Wed, 26 May 2010 16:52:33 +0100 Subject: [PATCH] More cleanups --- openlp/plugins/bibles/lib/common.py | 4 +- .../presentations/presentationplugin.py | 8 +-- openlp/plugins/remotes/lib/httpserver.py | 13 ++-- openlp/plugins/songs/lib/songimport.py | 4 +- openlp/plugins/songs/lib/songxml.py | 69 +++++++++---------- 5 files changed, 50 insertions(+), 48 deletions(-) diff --git a/openlp/plugins/bibles/lib/common.py b/openlp/plugins/bibles/lib/common.py index 48e55cb7e..94d83ce3d 100644 --- a/openlp/plugins/bibles/lib/common.py +++ b/openlp/plugins/bibles/lib/common.py @@ -257,8 +257,8 @@ def unescape(text): @param text The HTML (or XML) source text. @return The plain text, as a Unicode string, if necessary. """ - def fixup(m): - text = m.group(0) + def fixup(markup): + text = markup.group(0) if text[:2] == u'&#': # character reference try: diff --git a/openlp/plugins/presentations/presentationplugin.py b/openlp/plugins/presentations/presentationplugin.py index dd1a5259b..f57235c9b 100644 --- a/openlp/plugins/presentations/presentationplugin.py +++ b/openlp/plugins/presentations/presentationplugin.py @@ -95,10 +95,9 @@ class PresentationPlugin(Plugin): log.debug(u'Importing controller %s', modulename) try: __import__(modulename, globals(), locals(), []) - except ImportError, e: - log.error( - u'Failed to import %s on path %s for reason %s', - modulename, path, e.args[0]) + except ImportError: + log.exception(u'Failed to import %s on path %s', + modulename, path) controller_classes = PresentationController.__subclasses__() for controller_class in controller_classes: controller = controller_class(self) @@ -114,3 +113,4 @@ class PresentationPlugin(Plugin): 'programs. The choice of available presentation programs is ' 'available to the user in a drop down box.') return about_text + diff --git a/openlp/plugins/remotes/lib/httpserver.py b/openlp/plugins/remotes/lib/httpserver.py index 3c87346cd..0ac21b924 100644 --- a/openlp/plugins/remotes/lib/httpserver.py +++ b/openlp/plugins/remotes/lib/httpserver.py @@ -206,14 +206,17 @@ class HttpConnection(object): mimetype = u'image/png' else: return (None, None) + file_handle = None try: - f = open(path, u'rb') - except: + file_handle = open(path, u'rb') + log.debug(u'Opened %s' % path) + html = file_handle.read() + except IOError: log.exception(u'Failed to open %s' % path) return None - log.debug(u'Opened %s' % path) - html = f.read() - f.close() + finally: + if file_handle: + file_handle.close() return (mimetype, html) def load_params(self, query): diff --git a/openlp/plugins/songs/lib/songimport.py b/openlp/plugins/songs/lib/songimport.py index 58e3a4df7..08f39954e 100644 --- a/openlp/plugins/songs/lib/songimport.py +++ b/openlp/plugins/songs/lib/songimport.py @@ -265,8 +265,8 @@ class SongImport(object): """ Remove punctuation from the string for searchable fields """ - for c in string.punctuation: - text = text.replace(c, u'') + for character in string.punctuation: + text = text.replace(character, u'') return text def finish(self): diff --git a/openlp/plugins/songs/lib/songxml.py b/openlp/plugins/songs/lib/songxml.py index 8789b379d..0979eb2b8 100644 --- a/openlp/plugins/songs/lib/songxml.py +++ b/openlp/plugins/songs/lib/songxml.py @@ -75,7 +75,7 @@ _blankOpenSongXml = \ ''' class _OpenSong(XmlRootClass): - """Class for import of OpenSogn""" + """Class for import of OpenSong""" def __init__(self, xmlContent = None): """Initialize from given xml content""" @@ -113,8 +113,7 @@ class _OpenSong(XmlRootClass): res.append(self.theme) if self.alttheme: res.append(self.alttheme) - s = u', u'.join(res) - return s + return u', u'.join(res) def _reorder_verse(self, tag, tmpVerse): """ @@ -123,28 +122,28 @@ class _OpenSong(XmlRootClass): tmpVerse -- list of strings """ res = [] - for c in '1234567890 ': + for digit in '1234567890 ': tagPending = True - for l in tmpVerse: - if l.startswith(c): + for line in tmpVerse: + if line.startswith(digit): if tagPending: tagPending = False - t = tag.strip(u'[]').lower() - if 'v' == t: + tagChar = tag.strip(u'[]').lower() + if 'v' == tagChar: newtag = "Verse" - elif 'c' == t: + elif 'c' == tagChar: newtag = "Chorus" - elif 'b' == t: + elif 'b' == tagChar: newtag = "Bridge" - elif 'p' == t: + elif 'p' == tagChar: newtag = "Pre-chorus" else: - newtag = t - s = (u'# %s %s' % (newtag, c)).rstrip() - res.append(s) - res.append(l[1:]) - if (len(l) == 0) and (not tagPending): - res.append(l) + newtag = tagChar + tagString = (u'# %s %s' % (newtag, digit)).rstrip() + res.append(tagString) + res.append(line[1:]) + if (len(line) == 0) and (not tagPending): + res.append(line) return res def get_lyrics(self): @@ -165,13 +164,13 @@ class _OpenSong(XmlRootClass): if line.startswith(u'['): tag = line else: - r = self._reorder_verse(tag, tmpVerse) - finalLyrics.extend(r) + reorderedVerse = self._reorder_verse(tag, tmpVerse) + finalLyrics.extend(reorderedVerse) tag = "" tmpVerse = [] # catch up final verse - r = self._reorder_verse(tag, tmpVerse) - finalLyrics.extend(r) + reorderedVerse = self._reorder_verse(tag, tmpVerse) + finalLyrics.extend(reorderedVerse) return finalLyrics @@ -344,36 +343,36 @@ class Song(object): sCopyright = "" sCcli = "" lastpart = 0 - n = 0 + lineCount = 0 metMisc = False lyrics = [] - for l in textList: - n += 1 + for line in textList: + lineCount += 1 if lastpart > 0: lastpart += 1 if lastpart == 2: - sCopyright = l[1:].strip() + sCopyright = line[1:].strip() if lastpart == 3: - sAuthor = l - elif l.startswith(u'CCLI Song'): - sCcli = l[13:].strip() + sAuthor = line + elif line.startswith(u'CCLI Song'): + sCcli = line[13:].strip() lastpart = 1 else: if metMisc: metMisc = False - if l.upper().startswith(u'(BRIDGE)'): + if line.upper().startswith(u'(BRIDGE)'): lyrics.append(u'# Bridge') # otherwise unknown misc keyword - elif l.startswith(u'Misc'): + elif line.startswith(u'Misc'): metMisc = True - elif l.startswith(u'Verse') or l.startswith(u'Chorus'): - lyrics.append(u'# %s'%l) + elif line.startswith(u'Verse') or line.startswith(u'Chorus'): + lyrics.append(u'# %s' % line) else: # should we remove multiple blank lines? - if n == 1: - sName = l + if lineCount == 1: + sName = line else: - lyrics.append(l) + lyrics.append(line) # split on known separators lst = sAuthor.split(u'/') if len(lst) < 2: