From 3298fa1e15f0d110210391a92812ac219accf817 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 10 Mar 2011 17:05:12 +0100 Subject: [PATCH] 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