reverted changed, due to database problems

This commit is contained in:
Andreas Preikschat 2011-03-10 17:05:12 +01:00
parent 262b179d07
commit 3298fa1e15
3 changed files with 22 additions and 18 deletions

View File

@ -29,7 +29,6 @@ OpenLP work.
""" """
import logging import logging
import os.path import os.path
import re
import types import types
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
@ -321,17 +320,6 @@ def check_directory_exists(dir):
if not os.path.exists(dir): if not os.path.exists(dir):
os.makedirs(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 listwidgetwithdnd import ListWidgetWithDnD
from displaytags import DisplayTags from displaytags import DisplayTags
from spelltextedit import SpellTextEdit from spelltextedit import SpellTextEdit

View File

@ -26,13 +26,14 @@
import logging import logging
import chardet import chardet
import re
from PyQt4 import QtCore from PyQt4 import QtCore
from sqlalchemy import Column, ForeignKey, or_, Table, types from sqlalchemy import Column, ForeignKey, or_, Table, types
from sqlalchemy.orm import class_mapper, mapper, relation from sqlalchemy.orm import class_mapper, mapper, relation
from sqlalchemy.orm.exc import UnmappedClassError 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.db import BaseModel, init_db, Manager
from openlp.core.lib.ui import critical_error_message_box from openlp.core.lib.ui import critical_error_message_box
@ -154,7 +155,7 @@ class BibleDB(QtCore.QObject, Manager):
self.name = kwargs[u'name'] self.name = kwargs[u'name']
if not isinstance(self.name, unicode): if not isinstance(self.name, unicode):
self.name = unicode(self.name, u'utf-8') 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: if u'file' in kwargs:
self.file = kwargs[u'file'] self.file = kwargs[u'file']
Manager.__init__(self, u'bibles', init_schema, self.file) Manager.__init__(self, u'bibles', init_schema, self.file)
@ -182,6 +183,19 @@ class BibleDB(QtCore.QObject, Manager):
self.name = None self.name = None
return self.name 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): def register(self, wizard):
""" """
This method basically just initialialises the database. It is called This method basically just initialialises the database. It is called

View File

@ -29,11 +29,11 @@ songs from the database to the OpenLyrics format.
""" """
import logging import logging
import os import os
import re
from lxml import etree from lxml import etree
from openlp.core.lib import check_directory_exists, clean_file_name, Receiver, \ from openlp.core.lib import check_directory_exists, Receiver, translate
translate
from openlp.plugins.songs.lib import OpenLyrics from openlp.plugins.songs.lib import OpenLyrics
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -69,8 +69,10 @@ class OpenLyricsExport(object):
song.title) song.title)
xml = openLyrics.song_to_xml(song) xml = openLyrics.song_to_xml(song)
tree = etree.ElementTree(etree.fromstring(xml)) tree = etree.ElementTree(etree.fromstring(xml))
filename = clean_file_name(u'%s (%s).xml' % (song.title, filename = u'%s (%s).xml' % (song.title,
u', '.join([author.display_name for author in song.authors]))) 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), tree.write(os.path.join(self.save_path, filename),
encoding=u'utf-8', xml_declaration=True, pretty_print=True) encoding=u'utf-8', xml_declaration=True, pretty_print=True)
return True return True