From fcadc58e75c744c6fa167c036f871de573f5f751 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Tue, 8 Mar 2011 22:09:52 +0100 Subject: [PATCH 1/2] fixed bug #730979 Fixes: https://launchpad.net/bugs/730979 --- openlp/core/lib/__init__.py | 12 ++++++++++++ openlp/plugins/bibles/lib/db.py | 18 ++---------------- openlp/plugins/songs/lib/openlyricsexport.py | 10 ++++++---- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index dc60a5a65..e92b9c64a 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -29,6 +29,7 @@ OpenLP work. """ import logging import os.path +import re import types from PyQt4 import QtCore, QtGui @@ -320,6 +321,17 @@ def check_directory_exists(dir): if not os.path.exists(dir): os.makedirs(dir) +def clean_file_name(path): + """ + Removes not supported characters from the given path. + + ``path`` + The path to clean. + """ + if not isinstance(path, unicode): + path = unicode(path, u'utf-8') + return re.sub(r'[/\\?*|<>\[\]":<>+%]+', u'_', path).strip(u'_') + from listwidgetwithdnd import ListWidgetWithDnD from displaytags import DisplayTags from spelltextedit import SpellTextEdit diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 5cf000ee1..2021afa40 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -26,14 +26,13 @@ import logging import chardet -import re from PyQt4 import QtCore from sqlalchemy import Column, ForeignKey, or_, Table, types from sqlalchemy.orm import class_mapper, mapper, relation from sqlalchemy.orm.exc import UnmappedClassError -from openlp.core.lib import Receiver, translate +from openlp.core.lib import clean_file_name, Receiver, translate from openlp.core.lib.db import BaseModel, init_db, Manager from openlp.core.lib.ui import critical_error_message_box @@ -155,7 +154,7 @@ class BibleDB(QtCore.QObject, Manager): self.name = kwargs[u'name'] if not isinstance(self.name, unicode): self.name = unicode(self.name, u'utf-8') - self.file = self.clean_filename(self.name) + self.file = clean_file_name(self.name) + u'.sqlite' if u'file' in kwargs: self.file = kwargs[u'file'] Manager.__init__(self, u'bibles', init_schema, self.file) @@ -183,19 +182,6 @@ class BibleDB(QtCore.QObject, Manager): self.name = None return self.name - def clean_filename(self, old_filename): - """ - Clean up the version name of the Bible and convert it into a valid - file name. - - ``old_filename`` - The "dirty" file name or version name. - """ - if not isinstance(old_filename, unicode): - old_filename = unicode(old_filename, u'utf-8') - old_filename = re.sub(r'[^\w]+', u'_', old_filename).strip(u'_') - return old_filename + u'.sqlite' - def register(self, wizard): """ This method basically just initialialises the database. It is called diff --git a/openlp/plugins/songs/lib/openlyricsexport.py b/openlp/plugins/songs/lib/openlyricsexport.py index c2b58980b..f4fdd769a 100644 --- a/openlp/plugins/songs/lib/openlyricsexport.py +++ b/openlp/plugins/songs/lib/openlyricsexport.py @@ -32,7 +32,8 @@ import os from lxml import etree -from openlp.core.lib import Receiver, translate +from openlp.core.lib import check_directory_exists, clean_file_name, Receiver, \ + translate from openlp.plugins.songs.lib import OpenLyrics log = logging.getLogger(__name__) @@ -50,8 +51,7 @@ class OpenLyricsExport(object): self.manager = parent.plugin.manager self.songs = songs self.save_path = save_path - if not os.path.exists(self.save_path): - os.mkdir(self.save_path) + check_directory_exists(self.save_path) def do_export(self): """ @@ -69,6 +69,8 @@ class OpenLyricsExport(object): song.title) xml = openLyrics.song_to_xml(song) tree = etree.ElementTree(etree.fromstring(xml)) - tree.write(os.path.join(self.save_path, song.title + u'.xml'), + filename = clean_file_name(u'%s (%s).xml' % (song.title, + u', '.join([author.display_name for author in song.authors]))) + tree.write(os.path.join(self.save_path, filename), encoding=u'utf-8', xml_declaration=True, pretty_print=True) return True From 3298fa1e15f0d110210391a92812ac219accf817 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 10 Mar 2011 17:05:12 +0100 Subject: [PATCH 2/2] reverted changed, due to database problems --- openlp/core/lib/__init__.py | 12 ------------ openlp/plugins/bibles/lib/db.py | 18 ++++++++++++++++-- openlp/plugins/songs/lib/openlyricsexport.py | 10 ++++++---- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index e92b9c64a..dc60a5a65 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -29,7 +29,6 @@ OpenLP work. """ import logging import os.path -import re import types from PyQt4 import QtCore, QtGui @@ -321,17 +320,6 @@ def check_directory_exists(dir): if not os.path.exists(dir): os.makedirs(dir) -def clean_file_name(path): - """ - Removes not supported characters from the given path. - - ``path`` - The path to clean. - """ - if not isinstance(path, unicode): - path = unicode(path, u'utf-8') - return re.sub(r'[/\\?*|<>\[\]":<>+%]+', u'_', path).strip(u'_') - from listwidgetwithdnd import ListWidgetWithDnD from displaytags import DisplayTags from spelltextedit import SpellTextEdit diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 2021afa40..5cf000ee1 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -26,13 +26,14 @@ import logging import chardet +import re from PyQt4 import QtCore from sqlalchemy import Column, ForeignKey, or_, Table, types from sqlalchemy.orm import class_mapper, mapper, relation from sqlalchemy.orm.exc import UnmappedClassError -from openlp.core.lib import clean_file_name, Receiver, translate +from openlp.core.lib import Receiver, translate from openlp.core.lib.db import BaseModel, init_db, Manager from openlp.core.lib.ui import critical_error_message_box @@ -154,7 +155,7 @@ class BibleDB(QtCore.QObject, Manager): self.name = kwargs[u'name'] if not isinstance(self.name, unicode): self.name = unicode(self.name, u'utf-8') - self.file = clean_file_name(self.name) + u'.sqlite' + self.file = self.clean_filename(self.name) if u'file' in kwargs: self.file = kwargs[u'file'] Manager.__init__(self, u'bibles', init_schema, self.file) @@ -182,6 +183,19 @@ class BibleDB(QtCore.QObject, Manager): self.name = None return self.name + def clean_filename(self, old_filename): + """ + Clean up the version name of the Bible and convert it into a valid + file name. + + ``old_filename`` + The "dirty" file name or version name. + """ + if not isinstance(old_filename, unicode): + old_filename = unicode(old_filename, u'utf-8') + old_filename = re.sub(r'[^\w]+', u'_', old_filename).strip(u'_') + return old_filename + u'.sqlite' + def register(self, wizard): """ This method basically just initialialises the database. It is called diff --git a/openlp/plugins/songs/lib/openlyricsexport.py b/openlp/plugins/songs/lib/openlyricsexport.py index f4fdd769a..42410a7e0 100644 --- a/openlp/plugins/songs/lib/openlyricsexport.py +++ b/openlp/plugins/songs/lib/openlyricsexport.py @@ -29,11 +29,11 @@ songs from the database to the OpenLyrics format. """ import logging import os +import re from lxml import etree -from openlp.core.lib import check_directory_exists, clean_file_name, Receiver, \ - translate +from openlp.core.lib import check_directory_exists, Receiver, translate from openlp.plugins.songs.lib import OpenLyrics log = logging.getLogger(__name__) @@ -69,8 +69,10 @@ class OpenLyricsExport(object): song.title) xml = openLyrics.song_to_xml(song) tree = etree.ElementTree(etree.fromstring(xml)) - filename = clean_file_name(u'%s (%s).xml' % (song.title, - u', '.join([author.display_name for author in song.authors]))) + filename = u'%s (%s).xml' % (song.title, + u', '.join([author.display_name for author in song.authors])) + filename = re.sub( + r'[/\\?*|<>\[\]":<>+%]+', u'_', filename).strip(u'_') tree.write(os.path.join(self.save_path, filename), encoding=u'utf-8', xml_declaration=True, pretty_print=True) return True