forked from openlp/openlp
Refactor file deleting, cleanups
This commit is contained in:
parent
6beac0d027
commit
ecb97881a1
@ -72,9 +72,6 @@ Song Importers
|
|||||||
.. automodule:: openlp.plugins.songs.lib.cclifileimport
|
.. automodule:: openlp.plugins.songs.lib.cclifileimport
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
.. autoclass:: openlp.plugins.songs.lib.cclifileimport.CCLIFileImportError
|
|
||||||
:members:
|
|
||||||
|
|
||||||
.. automodule:: openlp.plugins.songs.lib.ewimport
|
.. automodule:: openlp.plugins.songs.lib.ewimport
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ from sqlalchemy import create_engine, MetaData
|
|||||||
from sqlalchemy.exceptions import InvalidRequestError
|
from sqlalchemy.exceptions import InvalidRequestError
|
||||||
from sqlalchemy.orm import scoped_session, sessionmaker
|
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__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -75,11 +75,7 @@ def delete_database(plugin_name, db_file_name=None):
|
|||||||
else:
|
else:
|
||||||
db_file_path = os.path.join(
|
db_file_path = os.path.join(
|
||||||
AppLocation.get_section_data_path(plugin_name), plugin_name)
|
AppLocation.get_section_data_path(plugin_name), plugin_name)
|
||||||
try:
|
return delete_file(db_file_path)
|
||||||
os.remove(db_file_path)
|
|
||||||
return True
|
|
||||||
except OSError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
class BaseModel(object):
|
class BaseModel(object):
|
||||||
"""
|
"""
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
# 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 logging
|
||||||
import os
|
import os
|
||||||
|
@ -37,7 +37,8 @@ from openlp.core.lib import OpenLPToolbar, ServiceItem, context_menu_action, \
|
|||||||
Receiver, build_icon, ItemCapabilities, SettingsManager, translate, \
|
Receiver, build_icon, ItemCapabilities, SettingsManager, translate, \
|
||||||
ThemeLevel
|
ThemeLevel
|
||||||
from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm
|
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):
|
class ServiceManagerList(QtGui.QTreeWidget):
|
||||||
"""
|
"""
|
||||||
@ -445,11 +446,7 @@ class ServiceManager(QtGui.QWidget):
|
|||||||
file.close()
|
file.close()
|
||||||
if zip:
|
if zip:
|
||||||
zip.close()
|
zip.close()
|
||||||
try:
|
delete_file(serviceFileName)
|
||||||
os.remove(serviceFileName)
|
|
||||||
except (IOError, OSError):
|
|
||||||
# if not present do not worry
|
|
||||||
pass
|
|
||||||
self.mainwindow.addRecentFile(fileName)
|
self.mainwindow.addRecentFile(fileName)
|
||||||
self.setModified(False)
|
self.setModified(False)
|
||||||
return True
|
return True
|
||||||
@ -515,11 +512,7 @@ class ServiceManager(QtGui.QWidget):
|
|||||||
if serviceItem.is_capable(ItemCapabilities.OnLoadUpdate):
|
if serviceItem.is_capable(ItemCapabilities.OnLoadUpdate):
|
||||||
Receiver.send_message(u'%s_service_load' %
|
Receiver.send_message(u'%s_service_load' %
|
||||||
serviceItem.name.lower(), serviceItem)
|
serviceItem.name.lower(), serviceItem)
|
||||||
try:
|
delete_file(p_file)
|
||||||
if os.path.isfile(p_file):
|
|
||||||
os.remove(p_file)
|
|
||||||
except (IOError, OSError):
|
|
||||||
log.exception(u'Failed to remove osd file')
|
|
||||||
else:
|
else:
|
||||||
QtGui.QMessageBox.critical(
|
QtGui.QMessageBox.critical(
|
||||||
self, translate('OpenLP.ServiceManager', 'Error'),
|
self, translate('OpenLP.ServiceManager', 'Error'),
|
||||||
@ -873,11 +866,7 @@ class ServiceManager(QtGui.QWidget):
|
|||||||
"""
|
"""
|
||||||
for file in os.listdir(self.servicePath):
|
for file in os.listdir(self.servicePath):
|
||||||
file_path = os.path.join(self.servicePath, file)
|
file_path = os.path.join(self.servicePath, file)
|
||||||
try:
|
delete_file(file_path)
|
||||||
if os.path.isfile(file_path):
|
|
||||||
os.remove(file_path)
|
|
||||||
except OSError:
|
|
||||||
log.exception(u'Failed to clean up servicePath')
|
|
||||||
|
|
||||||
def onThemeComboBoxSelected(self, currentIndex):
|
def onThemeComboBoxSelected(self, currentIndex):
|
||||||
"""
|
"""
|
||||||
|
@ -37,7 +37,7 @@ from openlp.core.theme import Theme
|
|||||||
from openlp.core.lib import OpenLPToolbar, ThemeXML, get_text_file_string, \
|
from openlp.core.lib import OpenLPToolbar, ThemeXML, get_text_file_string, \
|
||||||
build_icon, Receiver, SettingsManager, translate, check_item_selected, \
|
build_icon, Receiver, SettingsManager, translate, check_item_selected, \
|
||||||
BackgroundType, BackgroundGradientType, check_directory_exists
|
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
|
get_filesystem_encoding
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -341,9 +341,9 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
"""
|
"""
|
||||||
self.themelist.remove(theme)
|
self.themelist.remove(theme)
|
||||||
thumb = theme + u'.png'
|
thumb = theme + u'.png'
|
||||||
|
delete_file(os.path.join(self.path, thumb))
|
||||||
|
delete_file(os.path.join(self.thumbPath, thumb))
|
||||||
try:
|
try:
|
||||||
os.remove(os.path.join(self.path, thumb))
|
|
||||||
os.remove(os.path.join(self.thumbPath, thumb))
|
|
||||||
encoding = get_filesystem_encoding()
|
encoding = get_filesystem_encoding()
|
||||||
shutil.rmtree(os.path.join(self.path, theme).encode(encoding))
|
shutil.rmtree(os.path.join(self.path, theme).encode(encoding))
|
||||||
except OSError:
|
except OSError:
|
||||||
@ -521,11 +521,8 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
check_directory_exists(theme_dir)
|
check_directory_exists(theme_dir)
|
||||||
if os.path.splitext(ucsfile)[1].lower() in [u'.xml']:
|
if os.path.splitext(ucsfile)[1].lower() in [u'.xml']:
|
||||||
xml_data = zip.read(file)
|
xml_data = zip.read(file)
|
||||||
try:
|
xml_data = file_is_unicode(xml_data)
|
||||||
xml_data = xml_data.decode(u'utf-8')
|
if not xml_data:
|
||||||
except UnicodeDecodeError:
|
|
||||||
log.exception(u'Theme XML is not UTF-8 '
|
|
||||||
u'encoded.')
|
|
||||||
break
|
break
|
||||||
filexml = self.checkVersionAndConvert(xml_data)
|
filexml = self.checkVersionAndConvert(xml_data)
|
||||||
outfile = open(fullpath, u'w')
|
outfile = open(fullpath, u'w')
|
||||||
@ -603,10 +600,7 @@ class ThemeManager(QtGui.QWidget):
|
|||||||
theme_file = os.path.join(theme_dir, name + u'.xml')
|
theme_file = os.path.join(theme_dir, name + u'.xml')
|
||||||
if imageTo and self.oldBackgroundImage and \
|
if imageTo and self.oldBackgroundImage and \
|
||||||
imageTo != self.oldBackgroundImage:
|
imageTo != self.oldBackgroundImage:
|
||||||
try:
|
delete_file(self.oldBackgroundImage)
|
||||||
os.remove(self.oldBackgroundImage)
|
|
||||||
except OSError:
|
|
||||||
log.exception(u'Unable to remove old theme background')
|
|
||||||
outfile = None
|
outfile = None
|
||||||
try:
|
try:
|
||||||
outfile = open(theme_file, u'w')
|
outfile = open(theme_file, u'w')
|
||||||
|
@ -282,6 +282,23 @@ def split_filename(path):
|
|||||||
else:
|
else:
|
||||||
return os.path.split(path)
|
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):
|
def get_web_page(url, header=None, update_openlp=False):
|
||||||
"""
|
"""
|
||||||
Attempts to download the webpage at url and returns that page or None.
|
Attempts to download the webpage at url and returns that page or None.
|
||||||
|
@ -32,7 +32,7 @@ from PyQt4 import QtCore, QtGui
|
|||||||
from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \
|
from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \
|
||||||
ItemCapabilities, SettingsManager, translate, check_item_selected, \
|
ItemCapabilities, SettingsManager, translate, check_item_selected, \
|
||||||
Receiver, check_directory_exists
|
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__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -115,12 +115,8 @@ class ImageMediaItem(MediaManagerItem):
|
|||||||
for row in row_list:
|
for row in row_list:
|
||||||
text = self.listView.item(row)
|
text = self.listView.item(row)
|
||||||
if text:
|
if text:
|
||||||
try:
|
delete_file(os.path.join(self.servicePath,
|
||||||
os.remove(os.path.join(self.servicePath,
|
|
||||||
unicode(text.text())))
|
unicode(text.text())))
|
||||||
except OSError:
|
|
||||||
# if not present do not worry
|
|
||||||
pass
|
|
||||||
self.listView.takeItem(row)
|
self.listView.takeItem(row)
|
||||||
SettingsManager.set_list(self.settingsSection,
|
SettingsManager.set_list(self.settingsSection,
|
||||||
self.settingsSection, self.getFileList())
|
self.settingsSection, self.getFileList())
|
||||||
|
@ -51,6 +51,7 @@ else:
|
|||||||
|
|
||||||
from PyQt4 import QtCore
|
from PyQt4 import QtCore
|
||||||
|
|
||||||
|
from openlp.core.utils import delete_file
|
||||||
from presentationcontroller import PresentationController, PresentationDocument
|
from presentationcontroller import PresentationController, PresentationDocument
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -292,8 +293,7 @@ class ImpressDocument(PresentationDocument):
|
|||||||
try:
|
try:
|
||||||
doc.storeToURL(urlpath, props)
|
doc.storeToURL(urlpath, props)
|
||||||
self.convert_thumbnail(path, idx + 1)
|
self.convert_thumbnail(path, idx + 1)
|
||||||
if os.path.exists(path):
|
delete_file(path)
|
||||||
os.remove(path)
|
|
||||||
except:
|
except:
|
||||||
log.exception(u'%s - Unable to store openoffice preview' % path)
|
log.exception(u'%s - Unable to store openoffice preview' % path)
|
||||||
|
|
||||||
|
@ -34,9 +34,6 @@ from songimport import SongImport
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
class CCLIFileImportError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class CCLIFileImport(SongImport):
|
class CCLIFileImport(SongImport):
|
||||||
"""
|
"""
|
||||||
The :class:`CCLIFileImport` class provides OpenLP with the ability to
|
The :class:`CCLIFileImport` class provides OpenLP with the ability to
|
||||||
@ -152,7 +149,6 @@ class CCLIFileImport(SongImport):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
log.debug(u'USR file text: %s', textList)
|
log.debug(u'USR file text: %s', textList)
|
||||||
lyrics = []
|
|
||||||
self.set_defaults()
|
self.set_defaults()
|
||||||
for line in textList:
|
for line in textList:
|
||||||
if line.startswith(u'Title='):
|
if line.startswith(u'Title='):
|
||||||
|
Loading…
Reference in New Issue
Block a user