More cleanups

This commit is contained in:
Jon Tibble 2010-05-26 16:52:33 +01:00
parent a8726e650c
commit 15038a9184
5 changed files with 50 additions and 48 deletions

View File

@ -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:

View File

@ -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

View File

@ -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):

View File

@ -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):

View File

@ -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: