From 26df14e43c84a99cb22c628e2afd6577cae53f6a Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Sun, 11 Dec 2011 14:53:44 +0000 Subject: [PATCH 1/3] Fix v1 theme importing --- openlp/core/ui/thememanager.py | 14 ++++++++------ openlp/core/utils/__init__.py | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 596bce5d9..6b43f2496 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -44,7 +44,7 @@ from openlp.core.lib.ui import UiStrings, critical_error_message_box, \ from openlp.core.theme import Theme from openlp.core.ui import FileRenameForm, ThemeForm from openlp.core.utils import AppLocation, delete_file, file_is_unicode, \ - get_filesystem_encoding + file_is_mbcs, get_filesystem_encoding log = logging.getLogger(__name__) @@ -528,11 +528,13 @@ class ThemeManager(QtGui.QWidget): for file in zip.namelist(): ucsfile = file_is_unicode(file) if not ucsfile: - critical_error_message_box( - message=translate('OpenLP.ThemeManager', - 'File is not a valid theme.\n' - 'The content encoding is not UTF-8.')) - continue + ucsfile = file_is_mbcs(file) + if not ucsfile: + critical_error_message_box( + message=translate('OpenLP.ThemeManager', + 'File is not a valid theme.\n' + 'The content encoding is not UTF-8.')) + continue osfile = unicode(QtCore.QDir.toNativeSeparators(ucsfile)) theme_dir = None if osfile.endswith(os.path.sep): diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index fbf185474..9aa1acde6 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -475,6 +475,26 @@ def file_is_unicode(filename): return None return ucsfile +def file_is_mbcs(filename): + """ + Checks if a file is valid Windows file system encoded unicode and returns + the unicode decoded file or None. + + ``filename`` + File to check is valid Windows file system encoded. + """ + if not filename: + return None + ucsfile = None + try: + ucsfile = filename.decode(u'mbcs') + except UnicodeDecodeError: + log.exception(u'Filename "%s" is not valid Windows encoded file' % + filename.decode(u'mbcs', u'replace')) + if not ucsfile: + return None + return ucsfile + def get_uno_command(): """ Returns the UNO command to launch an openoffice.org instance. From e5d1fca74d9d926a5708ff1a60cc73299d99c609 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Sun, 11 Dec 2011 15:31:44 +0000 Subject: [PATCH 2/3] Previous fix broke on non-Windows, try again --- openlp/core/ui/thememanager.py | 12 ++++-------- openlp/core/utils/__init__.py | 20 -------------------- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 6b43f2496..7c9fc073d 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -44,7 +44,7 @@ from openlp.core.lib.ui import UiStrings, critical_error_message_box, \ from openlp.core.theme import Theme from openlp.core.ui import FileRenameForm, ThemeForm from openlp.core.utils import AppLocation, delete_file, file_is_unicode, \ - file_is_mbcs, get_filesystem_encoding + get_filesystem_encoding log = logging.getLogger(__name__) @@ -526,15 +526,11 @@ class ThemeManager(QtGui.QWidget): zip = zipfile.ZipFile(filename) themename = None for file in zip.namelist(): + # Handle UTF-8 files ucsfile = file_is_unicode(file) if not ucsfile: - ucsfile = file_is_mbcs(file) - if not ucsfile: - critical_error_message_box( - message=translate('OpenLP.ThemeManager', - 'File is not a valid theme.\n' - 'The content encoding is not UTF-8.')) - continue + # Handle native Unicode files from Windows + ucsfile = file osfile = unicode(QtCore.QDir.toNativeSeparators(ucsfile)) theme_dir = None if osfile.endswith(os.path.sep): diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 9aa1acde6..fbf185474 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -475,26 +475,6 @@ def file_is_unicode(filename): return None return ucsfile -def file_is_mbcs(filename): - """ - Checks if a file is valid Windows file system encoded unicode and returns - the unicode decoded file or None. - - ``filename`` - File to check is valid Windows file system encoded. - """ - if not filename: - return None - ucsfile = None - try: - ucsfile = filename.decode(u'mbcs') - except UnicodeDecodeError: - log.exception(u'Filename "%s" is not valid Windows encoded file' % - filename.decode(u'mbcs', u'replace')) - if not ucsfile: - return None - return ucsfile - def get_uno_command(): """ Returns the UNO command to launch an openoffice.org instance. From 85e29678548ca8f8acb42c9ad362f1b9dbcdd4e6 Mon Sep 17 00:00:00 2001 From: Jon Tibble Date: Sun, 11 Dec 2011 16:23:24 +0000 Subject: [PATCH 3/3] Fix logging theme names --- openlp/core/ui/thememanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 7c9fc073d..b8767d736 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -618,7 +618,7 @@ class ThemeManager(QtGui.QWidget): """ name = theme.theme_name theme_pretty_xml = theme.extract_formatted_xml() - log.debug(u'saveTheme %s %s', name, theme_pretty_xml) + log.debug(u'saveTheme %s %s', name, theme_pretty_xml.decode(u'utf-8')) theme_dir = os.path.join(self.path, name) check_directory_exists(theme_dir) theme_file = os.path.join(theme_dir, name + u'.xml')