fix inconsistant field names, refer now to the xml file

This commit is contained in:
Armin Köhler 2011-02-22 21:35:18 +01:00
parent 0ecc3c2dc9
commit 71068d4eb6

View File

@ -105,7 +105,7 @@ log = logging.getLogger(__name__)
class FoilPresenterImport(SongImport): class FoilPresenterImport(SongImport):
""" """
This provides the Openlyrics import. This provides the Foilpresenter import.
""" """
def __init__(self, master_manager, **kwargs): def __init__(self, master_manager, **kwargs):
""" """
@ -263,37 +263,37 @@ class FoilPresenter(object):
strings = [] strings = []
author_temp = [] author_temp = []
if copyright.find(u'Copyright') != -1: if copyright.find(u'Copyright') != -1:
test = copyright.partition(u'Copyright') temp = copyright.partition(u'Copyright')
copyright = test[0] copyright = temp[0]
elif copyright.find(u'copyright') != -1: elif copyright.find(u'copyright') != -1:
test = copyright.partition(u'copyright') temp = copyright.partition(u'copyright')
copyright = test[0] copyright = temp[0]
elif copyright.find(u'©') != -1: elif copyright.find(u'©') != -1:
test = copyright.partition(u'©') temp = copyright.partition(u'©')
copyright = test[0] copyright = temp[0]
elif copyright.find(u'(c)') != -1: elif copyright.find(u'(c)') != -1:
test = copyright.partition(u'(c)') temp = copyright.partition(u'(c)')
copyright = test[0] copyright = temp[0]
elif copyright.find(u'(C)') != -1: elif copyright.find(u'(C)') != -1:
test = copyright.partition(u'(C)') temp = copyright.partition(u'(C)')
copyright = test[0] copyright = temp[0]
elif copyright.find(u'c)') != -1: elif copyright.find(u'c)') != -1:
test = copyright.partition(u'c)') temp = copyright.partition(u'c)')
copyright = test[0] copyright = temp[0]
elif copyright.find(u'C)') != -1: elif copyright.find(u'C)') != -1:
test = copyright.partition(u'C)') temp = copyright.partition(u'C)')
copyright = test[0] copyright = temp[0]
elif copyright.find(u'C:') != -1: elif copyright.find(u'C:') != -1:
test = copyright.partition(u'C:') temp = copyright.partition(u'C:')
copyright = test[0] copyright = temp[0]
elif copyright.find(u'C,)') != -1: elif copyright.find(u'C,)') != -1:
test = copyright.partition(u'C,)') temp = copyright.partition(u'C,)')
copyright = test[0] copyright = temp[0]
copyright = re.compile(u'\\n').sub(u' ', copyright) copyright = re.compile(u'\\n').sub(u' ', copyright)
copyright = re.compile(u'\(.*\)').sub(u'', copyright) copyright = re.compile(u'\(.*\)').sub(u'', copyright)
if copyright.find(u'Rechte') != -1: if copyright.find(u'Rechte') != -1:
test = copyright.partition(u'Rechte') temp = copyright.partition(u'Rechte')
copyright = test[0] copyright = temp[0]
markers = [u'Text +u\.?n?d? +Melodie[a-zA-Z0-9\,\. ]*:', markers = [u'Text +u\.?n?d? +Melodie[a-zA-Z0-9\,\. ]*:',
u'Text +u\.?n?d? +Musik', u'T & M', u'Melodie und Satz', u'Text +u\.?n?d? +Musik', u'T & M', u'Melodie und Satz',
u'Text[a-zA-Z0-9\,\. ]*:', u'Melodie', u'Musik', u'Satz', u'Text[a-zA-Z0-9\,\. ]*:', u'Melodie', u'Musik', u'Satz',
@ -306,10 +306,10 @@ class FoilPresenter(object):
x = 0 x = 0
while i != 1: while i != 1:
if copyright.find(u'<marker>') != -1: if copyright.find(u'<marker>') != -1:
test = copyright.partition(u'<marker>') temp = copyright.partition(u'<marker>')
if (test[0].strip() != u'') & (x > 0): if (temp[0].strip() != u'') & (x > 0):
strings.append(test[0]) strings.append(temp[0])
copyright = test[2] copyright = temp[2]
x += 1 x += 1
elif x > 0: elif x > 0:
strings.append(copyright) strings.append(copyright)
@ -317,10 +317,10 @@ class FoilPresenter(object):
else: else:
i = 1 i = 1
for author in strings: for author in strings:
test = re.split(u',(?=\D{2})|(?<=\D),|\/(?=\D{3,})|(?<=\D);', temp = re.split(u',(?=\D{2})|(?<=\D),|\/(?=\D{3,})|(?<=\D);',
author) author)
for test_temp in test: for tempx in temp:
author_temp.append(test_temp) author_temp.append(tempx)
for author in author_temp: for author in author_temp:
regex = u'^[\/,;\-\s]+|[\/,;\-\s]+$|'\ regex = u'^[\/,;\-\s]+|[\/,;\-\s]+$|'\
'\s*[0-9]{4}\s*[\-\/]?\s*([0-9]{4})?[\/,;\-\s]*$' '\s*[0-9]{4}\s*[\-\/]?\s*([0-9]{4})?[\/,;\-\s]*$'
@ -334,9 +334,9 @@ class FoilPresenter(object):
u'\w+\.?\s+\w{3,}\s+[a|u]nd\s|\w+\.?\s+\w{3,}\s+&\s', u'\w+\.?\s+\w{3,}\s+[a|u]nd\s|\w+\.?\s+\w{3,}\s+&\s',
author, re.U) != None: author, re.U) != None:
temp = re.split(u'\s[a|u]nd\s|\s&\s', author) temp = re.split(u'\s[a|u]nd\s|\s&\s', author)
for temp_temp in temp: for tempx in temp:
temp_temp = temp_temp.strip() tempx = tempx.strip()
authors.append(temp_temp) authors.append(tempx)
elif (len(author) > 2): elif (len(author) > 2):
authors.append(author) authors.append(author)
if not authors: if not authors:
@ -347,8 +347,8 @@ class FoilPresenter(object):
if author is None: if author is None:
# We need to create a new author, as the author does not exist. # We need to create a new author, as the author does not exist.
author = Author.populate(display_name=display_name, author = Author.populate(display_name=display_name,
last_name=display_name.split(u' ')[-1], last_name = display_name.split(u' ')[-1],
first_name=u' '.join(display_name.split(u' ')[:-1])) first_name = u' '.join(display_name.split(u' ')[:-1]))
self.manager.save_object(author) self.manager.save_object(author)
song.authors.append(author) song.authors.append(author)
@ -404,9 +404,6 @@ class FoilPresenter(object):
``foilpresenterfolie`` ``foilpresenterfolie``
The foilpresenterfolie object (lxml.objectify.ObjectifiedElement). The foilpresenterfolie object (lxml.objectify.ObjectifiedElement).
``lyrics``
The lyrics object (lxml.objectify.ObjectifiedElement).
``song`` ``song``
The song object. The song object.
""" """
@ -418,14 +415,14 @@ class FoilPresenter(object):
temp_sortnr_backup = 1 temp_sortnr_backup = 1
temp_sortnr_liste = [] temp_sortnr_liste = []
versenumber = {u'V': 1, u'C': 1, u'B': 1, u'E': 1, u'O': 1, u'I': 1, versenumber = {u'V': 1, u'C': 1, u'B': 1, u'E': 1, u'O': 1, u'I': 1,
u'P': 1 } u'P': 1}
for strophe in foilpresenterfolie.strophen.strophe: for strophe in foilpresenterfolie.strophen.strophe:
text = self._child(strophe.text_) text = self._child(strophe.text_)
verse_name = self._child(strophe.key) verse_name = self._child(strophe.key)
children = strophe.getchildren() children = strophe.getchildren()
sortnr = 0 sortnr = 0
for child in children: for child in children:
if child.tag == 'sortnr': if child.tag == u'sortnr':
verse_sortnr = self._child(strophe.sortnr) verse_sortnr = self._child(strophe.sortnr)
sortnr = 1 sortnr = 1
# In older Version there is no sortnr, but we need one # In older Version there is no sortnr, but we need one
@ -506,8 +503,8 @@ class FoilPresenter(object):
song.song_book_id = 0 song.song_book_id = 0
song.song_number = u'' song.song_number = u''
try: try:
for songbook in foilpresenterfolie.buch.bucheintrag: for bucheintrag in foilpresenterfolie.buch.bucheintrag:
bookname = self._child(songbook.name) bookname = self._child(bucheintrag.name)
if bookname: if bookname:
book = self.manager.get_object_filtered(Book, book = self.manager.get_object_filtered(Book,
Book.name == bookname) Book.name == bookname)
@ -517,8 +514,8 @@ class FoilPresenter(object):
self.manager.save_object(book) self.manager.save_object(book)
song.song_book_id = book.id song.song_book_id = book.id
try: try:
if self._child(songbook.nummer): if self._child(bucheintrag.nummer):
song.song_number = self._child(songbook.nummer) song.song_number = self._child(bucheintrag.nummer)
except AttributeError: except AttributeError:
pass pass
# We only support one song book, so take the first one. # We only support one song book, so take the first one.
@ -536,13 +533,13 @@ class FoilPresenter(object):
``song`` ``song``
The song object. The song object.
""" """
for title in foilpresenterfolie.titel.titelstring: for titelstring in foilpresenterfolie.titel.titelstring:
if not song.title: if not song.title:
song.title = self._child(title) song.title = self._child(titelstring)
song.search_title = unicode(song.title) song.search_title = unicode(song.title)
song.alternate_title = u'' song.alternate_title = u''
else: else:
song.alternate_title = self._child(title) song.alternate_title = self._child(titelstring)
song.search_title += u'@' + song.alternate_title song.search_title += u'@' + song.alternate_title
song.search_title = re.sub(r'[\'"`,;:(){}?]+', u'', song.search_title = re.sub(r'[\'"`,;:(){}?]+', u'',
unicode(song.search_title)).lower() unicode(song.search_title)).lower()
@ -558,8 +555,8 @@ class FoilPresenter(object):
The song object. The song object.
""" """
try: try:
for topictext in foilpresenterfolie.kategorien.name: for name in foilpresenterfolie.kategorien.name:
topictext = self._child(topictext) topictext = self._child(name)
if topictext: if topictext:
topic = self.manager.get_object_filtered(Topic, topic = self.manager.get_object_filtered(Topic,
Topic.name == topictext) Topic.name == topictext)