openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #00812
[Merge] lp:~meths/openlp/trivialfixes into lp:openlp
Jon Tibble has proposed merging lp:~meths/openlp/trivialfixes into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
Truth handling for != u''
File loading exception handling fixes
--
https://code.launchpad.net/~meths/openlp/trivialfixes/+merge/14571
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp.pyw'
--- openlp.pyw 2009-11-03 19:01:53 +0000
+++ openlp.pyw 2009-11-07 00:10:23 +0000
@@ -74,6 +74,7 @@
#Load and store current Application Version
filepath = os.path.split(os.path.abspath(__file__))[0]
filepath = os.path.abspath(os.path.join(filepath, u'version.txt'))
+ fversion = None
try:
fversion = open(filepath, 'r')
for line in fversion:
@@ -83,6 +84,9 @@
except:
applicationVersion = {u'Full':u'1.9.0-000',
u'version':u'1.9.0', u'build':u'000'}
+ finally:
+ if fversion:
+ fversion.close()
#set the default string encoding
try:
sys.setappdefaultencoding(u'utf-8')
=== modified file 'openlp/core/lib/settingsmanager.py'
--- openlp/core/lib/settingsmanager.py 2009-10-11 06:29:25 +0000
+++ openlp/core/lib/settingsmanager.py 2009-11-07 00:10:23 +0000
@@ -60,7 +60,7 @@
u'user interface', u'display previewpanel', True))
def setUIItemVisibility(self, item=u'', isVisible=True):
- if item != u'':
+ if item:
if item == u'ThemeManagerDock':
ConfigHelper.set_config(u'user interface',
u'display thememanager', isVisible)
=== modified file 'openlp/core/ui/amendthemeform.py'
--- openlp/core/ui/amendthemeform.py 2009-11-06 02:12:56 +0000
+++ openlp/core/ui/amendthemeform.py 2009-11-07 00:10:23 +0000
@@ -194,7 +194,7 @@
def onImageToolButtonClicked(self):
filename = QtGui.QFileDialog.getOpenFileName(
self, self.trUtf8('Open file'))
- if filename != u'':
+ if filename:
self.ImageLineEdit.setText(filename)
self.theme.background_filename = filename
self.previewTheme(self.theme)
=== modified file 'openlp/core/ui/servicemanager.py'
--- openlp/core/ui/servicemanager.py 2009-11-05 17:03:37 +0000
+++ openlp/core/ui/servicemanager.py 2009-11-07 00:10:24 +0000
@@ -35,7 +35,7 @@
class ServiceManagerList(QtGui.QTreeWidget):
- def __init__(self,parent=None,name=None):
+ def __init__(self, parent=None, name=None):
QtGui.QTreeWidget.__init__(self,parent)
self.parent = parent
@@ -418,7 +418,7 @@
u'Save Service', self.config.get_last_dir())
else:
filename = self.config.get_last_dir()
- if filename != u'':
+ if filename:
splittedFile = filename.split(u'.')
if splittedFile[-1] != u'osz':
filename = filename + u'.osz'
@@ -427,21 +427,30 @@
self.config.set_last_dir(filename)
service = []
servicefile = filename + u'.osd'
- zip = zipfile.ZipFile(unicode(filename), 'w')
- for item in self.serviceItems:
- service.append(
- {u'serviceitem':item[u'data'].get_service_repr()})
- if item[u'data'].service_item_type == ServiceItemType.Image or \
- item[u'data'].service_item_type == ServiceItemType.Command:
- for frame in item[u'data'].frames:
- path_from = unicode(os.path.join(
- item[u'data'].service_item_path, frame[u'title']))
- zip.write(path_from)
- file = open(servicefile, u'wb')
- cPickle.dump(service, file)
- file.close()
- zip.write(servicefile)
- zip.close()
+ zip = None
+ file = None
+ try:
+ zip = zipfile.ZipFile(unicode(filename), 'w')
+ for item in self.serviceItems:
+ service.append(
+ {u'serviceitem':item[u'data'].get_service_repr()})
+ if item[u'data'].service_item_type == ServiceItemType.Image or \
+ item[u'data'].service_item_type == ServiceItemType.Command:
+ for frame in item[u'data'].frames:
+ path_from = unicode(os.path.join(
+ item[u'data'].service_item_path, frame[u'title']))
+ zip.write(path_from)
+ file = open(servicefile, u'wb')
+ cPickle.dump(service, file)
+ file.close()
+ zip.write(servicefile)
+ except:
+ log.exception(u'Failed to save service to disk')
+ finally:
+ if file:
+ file.close()
+ if zip:
+ zip.close()
try:
os.remove(servicefile)
except:
@@ -467,8 +476,10 @@
self.config.get_last_dir(), u'Services (*.osz)')
filename = unicode(filename)
name = filename.split(os.path.sep)
- if filename != u'':
+ if filename:
self.config.set_last_dir(filename)
+ zip = None
+ f = None
try:
zip = zipfile.ZipFile(unicode(filename))
for file in zip.namelist():
@@ -501,6 +512,11 @@
log.exception(u'Failed to remove osd file')
except:
log.exception(u'Problem loading a service file')
+ finally:
+ if f:
+ f.close()
+ if zip:
+ zip.close()
self.isNew = False
self.serviceName = name[len(name) - 1]
self.parent.serviceChanged(True, self.serviceName)
=== modified file 'openlp/core/ui/slidecontroller.py'
--- openlp/core/ui/slidecontroller.py 2009-11-05 17:03:37 +0000
+++ openlp/core/ui/slidecontroller.py 2009-11-07 00:10:24 +0000
@@ -426,7 +426,7 @@
self.onSlideSelected()
self.PreviewListWidget.setFocus()
log.info(u'Display Rendering took %4s' % (time.time() - before))
- if self.serviceitem.audit != u'' and self.isLive:
+ if self.serviceitem.audit and self.isLive:
Receiver().send_message(u'songusage_live', self.serviceitem.audit)
log.debug(u'displayServiceManagerItems End')
=== modified file 'openlp/core/ui/thememanager.py'
--- openlp/core/ui/thememanager.py 2009-11-06 18:50:46 +0000
+++ openlp/core/ui/thememanager.py 2009-11-07 00:10:24 +0000
@@ -182,10 +182,6 @@
self.ThemeListWidget.takeItem(row)
try:
os.remove(os.path.join(self.path, th))
- except:
- #if not present do not worry
- pass
- try:
shutil.rmtree(os.path.join(self.path, theme))
except:
#if not present do not worry
@@ -210,16 +206,22 @@
unicode(self.trUtf8(u'Save Theme - (%s)')) % theme,
self.config.get_last_dir(1) )
path = unicode(path)
- if path != u'':
+ if path:
self.config.set_last_dir(path, 1)
themePath = os.path.join(path, theme + u'.theme')
- zip = zipfile.ZipFile(themePath, u'w')
- source = os.path.join(self.path, theme)
- for root, dirs, files in os.walk(source):
- for name in files:
- zip.write(
- os.path.join(source, name), os.path.join(theme, name))
- zip.close()
+ zip = None
+ try:
+ zip = zipfile.ZipFile(themePath, u'w')
+ source = os.path.join(self.path, theme)
+ for root, dirs, files in os.walk(source):
+ for name in files:
+ zip.write(
+ os.path.join(source, name), os.path.join(theme, name))
+ except:
+ log.exception(u'Export Theme Failed')
+ finally:
+ if zip:
+ zip.close()
def onImportTheme(self):
files = QtGui.QFileDialog.getOpenFileNames(
@@ -291,44 +293,49 @@
"""
log.debug(u'Unzipping theme %s', filename)
filename = unicode(filename)
+ zip = None
+ outfile = None
try:
zip = zipfile.ZipFile(filename)
+ filexml = None
+ themename = None
+ for file in zip.namelist():
+ if file.endswith(os.path.sep):
+ theme_dir = os.path.join(dir, file)
+ if not os.path.exists(theme_dir):
+ os.mkdir(os.path.join(dir, file))
+ else:
+ fullpath = os.path.join(dir, file)
+ names = file.split(os.path.sep)
+ if len(names) > 1:
+ # not preview file
+ if themename is None:
+ themename = names[0]
+ xml_data = zip.read(file)
+ if os.path.splitext(file)[1].lower() in [u'.xml']:
+ if self.checkVersion1(xml_data):
+ # upgrade theme xml
+ filexml = self.migrateVersion122(filename,
+ fullpath, xml_data)
+ else:
+ filexml = xml_data
+ outfile = open(fullpath, u'w')
+ outfile.write(filexml)
+ else:
+ outfile = open(fullpath, u'w')
+ outfile.write(zip.read(file))
+ self.generateAndSaveImage(dir, themename, filexml)
except:
QtGui.QMessageBox.critical(
self, self.trUtf8(u'Error'),
self.trUtf8(u'File is not a valid theme!'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
- return
- filexml = None
- themename = None
- for file in zip.namelist():
- if file.endswith(os.path.sep):
- theme_dir = os.path.join(dir, file)
- if not os.path.exists(theme_dir):
- os.mkdir(os.path.join(dir, file))
- else:
- fullpath = os.path.join(dir, file)
- names = file.split(os.path.sep)
- if len(names) > 1:
- # not preview file
- if themename is None:
- themename = names[0]
- xml_data = zip.read(file)
- if os.path.splitext(file)[1].lower() in [u'.xml']:
- if self.checkVersion1(xml_data):
- # upgrade theme xml
- filexml = self.migrateVersion122(filename,
- fullpath, xml_data)
- else:
- filexml = xml_data
- outfile = open(fullpath, u'w')
- outfile.write(filexml)
- outfile.close()
- else:
- outfile = open(fullpath, u'w')
- outfile.write(zip.read(file))
- outfile.close()
- self.generateAndSaveImage(dir, themename, filexml)
+ log.exception(u'Importing theme from zip file failed')
+ finally:
+ if zip:
+ zip.close()
+ if outfile:
+ outfile.close()
def checkVersion1(self, xmlfile):
"""
@@ -408,13 +415,22 @@
result == QtGui.QMessageBox.Yes
if result == QtGui.QMessageBox.Yes:
# Save the theme, overwriting the existing theme if necessary.
- outfile = open(theme_file, u'w')
- outfile.write(theme_pretty_xml)
- outfile.close()
+ outfile = None
+ try:
+ outfile = open(theme_file, u'w')
+ outfile.write(theme_pretty_xml)
+ except:
+ log.exception(u'Saving theme to file failed')
+ finally:
+ if outfile:
+ outfile.close()
if image_from and image_from != image_to:
print "if", image_from
print "it", image_to
- shutil.copyfile(image_from, image_to)
+ try:
+ shutil.copyfile(image_from, image_to)
+ except:
+ log.exception(u'Failed to save theme image')
self.generateAndSaveImage(self.path, name, theme_xml)
self.loadThemes()
else:
=== modified file 'openlp/core/utils/registry.py'
--- openlp/core/utils/registry.py 2009-09-25 00:43:42 +0000
+++ openlp/core/utils/registry.py 2009-11-07 00:10:24 +0000
@@ -101,23 +101,29 @@
return False
def _load(self):
+ file_handle = None
try:
if not os.path.isfile(self.file_name):
return False
file_handle = open(self.file_name, u'r')
self.config.readfp(file_handle)
- file_handle.close()
return True
except:
return False
+ finally:
+ if file_handle:
+ file_handle.close()
def _save(self):
+ file_handle = None
try:
if not os.path.exists(os.path.dirname(self.file_name)):
os.makedirs(os.path.dirname(self.file_name))
file_handle = open(self.file_name, u'w')
self.config.write(file_handle)
- file_handle.close()
return self._load()
except:
return False
+ finally:
+ if file_handle:
+ file_handle.close()
=== modified file 'openlp/plugins/bibles/forms/bibleimportform.py'
--- openlp/plugins/bibles/forms/bibleimportform.py 2009-11-03 19:01:53 +0000
+++ openlp/plugins/bibles/forms/bibleimportform.py 2009-11-07 00:10:24 +0000
@@ -59,6 +59,7 @@
filepath = os.path.split(os.path.abspath(__file__))[0]
filepath = os.path.abspath(os.path.join(filepath, u'..',
u'resources', u'crosswalkbooks.csv'))
+ fbibles = None
try:
fbibles = open(filepath, 'r')
for line in fbibles:
@@ -66,6 +67,9 @@
self.cwBibleVersions[p[0]] = p[1].replace(u'\n', u'')
except:
log.exception(u'Crosswalk resources missing')
+ finally:
+ if fbibles:
+ fbibles.close()
#Load and store BibleGateway Bibles
filepath = os.path.split(os.path.abspath(__file__))[0]
filepath = os.path.abspath(os.path.join(filepath, u'..',
@@ -77,6 +81,9 @@
self.bgBibleVersions[p[0]] = p[1].replace(u'\n', u'')
except:
log.exception(u'Biblegateway resources missing')
+ finally:
+ if fbibles:
+ fbibles.close()
self.loadBibleCombo(self.cwBibleVersions)
self.cwActive = True
@@ -125,7 +132,7 @@
filename = QtGui.QFileDialog.getOpenFileName(
self, self.trUtf8(u'Open Bible Verses file'),
self.config.get_last_dir(1))
- if filename != u'':
+ if filename:
self.VerseLocationEdit.setText(filename)
self.config.set_last_dir(filename, 1)
self.setCsv()
@@ -134,7 +141,7 @@
filename = QtGui.QFileDialog.getOpenFileName(
self, self.trUtf8(u'Open Bible Books file'),
self.config.get_last_dir(2))
- if filename != u'':
+ if filename:
self.BooksLocationEdit.setText(filename)
self.config.set_last_dir(filename, 2)
self.setCsv()
@@ -143,7 +150,7 @@
filename = QtGui.QFileDialog.getOpenFileName(
self, self.trUtf8(u'Open OSIS import file'),
self.config.get_last_dir(3))
- if filename != u'':
+ if filename:
self.OSISLocationEdit.setText(filename)
self.config.set_last_dir(filename, 3)
self.setOsis()
=== modified file 'openlp/plugins/bibles/lib/bibleCSVimpl.py'
--- openlp/plugins/bibles/lib/bibleCSVimpl.py 2009-11-03 15:13:52 +0000
+++ openlp/plugins/bibles/lib/bibleCSVimpl.py 2009-11-07 00:10:24 +0000
@@ -48,46 +48,59 @@
def load_data(self, booksfile, versesfile, dialogobject):
#Populate the Tables
- fbooks = open(booksfile, 'r')
- fverse = open(versesfile, 'r')
-
- count = 0
- for line in fbooks:
- # cancel pressed
- if not self.loadbible:
- break
- details = chardet.detect(line)
- line = unicode(line, details['encoding'])
- p = line.split(u',')
- p1 = p[1].replace(u'"', u'')
- p2 = p[2].replace(u'"', u'')
- p3 = p[3].replace(u'"', u'')
- self.bibledb.create_book(p2, p3, int(p1))
- count += 1
- #Flush the screen events
- if count % 3 == 0:
- Receiver().send_message(u'process_events')
- count = 0
-
- count = 0
- book_ptr = None
- for line in fverse:
- if not self.loadbible: # cancel pressed
- break
- details = chardet.detect(line)
- line = unicode(line, details['encoding'])
- # split into 3 units and leave the rest as a single field
- p = line.split(u',', 3)
- p0 = p[0].replace(u'"', u'')
- p3 = p[3].replace(u'"',u'')
- if book_ptr is not p0:
- book = self.bibledb.get_bible_book(p0)
- book_ptr = book.name
- # increament the progress bar
- dialogobject.incrementProgressBar(book.name)
- self.bibledb.add_verse(book.id, p[1], p[2], p3)
- count += 1
- #Every x verses repaint the screen
- if count % 3 == 0:
- Receiver().send_message(u'process_events')
- count = 0
+ fbooks = None
+ try:
+ fbooks = open(booksfile, 'r')
+ count = 0
+ for line in fbooks:
+ # cancel pressed
+ if not self.loadbible:
+ break
+ details = chardet.detect(line)
+ line = unicode(line, details['encoding'])
+ p = line.split(u',')
+ p1 = p[1].replace(u'"', u'')
+ p2 = p[2].replace(u'"', u'')
+ p3 = p[3].replace(u'"', u'')
+ self.bibledb.create_book(p2, p3, int(p1))
+ count += 1
+ #Flush the screen events
+ if count % 3 == 0:
+ Receiver().send_message(u'process_events')
+ count = 0
+ except:
+ log.exception(u'Loading books from file failed')
+ finally:
+ if fbooks:
+ fbooks.close()
+
+ fverse = None
+ try:
+ fverse = open(versesfile, 'r')
+ count = 0
+ book_ptr = None
+ for line in fverse:
+ if not self.loadbible: # cancel pressed
+ break
+ details = chardet.detect(line)
+ line = unicode(line, details['encoding'])
+ # split into 3 units and leave the rest as a single field
+ p = line.split(u',', 3)
+ p0 = p[0].replace(u'"', u'')
+ p3 = p[3].replace(u'"',u'')
+ if book_ptr is not p0:
+ book = self.bibledb.get_bible_book(p0)
+ book_ptr = book.name
+ # increament the progress bar
+ dialogobject.incrementProgressBar(book.name)
+ self.bibledb.add_verse(book.id, p[1], p[2], p3)
+ count += 1
+ #Every x verses repaint the screen
+ if count % 3 == 0:
+ Receiver().send_message(u'process_events')
+ count = 0
+ except:
+ log.exception(u'Loading verses from file failed')
+ finally:
+ if fverse:
+ fverse.close()
=== modified file 'openlp/plugins/bibles/lib/bibleOSISimpl.py'
--- openlp/plugins/bibles/lib/bibleOSISimpl.py 2009-11-03 15:13:52 +0000
+++ openlp/plugins/bibles/lib/bibleOSISimpl.py 2009-11-07 00:10:24 +0000
@@ -60,12 +60,20 @@
filepath = os.path.split(os.path.abspath(__file__))[0]
filepath = os.path.abspath(os.path.join(
filepath, u'..', u'resources',u'osisbooks.csv'))
- fbibles = open(filepath, u'r')
- for line in fbibles:
- p = line.split(u',')
- self.booksOfBible[p[0]] = p[1].replace(u'\n', u'')
- self.abbrevOfBible[p[0]] = p[2].replace(u'\n', u'')
- self.loadbible = True
+ fbibles = None
+ try:
+ fbibles = open(filepath, u'r')
+ for line in fbibles:
+ p = line.split(u',')
+ self.booksOfBible[p[0]] = p[1].replace(u'\n', u'')
+ self.abbrevOfBible[p[0]] = p[2].replace(u'\n', u'')
+ self.loadbible = True
+ except:
+ log.exception(u'OSIS bible import failed')
+ finally:
+ self.loadbible = False
+ if fbibles:
+ fbibles.close()
QtCore.QObject.connect(Receiver().get_receiver(),
QtCore.SIGNAL(u'openlpstopimport'), self.stop_import)
@@ -86,82 +94,98 @@
The Import dialog, so that we can increase the counter on
the progress bar.
"""
- detect_file = open(osisfile_record, u'r')
- details = chardet.detect(detect_file.read(2048))
- detect_file.close()
- osis = codecs.open(osisfile_record, u'r', details['encoding'])
- book_ptr = None
- count = 0
- verseText = u'<verse osisID='
- testament = 1
- for file_record in osis.readlines():
- # cancel pressed on UI
- if not self.loadbible:
- break
- pos = file_record.find(verseText)
- # we have a verse
- if pos > -1:
- epos = file_record.find(u'>', pos)
- # Book Reference
- ref = file_record[pos+15:epos-1]
- #lets find the bible text only
- # find start of text
- pos = epos + 1
- # end of text
- epos = file_record.find(u'</verse>', pos)
- text = file_record[pos : epos]
- #remove tags of extra information
- text = self.remove_block(u'<title', u'</title>', text)
- text = self.remove_block(u'<note', u'</note>', text)
- text = self.remove_block(u'<divineName', u'</divineName>', text)
- text = self.remove_tag(u'<lb', text)
- text = self.remove_tag(u'<q', text)
- text = self.remove_tag(u'<l', text)
- text = self.remove_tag(u'<lg', text)
- # Strange tags where the end is not the same as the start
- # The must be in this order as at least one bible has them
- # crossing and the removal does not work.
- pos = text.find(u'<FI>')
- while pos > -1:
- epos = text.find(u'<Fi>', pos)
- if epos == -1: # TODO
- pos = -1
- else:
+ detect_file = None
+ try:
+ detect_file = open(osisfile_record, u'r')
+ details = chardet.detect(detect_file.read(2048))
+ except:
+ log.exception(u'Failed to detect OSIS file encoding')
+ return
+ finally:
+ if detect_file:
+ detect_file.close()
+ osis = None
+ try:
+ osis = codecs.open(osisfile_record, u'r', details['encoding'])
+ book_ptr = None
+ count = 0
+ verseText = u'<verse osisID='
+ testament = 1
+ for file_record in osis.readlines():
+ # cancel pressed on UI
+ if not self.loadbible:
+ break
+ pos = file_record.find(verseText)
+ # we have a verse
+ if pos > -1:
+ epos = file_record.find(u'>', pos)
+ # Book Reference
+ ref = file_record[pos+15:epos-1]
+ #lets find the bible text only
+ # find start of text
+ pos = epos + 1
+ # end of text
+ epos = file_record.find(u'</verse>', pos)
+ text = file_record[pos : epos]
+ #remove tags of extra information
+ text = self.remove_block(u'<title', u'</title>', text)
+ text = self.remove_block(u'<note', u'</note>', text)
+ text = self.remove_block(
+ u'<divineName', u'</divineName>', text)
+ text = self.remove_tag(u'<lb', text)
+ text = self.remove_tag(u'<q', text)
+ text = self.remove_tag(u'<l', text)
+ text = self.remove_tag(u'<lg', text)
+ # Strange tags where the end is not the same as the start
+ # The must be in this order as at least one bible has them
+ # crossing and the removal does not work.
+ pos = text.find(u'<FI>')
+ while pos > -1:
+ epos = text.find(u'<Fi>', pos)
+ if epos == -1: # TODO
+ pos = -1
+ else:
+ text = text[:pos] + text[epos + 4: ]
+ pos = text.find(u'<FI>')
+ pos = text.find(u'<RF>')
+ while pos > -1:
+ epos = text.find(u'<Rf>', pos)
text = text[:pos] + text[epos + 4: ]
- pos = text.find(u'<FI>')
- pos = text.find(u'<RF>')
- while pos > -1:
- epos = text.find(u'<Rf>', pos)
- text = text[:pos] + text[epos + 4: ]
- pos = text.find(u'<RF>')
- # split up the reference
- p = ref.split(u'.', 3)
- if book_ptr != p[0]:
- # first time through
- if book_ptr is None:
- # set the max book size depending on the first book read
- if p[0] == u'Gen':
- dialogobject.setMax(65)
- else:
- dialogobject.setMax(27)
- # First book of NT
- if p[0] == u'Matt':
- testament += 1
- book_ptr = p[0]
- book = self.bibledb.create_book(
- unicode(self.booksOfBible[p[0]]),
- unicode(self.abbrevOfBible[p[0]]),
- testament)
- dialogobject.incrementProgressBar(
- self.booksOfBible[p[0]])
- Receiver().send_message(u'process_events')
- count = 0
- self.bibledb.add_verse(book.id, p[1], p[2], text)
- count += 1
- #Every 3 verses repaint the screen
- if count % 3 == 0:
- Receiver().send_message(u'process_events')
- count = 0
+ pos = text.find(u'<RF>')
+ # split up the reference
+ p = ref.split(u'.', 3)
+ if book_ptr != p[0]:
+ # first time through
+ if book_ptr is None:
+ # set the max book size depending
+ # on the first book read
+ if p[0] == u'Gen':
+ dialogobject.setMax(65)
+ else:
+ dialogobject.setMax(27)
+ # First book of NT
+ if p[0] == u'Matt':
+ testament += 1
+ book_ptr = p[0]
+ book = self.bibledb.create_book(
+ unicode(self.booksOfBible[p[0]]),
+ unicode(self.abbrevOfBible[p[0]]),
+ testament)
+ dialogobject.incrementProgressBar(
+ self.booksOfBible[p[0]])
+ Receiver().send_message(u'process_events')
+ count = 0
+ self.bibledb.add_verse(book.id, p[1], p[2], text)
+ count += 1
+ #Every 3 verses repaint the screen
+ if count % 3 == 0:
+ Receiver().send_message(u'process_events')
+ count = 0
+ except:
+ log.exception(u'Loading bible from OSIS file failed')
+ finally:
+ if osis:
+ osis.close()
def remove_block(self, start_tag, end_tag, text):
"""
=== modified file 'openlp/plugins/bibles/lib/common.py'
--- openlp/plugins/bibles/lib/common.py 2009-11-03 19:01:53 +0000
+++ openlp/plugins/bibles/lib/common.py 2009-11-07 00:10:24 +0000
@@ -105,7 +105,8 @@
xml_string = u''
req = urllib2.Request(urlstring)
#Make us look like an IE Browser on XP to stop blocking by web site
- req.add_header(u'User-Agent', u'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)')
+ req.add_header(u'User-Agent',
+ u'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)')
try:
handle = urllib2.urlopen(req)
html = handle.read()
@@ -164,4 +165,3 @@
start_tag = text.find(u'<')
text = text.replace(u'>', u'')
return text.rstrip().lstrip()
-
=== modified file 'openlp/plugins/bibles/lib/manager.py'
--- openlp/plugins/bibles/lib/manager.py 2009-11-05 00:28:05 +0000
+++ openlp/plugins/bibles/lib/manager.py 2009-11-07 00:10:24 +0000
@@ -71,7 +71,7 @@
def reload_bibles(self):
log.debug(u'Reload bibles')
files = self.config.get_files(self.bibleSuffix)
- log.debug(u'Bible Files %s', files )
+ log.debug(u'Bible Files %s', files)
self.bible_db_cache = {}
self.bible_http_cache = {}
# books of the bible with testaments
@@ -116,12 +116,19 @@
filepath = os.path.split(os.path.abspath(__file__))[0]
filepath = os.path.abspath(os.path.join(
filepath, u'..', u'resources',u'httpbooks.csv'))
- fbibles = open(filepath, u'r')
- for line in fbibles:
- p = line.split(u',')
- self.book_abbreviations[p[0]] = p[1].replace(u'\n', '')
- self.book_testaments[p[0]] = p[2].replace(u'\n', '')
- self.book_chapters.append({u'book':p[0], u'total':p[3].replace(u'\n', '')})
+ fbibles = None
+ try:
+ fbibles = open(filepath, u'r')
+ for line in fbibles:
+ p = line.split(u',')
+ self.book_abbreviations[p[0]] = p[1].replace(u'\n', '')
+ self.book_testaments[p[0]] = p[2].replace(u'\n', '')
+ self.book_chapters.append({u'book':p[0], u'total':p[3].replace(u'\n', '')})
+ except:
+ log.exception(u'Failed to load bible')
+ finally:
+ if fbibles:
+ fbibles.close()
log.debug(u'Bible Initialised')
def process_dialog(self, dialogobject):
=== modified file 'openlp/plugins/songs/lib/songxml.py'
--- openlp/plugins/songs/lib/songxml.py 2009-11-03 19:01:53 +0000
+++ openlp/plugins/songs/lib/songxml.py 2009-11-07 00:10:24 +0000
@@ -94,13 +94,10 @@
in OpenSong an author list may be separated by '/'
return as a string
"""
- res = []
if self.author:
- lst = self.author.split(u' and ')
- for l in lst:
- res.append(l.strip())
- s = u', '.join(res)
- return s
+ list = self.author.split(u' and ')
+ res = [item.strip() for item in list]
+ return u', '.join(res)
def get_category_array(self):
"""Convert theme and alttheme into category_array
@@ -116,8 +113,8 @@
return s
def _reorder_verse(self, tag, tmpVerse):
- """Reorder the verse in case of first char is a number
-
+ """
+ Reorder the verse in case of first char is a number
tag -- the tag of this verse / verse group
tmpVerse -- list of strings
"""
@@ -147,8 +144,8 @@
return res
def get_lyrics(self):
- """Convert the lyrics to openlp lyrics format
-
+ """
+ Convert the lyrics to openlp lyrics format
return as list of strings
"""
lyrics = self.lyrics.split(u'\n')
@@ -277,17 +274,22 @@
self.set_lyrics(opensong.get_lyrics())
def from_opensong_file(self, xmlfilename):
- """Initialize from file containing xml
-
+ """
+ Initialize from file containing xml
xmlfilename -- path to xml file
"""
- lst = []
- f = open(xmlfilename, 'r')
- for line in f:
- lst.append(line)
- f.close()
- xml = "".join(lst)
- self.from_opensong_buffer(xml)
+ osfile = None
+ try:
+ osfile = open(xmlfilename, 'r')
+ list = [line for line in osfile]
+ osfile.close()
+ xml = "".join(list)
+ self.from_opensong_buffer(xml)
+ except:
+ log.exception(u'Failed to load opensong xml file')
+ finally:
+ if osfile:
+ osfile.close()
def _remove_punctuation(self, title):
"""Remove the puntuation chars from title
@@ -380,16 +382,20 @@
self.set_lyrics(lyrics)
def from_ccli_text_file(self, textFileName):
- """Create song from a list of texts read from given file
-
+ """
+ Create song from a list of texts read from given file
textFileName -- path to text file
"""
- lines = []
- f = open(textFileName, 'r')
- for orgline in f:
- lines.append(orgline.rstrip())
- f.close()
- self.from_ccli_text_buffer(lines)
+ ccli_file = None
+ try:
+ ccli_file = open(textFileName, 'r')
+ lines = [orgline.rstrip() for orgline in ccli_file]
+ self.from_ccli_text_buffer(lines)
+ except:
+ log.exception(u'Failed to load CCLI text file')
+ finally:
+ if ccli_file:
+ ccli_file.close()
def _assure_string(self, string_in):
"""Force a string is returned"""
@@ -401,13 +407,10 @@
def _split_to_list(self, aString):
"""Split a string into a list - comma separated"""
- res = []
if aString:
- lst = aString.split(u',')
- for l in lst:
- # remove whitespace
- res.append(l.strip())
- return res
+ list = aString.split(u',')
+ res = [item.strip() for item in list]
+ return res
def _list_to_string(self, strOrList):
"""Force a possibly list into a string"""
@@ -419,8 +422,8 @@
lst = []
else:
raise SongTypeError(u'Variable not String or List')
- s = u', '.join(lst)
- return s
+ string = u', '.join(lst)
+ return string
def get_copyright(self):
"""Return copyright info string"""
=== modified file 'openlp/plugins/songusage/forms/songusagedetailform.py'
--- openlp/plugins/songusage/forms/songusagedetailform.py 2009-10-27 08:38:02 +0000
+++ openlp/plugins/songusage/forms/songusagedetailform.py 2009-11-07 00:10:24 +0000
@@ -111,13 +111,19 @@
self.ToDateEdit.date().toString(u'ddMMyyyy'))
audits = self.parent.auditmanager.get_all_audits()
outname = os.path.join(unicode(self.FileLineEdit.text()), filename)
- file = open(outname, u'w')
- for audit in audits:
- record = u'\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n' % \
- (audit.auditdate,audit.audittime, audit.title,
- audit.copyright, audit.ccl_number , audit.authors)
- file.write(record)
- file.close()
+ file = None
+ try:
+ file = open(outname, u'w')
+ for audit in audits:
+ record = u'\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n' % \
+ (audit.auditdate,audit.audittime, audit.title,
+ audit.copyright, audit.ccl_number , audit.authors)
+ file.write(record)
+ except:
+ log.exception(u'Failed to write out audit records')
+ finally:
+ if file:
+ file.close()
def summaryReport(self):
print "summary"
Follow ups