Fixes: https://launchpad.net/bugs/730979
This commit is contained in:
Andreas Preikschat 2011-03-08 22:09:52 +01:00
parent ba472d456d
commit fcadc58e75
3 changed files with 20 additions and 20 deletions

View File

@ -29,6 +29,7 @@ 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
@ -320,6 +321,17 @@ 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,14 +26,13 @@
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 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.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
@ -155,7 +154,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 = self.clean_filename(self.name) self.file = clean_file_name(self.name) + u'.sqlite'
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)
@ -183,19 +182,6 @@ 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

@ -32,7 +32,8 @@ import os
from lxml import etree 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 from openlp.plugins.songs.lib import OpenLyrics
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -50,8 +51,7 @@ class OpenLyricsExport(object):
self.manager = parent.plugin.manager self.manager = parent.plugin.manager
self.songs = songs self.songs = songs
self.save_path = save_path self.save_path = save_path
if not os.path.exists(self.save_path): check_directory_exists(self.save_path)
os.mkdir(self.save_path)
def do_export(self): def do_export(self):
""" """
@ -69,6 +69,8 @@ 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))
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) encoding=u'utf-8', xml_declaration=True, pretty_print=True)
return True return True