move method

This commit is contained in:
Tim Bentley 2016-04-05 18:10:51 +01:00
parent f19280c88d
commit b7da0be71e
11 changed files with 42 additions and 47 deletions

View File

@ -298,4 +298,32 @@ def get_filesystem_encoding():
encoding = sys.getfilesystemencoding()
if encoding is None:
encoding = sys.getdefaultencoding()
return encoding
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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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