From b7da0be71ec99b2bc44b60a5d9371a4853a67a08 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 5 Apr 2016 18:10:51 +0100 Subject: [PATCH] move method --- openlp/core/common/__init__.py | 30 ++++++++++++++++++- openlp/core/lib/db.py | 3 +- openlp/core/ui/servicemanager.py | 3 +- openlp/core/ui/thememanager.py | 3 +- openlp/core/utils/__init__.py | 30 +------------------ .../plugins/bibles/forms/bibleupgradeform.py | 4 +-- openlp/plugins/bibles/lib/manager.py | 3 +- openlp/plugins/images/lib/mediaitem.py | 5 ++-- .../presentations/lib/impresscontroller.py | 3 +- .../plugins/songs/lib/importers/openoffice.py | 1 - .../openlp_core_utils/test_utils.py | 4 +-- 11 files changed, 42 insertions(+), 47 deletions(-) diff --git a/openlp/core/common/__init__.py b/openlp/core/common/__init__.py index a20aa48ae..7b5c9f3fd 100644 --- a/openlp/core/common/__init__.py +++ b/openlp/core/common/__init__.py @@ -298,4 +298,32 @@ def get_filesystem_encoding(): encoding = sys.getfilesystemencoding() if encoding is None: encoding = sys.getdefaultencoding() - return encoding \ No newline at end of file + return encoding + + +def split_filename(path): + """ + Return a list of the parts in a given path. + """ + path = os.path.abspath(path) + if not os.path.isfile(path): + return path, '' + else: + return os.path.split(path) + + +def delete_file(file_path_name): + """ + Deletes a file from the system. + + :param 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 \ No newline at end of file diff --git a/openlp/core/lib/db.py b/openlp/core/lib/db.py index d63dee23c..7ae3cdc6f 100644 --- a/openlp/core/lib/db.py +++ b/openlp/core/lib/db.py @@ -34,9 +34,8 @@ from sqlalchemy.pool import NullPool from alembic.migration import MigrationContext from alembic.operations import Operations -from openlp.core.common import AppLocation, Settings, translate +from openlp.core.common import AppLocation, Settings, translate, delete_file from openlp.core.lib.ui import critical_error_message_box -from openlp.core.utils import delete_file log = logging.getLogger(__name__) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 129d24ca1..66cbdf1b7 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -33,12 +33,11 @@ from tempfile import mkstemp from PyQt5 import QtCore, QtGui, QtWidgets from openlp.core.common import Registry, RegistryProperties, AppLocation, Settings, ThemeLevel, OpenLPMixin, \ - RegistryMixin, check_directory_exists, UiStrings, translate + RegistryMixin, check_directory_exists, UiStrings, translate, split_filename, delete_file from openlp.core.common.actions import ActionList, CategoryOrder from openlp.core.lib import OpenLPToolbar, ServiceItem, ItemCapabilities, PluginStatus, build_icon from openlp.core.lib.ui import critical_error_message_box, create_widget_action, find_and_set_in_combo_box from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm, StartTimeForm -from openlp.core.utils import delete_file, split_filename from openlp.core.common.languagemanager import format_time diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 9d1b2d8e7..a80640150 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -30,13 +30,12 @@ from xml.etree.ElementTree import ElementTree, XML from PyQt5 import QtCore, QtGui, QtWidgets from openlp.core.common import Registry, RegistryProperties, AppLocation, Settings, OpenLPMixin, RegistryMixin, \ - check_directory_exists, UiStrings, translate, is_win, get_filesystem_encoding + check_directory_exists, UiStrings, translate, is_win, get_filesystem_encoding, delete_file from openlp.core.lib import FileDialog, ImageSource, OpenLPToolbar, ValidationError, get_text_file_string, build_icon, \ check_item_selected, create_thumb, validate_thumb from openlp.core.lib.theme import ThemeXML, BackgroundType from openlp.core.lib.ui import critical_error_message_box, create_widget_action from openlp.core.ui import FileRenameForm, ThemeForm -from openlp.core.utils import delete_file from openlp.core.common.languagemanager import get_locale_key diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 2fea5df80..0be2338b3 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -142,17 +142,6 @@ def is_not_image_file(file_name): return True -def split_filename(path): - """ - Return a list of the parts in a given path. - """ - path = os.path.abspath(path) - if not os.path.isfile(path): - return path, '' - else: - return os.path.split(path) - - def clean_filename(filename): """ Removes invalid characters from the given ``filename``. @@ -164,23 +153,6 @@ def clean_filename(filename): return INVALID_FILE_CHARS.sub('_', CONTROL_CHARS.sub('', filename)) -def delete_file(file_path_name): - """ - Deletes a file from the system. - - :param 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_user_agent(): """ Return a user agent customised for the platform the user is on. @@ -269,4 +241,4 @@ def get_web_page(url, header=None, update_openlp=False): __all__ = ['get_application_version', 'check_latest_version', - 'get_web_page', 'delete_file', 'clean_filename'] + 'get_web_page', 'clean_filename'] diff --git a/openlp/plugins/bibles/forms/bibleupgradeform.py b/openlp/plugins/bibles/forms/bibleupgradeform.py index 4adfeaf3b..611e6ead3 100644 --- a/openlp/plugins/bibles/forms/bibleupgradeform.py +++ b/openlp/plugins/bibles/forms/bibleupgradeform.py @@ -29,10 +29,10 @@ from tempfile import gettempdir from PyQt5 import QtCore, QtWidgets -from openlp.core.common import Registry, AppLocation, UiStrings, Settings, check_directory_exists, translate +from openlp.core.common import Registry, AppLocation, UiStrings, Settings, check_directory_exists, translate, \ + delete_file from openlp.core.lib.ui import critical_error_message_box from openlp.core.ui.wizard import OpenLPWizard, WizardStrings -from openlp.core.utils import delete_file from openlp.plugins.bibles.lib.db import BibleDB, BibleMeta, OldBibleDB, BiblesResourcesDB from openlp.plugins.bibles.lib.http import BSExtract, BGExtract, CWExtract diff --git a/openlp/plugins/bibles/lib/manager.py b/openlp/plugins/bibles/lib/manager.py index 8cecbe0af..b8b7ee56f 100644 --- a/openlp/plugins/bibles/lib/manager.py +++ b/openlp/plugins/bibles/lib/manager.py @@ -23,8 +23,7 @@ import logging import os -from openlp.core.common import RegistryProperties, AppLocation, Settings, translate -from openlp.core.utils import delete_file +from openlp.core.common import RegistryProperties, AppLocation, Settings, translate, delete_file from openlp.plugins.bibles.lib import parse_reference, get_reference_separator, LanguageSelection from openlp.plugins.bibles.lib.db import BibleDB, BibleMeta from .csvbible import CSVBible diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index c57442156..6efcc32df 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -25,11 +25,12 @@ import os from PyQt5 import QtCore, QtGui, QtWidgets -from openlp.core.common import Registry, AppLocation, Settings, UiStrings, check_directory_exists, translate +from openlp.core.common import Registry, AppLocation, Settings, UiStrings, check_directory_exists, translate, \ + delete_file from openlp.core.lib import ItemCapabilities, MediaManagerItem, ServiceItemContext, StringContent, TreeWidgetWithDnD,\ build_icon, check_item_selected, create_thumb, validate_thumb from openlp.core.lib.ui import create_widget_action, critical_error_message_box -from openlp.core.utils import delete_file, get_images_filter +from openlp.core.utils import get_images_filter from openlp.core.common.languagemanager import get_locale_key from openlp.plugins.images.forms import AddGroupForm, ChooseGroupForm from openlp.plugins.images.lib.db import ImageFilenames, ImageGroups diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index 8f5742712..29af3a375 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -35,7 +35,7 @@ import logging import os import time -from openlp.core.common import is_win, Registry, get_uno_command, get_uno_instance +from openlp.core.common import is_win, Registry, get_uno_command, get_uno_instance, delete_file if is_win(): from win32com.client import Dispatch @@ -57,7 +57,6 @@ else: from PyQt5 import QtCore from openlp.core.lib import ScreenList -from openlp.core.utils import delete_file from openlp.core.common import get_uno_command, get_uno_instance from .presentationcontroller import PresentationController, PresentationDocument, TextType diff --git a/openlp/plugins/songs/lib/importers/openoffice.py b/openlp/plugins/songs/lib/importers/openoffice.py index e8bd60439..b21f3a7d3 100644 --- a/openlp/plugins/songs/lib/importers/openoffice.py +++ b/openlp/plugins/songs/lib/importers/openoffice.py @@ -26,7 +26,6 @@ import time from PyQt5 import QtCore from openlp.core.common import is_win, get_uno_command, get_uno_instance -from openlp.core.utils import get_uno_command, get_uno_instance from openlp.core.lib import translate from .songimport import SongImport diff --git a/tests/functional/openlp_core_utils/test_utils.py b/tests/functional/openlp_core_utils/test_utils.py index 0bd4f1645..d0bb07f95 100644 --- a/tests/functional/openlp_core_utils/test_utils.py +++ b/tests/functional/openlp_core_utils/test_utils.py @@ -25,8 +25,8 @@ Functional tests to test the AppLocation class and related methods. import os from unittest import TestCase -from openlp.core.utils import clean_filename, delete_file, split_filename, _get_user_agent, get_web_page -from openlp.core.common import get_filesystem_encoding +from openlp.core.utils import clean_filename, _get_user_agent, get_web_page +from openlp.core.common import get_filesystem_encoding, split_filename, delete_file from tests.functional import MagicMock, patch