Jon Tibble has proposed merging lp:~meths/openlp/trivialfixes into lp:openlp.
Requested reviews: OpenLP Core (openlp-core) For more details, see: https://code.launchpad.net/~meths/openlp/trivialfixes/+merge/46340 More cleanups Refactor file deleting Fix db committing too early (Bug #703073) -- https://code.launchpad.net/~meths/openlp/trivialfixes/+merge/46340 Your team OpenLP Core is requested to review the proposed merge of lp:~meths/openlp/trivialfixes into lp:openlp.
=== modified file 'documentation/api/source/plugins/songs.rst' --- documentation/api/source/plugins/songs.rst 2010-10-16 19:38:23 +0000 +++ documentation/api/source/plugins/songs.rst 2011-01-14 21:22:47 +0000 @@ -72,9 +72,6 @@ .. automodule:: openlp.plugins.songs.lib.cclifileimport :members: -.. autoclass:: openlp.plugins.songs.lib.cclifileimport.CCLIFileImportError - :members: - .. automodule:: openlp.plugins.songs.lib.ewimport :members: === modified file 'openlp/core/lib/db.py' --- openlp/core/lib/db.py 2010-12-26 11:04:47 +0000 +++ openlp/core/lib/db.py 2011-01-14 21:22:47 +0000 @@ -34,7 +34,7 @@ from sqlalchemy.exceptions import InvalidRequestError from sqlalchemy.orm import scoped_session, sessionmaker -from openlp.core.utils import AppLocation +from openlp.core.utils import AppLocation, delete_file log = logging.getLogger(__name__) @@ -75,11 +75,7 @@ else: db_file_path = os.path.join( AppLocation.get_section_data_path(plugin_name), plugin_name) - try: - os.remove(db_file_path) - return True - except OSError: - return False + return delete_file(db_file_path) class BaseModel(object): """ @@ -295,4 +291,4 @@ if self.is_dirty: engine = create_engine(self.db_url) if self.db_url.startswith(u'sqlite'): - engine.execute("vacuum") \ No newline at end of file + engine.execute("vacuum") === modified file 'openlp/core/ui/maindisplay.py' --- openlp/core/ui/maindisplay.py 2011-01-12 18:52:16 +0000 +++ openlp/core/ui/maindisplay.py 2011-01-14 21:22:47 +0000 @@ -24,6 +24,8 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### """ +The :mod:`maindisplay` module provides the functionality to display screens +and play multimedia within OpenLP. """ import logging import os === modified file 'openlp/core/ui/servicemanager.py' --- openlp/core/ui/servicemanager.py 2011-01-13 01:14:38 +0000 +++ openlp/core/ui/servicemanager.py 2011-01-14 21:22:47 +0000 @@ -37,7 +37,8 @@ Receiver, build_icon, ItemCapabilities, SettingsManager, translate, \ ThemeLevel from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm -from openlp.core.utils import AppLocation, file_is_unicode, split_filename +from openlp.core.utils import AppLocation, delete_file, file_is_unicode, \ + split_filename class ServiceManagerList(QtGui.QTreeWidget): """ @@ -445,11 +446,7 @@ file.close() if zip: zip.close() - try: - os.remove(serviceFileName) - except (IOError, OSError): - # if not present do not worry - pass + delete_file(serviceFileName) self.mainwindow.addRecentFile(fileName) self.setModified(False) return True @@ -515,11 +512,7 @@ if serviceItem.is_capable(ItemCapabilities.OnLoadUpdate): Receiver.send_message(u'%s_service_load' % serviceItem.name.lower(), serviceItem) - try: - if os.path.isfile(p_file): - os.remove(p_file) - except (IOError, OSError): - log.exception(u'Failed to remove osd file') + delete_file(p_file) else: QtGui.QMessageBox.critical( self, translate('OpenLP.ServiceManager', 'Error'), @@ -873,11 +866,7 @@ """ for file in os.listdir(self.servicePath): file_path = os.path.join(self.servicePath, file) - try: - if os.path.isfile(file_path): - os.remove(file_path) - except OSError: - log.exception(u'Failed to clean up servicePath') + delete_file(file_path) def onThemeComboBoxSelected(self, currentIndex): """ === modified file 'openlp/core/ui/thememanager.py' --- openlp/core/ui/thememanager.py 2011-01-13 01:14:38 +0000 +++ openlp/core/ui/thememanager.py 2011-01-14 21:22:47 +0000 @@ -37,7 +37,7 @@ from openlp.core.lib import OpenLPToolbar, ThemeXML, get_text_file_string, \ build_icon, Receiver, SettingsManager, translate, check_item_selected, \ BackgroundType, BackgroundGradientType, check_directory_exists -from openlp.core.utils import AppLocation, file_is_unicode, \ +from openlp.core.utils import AppLocation, delete_file, file_is_unicode, \ get_filesystem_encoding log = logging.getLogger(__name__) @@ -341,9 +341,9 @@ """ self.themelist.remove(theme) thumb = theme + u'.png' + delete_file(os.path.join(self.path, thumb)) + delete_file(os.path.join(self.thumbPath, thumb)) try: - os.remove(os.path.join(self.path, thumb)) - os.remove(os.path.join(self.thumbPath, thumb)) encoding = get_filesystem_encoding() shutil.rmtree(os.path.join(self.path, theme).encode(encoding)) except OSError: @@ -521,11 +521,8 @@ check_directory_exists(theme_dir) if os.path.splitext(ucsfile)[1].lower() in [u'.xml']: xml_data = zip.read(file) - try: - xml_data = xml_data.decode(u'utf-8') - except UnicodeDecodeError: - log.exception(u'Theme XML is not UTF-8 ' - u'encoded.') + xml_data = file_is_unicode(xml_data) + if not xml_data: break filexml = self.checkVersionAndConvert(xml_data) outfile = open(fullpath, u'w') @@ -603,10 +600,7 @@ theme_file = os.path.join(theme_dir, name + u'.xml') if imageTo and self.oldBackgroundImage and \ imageTo != self.oldBackgroundImage: - try: - os.remove(self.oldBackgroundImage) - except OSError: - log.exception(u'Unable to remove old theme background') + delete_file(self.oldBackgroundImage) outfile = None try: outfile = open(theme_file, u'w') === modified file 'openlp/core/utils/__init__.py' --- openlp/core/utils/__init__.py 2011-01-13 17:55:29 +0000 +++ openlp/core/utils/__init__.py 2011-01-14 21:22:47 +0000 @@ -282,6 +282,23 @@ else: return os.path.split(path) +def delete_file(file_path_name): + """ + Deletes a file from the system. + + ``file_path_name`` + The file, including path, to delete. + """ + if not file_path_name: + return False + try: + if os.path.exists(file_path_name): + os.remove(file_path_name) + return True + except (IOError, OSError): + log.exception("Unable to delete file %s" % file_path_name) + return False + def get_web_page(url, header=None, update_openlp=False): """ Attempts to download the webpage at url and returns that page or None. === modified file 'openlp/plugins/images/lib/mediaitem.py' --- openlp/plugins/images/lib/mediaitem.py 2011-01-09 08:17:17 +0000 +++ openlp/plugins/images/lib/mediaitem.py 2011-01-14 21:22:47 +0000 @@ -32,7 +32,7 @@ from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \ ItemCapabilities, SettingsManager, translate, check_item_selected, \ Receiver, check_directory_exists -from openlp.core.utils import AppLocation, get_images_filter +from openlp.core.utils import AppLocation, delete_file, get_images_filter log = logging.getLogger(__name__) @@ -115,12 +115,8 @@ for row in row_list: text = self.listView.item(row) if text: - try: - os.remove(os.path.join(self.servicePath, - unicode(text.text()))) - except OSError: - # if not present do not worry - pass + delete_file(os.path.join(self.servicePath, + unicode(text.text()))) self.listView.takeItem(row) SettingsManager.set_list(self.settingsSection, self.settingsSection, self.getFileList()) @@ -216,4 +212,4 @@ 'the image file "%s" no longer exists.')) % filename}) def onPreviewClick(self): - MediaManagerItem.onPreviewClick(self) \ No newline at end of file + MediaManagerItem.onPreviewClick(self) === modified file 'openlp/plugins/presentations/lib/impresscontroller.py' --- openlp/plugins/presentations/lib/impresscontroller.py 2011-01-11 17:13:17 +0000 +++ openlp/plugins/presentations/lib/impresscontroller.py 2011-01-14 21:22:47 +0000 @@ -51,6 +51,7 @@ from PyQt4 import QtCore +from openlp.core.utils import delete_file from presentationcontroller import PresentationController, PresentationDocument log = logging.getLogger(__name__) @@ -292,8 +293,7 @@ try: doc.storeToURL(urlpath, props) self.convert_thumbnail(path, idx + 1) - if os.path.exists(path): - os.remove(path) + delete_file(path) except: log.exception(u'%s - Unable to store openoffice preview' % path) === modified file 'openlp/plugins/songs/forms/editsongform.py' --- openlp/plugins/songs/forms/editsongform.py 2011-01-09 16:52:31 +0000 +++ openlp/plugins/songs/forms/editsongform.py 2011-01-14 21:22:47 +0000 @@ -331,7 +331,7 @@ else: author = Author.populate(first_name=text.rsplit(u' ', 1)[0], last_name=text.rsplit(u' ', 1)[1], display_name=text) - self.manager.save_object(author) + self.manager.save_object(author, False) author_item = QtGui.QListWidgetItem( unicode(author.display_name)) author_item.setData(QtCore.Qt.UserRole, @@ -386,7 +386,7 @@ QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes) == QtGui.QMessageBox.Yes: topic = Topic.populate(name=text) - self.manager.save_object(topic) + self.manager.save_object(topic, False) topic_item = QtGui.QListWidgetItem(unicode(topic.name)) topic_item.setData(QtCore.Qt.UserRole, QtCore.QVariant(topic.id)) @@ -654,7 +654,7 @@ def accept(self): """ - Exit Dialog and save soong if valid + Exit Dialog and save song if valid """ log.debug(u'accept') self.clearCaches() === modified file 'openlp/plugins/songs/lib/cclifileimport.py' --- openlp/plugins/songs/lib/cclifileimport.py 2011-01-13 17:55:29 +0000 +++ openlp/plugins/songs/lib/cclifileimport.py 2011-01-14 21:22:47 +0000 @@ -34,9 +34,6 @@ log = logging.getLogger(__name__) -class CCLIFileImportError(Exception): - pass - class CCLIFileImport(SongImport): """ The :class:`CCLIFileImport` class provides OpenLP with the ability to @@ -152,7 +149,6 @@ """ log.debug(u'USR file text: %s', textList) - lyrics = [] self.set_defaults() for line in textList: if line.startswith(u'Title='):
_______________________________________________ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp