- Include the author(s) in the file name, to prevent overwriting songs with the same name

bzr-revno: 1368
This commit is contained in:
Andreas Preikschat 2011-03-11 07:02:26 +02:00 committed by Raoul Snyman
commit f8e9bd3525

View File

@ -29,10 +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 Receiver, translate from openlp.core.lib import check_directory_exists, 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,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))
tree.write(os.path.join(self.save_path, song.title + u'.xml'), 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) encoding=u'utf-8', xml_declaration=True, pretty_print=True)
return True return True