forked from openlp/openlp
More code convention corrections
This commit is contained in:
parent
5734c3052a
commit
ce73d86e0a
@ -142,51 +142,52 @@ class CCLIFileImport(SongImport):
|
|||||||
"""
|
"""
|
||||||
log.debug(u'USR file text: %s', textList)
|
log.debug(u'USR file text: %s', textList)
|
||||||
lyrics = []
|
lyrics = []
|
||||||
new_song = SongImport(self.manager)
|
# new_song = SongImport(self.manager)
|
||||||
|
self.set_defaults()
|
||||||
for line in textList:
|
for line in textList:
|
||||||
if line.startswith(u'Title='):
|
if line.startswith(u'Title='):
|
||||||
sname = line[6:].strip()
|
song_name = line[6:].strip()
|
||||||
elif line.startswith(u'Author='):
|
elif line.startswith(u'Author='):
|
||||||
sauthor = line[7:].strip()
|
song_author = line[7:].strip()
|
||||||
elif line.startswith(u'Copyright='):
|
elif line.startswith(u'Copyright='):
|
||||||
scopyright = line[10:].strip()
|
song_copyright = line[10:].strip()
|
||||||
elif line.startswith(u'[S A'):
|
elif line.startswith(u'[S A'):
|
||||||
sccli = line[4:-3].strip()
|
song_ccli = line[4:-3].strip()
|
||||||
elif line.startswith(u'Fields='):
|
elif line.startswith(u'Fields='):
|
||||||
#Fields contain single line indicating verse, chorus, etc,
|
#Fields contain single line indicating verse, chorus, etc,
|
||||||
#/t delimited, same as with words field. store seperately
|
#/t delimited, same as with words field. store seperately
|
||||||
#and process at end.
|
#and process at end.
|
||||||
sfields = line[7:].strip()
|
song_fields = line[7:].strip()
|
||||||
elif line.startswith(u'Words='):
|
elif line.startswith(u'Words='):
|
||||||
swords = line[6:].strip()
|
song_words = line[6:].strip()
|
||||||
#Unhandled usr keywords:Type,Version,Admin,Themes,Keys
|
#Unhandled usr keywords:Type,Version,Admin,Themes,Keys
|
||||||
#Process Fields and words sections
|
#Process Fields and words sections
|
||||||
fieldlst = sfields.split(u'/t')
|
field_list = song_fields.split(u'/t')
|
||||||
wordslst = swords.split(u'/t')
|
words_list = song_words.split(u'/t')
|
||||||
for counter in range(0, len(fieldlst)):
|
for counter in range(0, len(field_list)):
|
||||||
if fieldlst[counter].startswith(u'Ver'):
|
if field_list[counter].startswith(u'Ver'):
|
||||||
vtype = u'V'
|
verse_type = u'V'
|
||||||
elif fieldlst[counter].startswith(u'Ch'):
|
elif field_list[counter].startswith(u'Ch'):
|
||||||
vtype = u'C'
|
verse_type = u'C'
|
||||||
elif fieldlst[counter].startswith(u'Br'):
|
elif field_list[counter].startswith(u'Br'):
|
||||||
vtype = u'B'
|
verse_type = u'B'
|
||||||
else: #Other
|
else: #Other
|
||||||
vtype = u'O'
|
verse_type = u'O'
|
||||||
vcontent = unicode(wordslst[counter])
|
verse_text = unicode(words_list[counter])
|
||||||
vcontent = vcontent.replace("/n", "\n")
|
verse_text = verse_text.replace("/n", "\n")
|
||||||
if (len(vcontent) > 0):
|
if len(verse_text) > 0:
|
||||||
new_song.add_verse(vcontent, vtype);
|
self.add_verse(verse_text, verse_type);
|
||||||
#Handle multiple authors
|
#Handle multiple authors
|
||||||
lst = sauthor.split(u'/')
|
author_list = song_author.split(u'/')
|
||||||
if len(lst) < 2:
|
if len(author_list) < 2:
|
||||||
lst = sauthor.split(u'|')
|
author_list = song_author.split(u'|')
|
||||||
for author in lst:
|
for author in author_list:
|
||||||
seperated = author.split(u',')
|
seperated = author.split(u',')
|
||||||
new_song.add_author(seperated[1].strip() + " " + seperated[0].strip())
|
self.add_author(seperated[1].strip() + " " + seperated[0].strip())
|
||||||
new_song.title = sname
|
self.title = song_name
|
||||||
new_song.copyright = scopyright
|
self.copyright = song_copyright
|
||||||
new_song.ccli_number = sccli
|
self.ccli_number = song_ccli
|
||||||
new_song.finish()
|
self.finish()
|
||||||
|
|
||||||
def do_import_txt_file(self, textList):
|
def do_import_txt_file(self, textList):
|
||||||
"""
|
"""
|
||||||
@ -234,75 +235,78 @@ class CCLIFileImport(SongImport):
|
|||||||
e.g. CCL-Liedlizenznummer: 14 / CCLI License No. 14
|
e.g. CCL-Liedlizenznummer: 14 / CCLI License No. 14
|
||||||
"""
|
"""
|
||||||
log.debug(u'TXT file text: %s', textList)
|
log.debug(u'TXT file text: %s', textList)
|
||||||
new_song = SongImport(self.manager)
|
# new_song = SongImport(self.manager)
|
||||||
lnum = 0
|
self.set_defaults()
|
||||||
vcontent = u''
|
line_number = 0
|
||||||
scomments = u''
|
verse_text = u''
|
||||||
scopyright = u'';
|
song_comments = u''
|
||||||
|
song_copyright = u'';
|
||||||
verse_start = False
|
verse_start = False
|
||||||
for line in textList:
|
for line in textList:
|
||||||
line = line.strip()
|
clean_line = line.strip()
|
||||||
if not line:
|
if not clean_line:
|
||||||
if (lnum==0):
|
if line_number==0:
|
||||||
continue
|
continue
|
||||||
elif verse_start:
|
elif verse_start:
|
||||||
if vcontent:
|
if verse_text:
|
||||||
new_song.add_verse(vcontent, vtype)
|
self.add_verse(verse_text, verse_type)
|
||||||
vcontent = ''
|
verse_text = ''
|
||||||
verse_start = False
|
verse_start = False
|
||||||
else:
|
else:
|
||||||
#lnum=0, song title
|
#line_number=0, song title
|
||||||
if (lnum==0):
|
if line_number==0:
|
||||||
sname = line
|
song_name = clean_line
|
||||||
lnum += 1
|
line_number += 1
|
||||||
#lnum=1, verses
|
#line_number=1, verses
|
||||||
elif (lnum==1):
|
elif line_number==1:
|
||||||
#lnum=1, ccli number, first line after verses
|
#line_number=1, ccli number, first line after verses
|
||||||
if line.startswith(u'CCLI'):
|
if clean_line.startswith(u'CCLI'):
|
||||||
lnum += 1
|
line_number += 1
|
||||||
cparts = line.split(' ')
|
ccli_parts = clean_line.split(' ')
|
||||||
sccli = cparts[len(cparts)-1]
|
song_ccli = ccli_parts[len(ccli_parts)-1]
|
||||||
elif (verse_start == False):
|
elif not verse_start:
|
||||||
# We have the verse descriptor
|
# We have the verse descriptor
|
||||||
parts = line.split(' ')
|
verse_desc_parts = clean_line.split(' ')
|
||||||
if (len(parts) == 2):
|
if len(verse_desc_parts) == 2:
|
||||||
if parts[0].startswith(u'Ver'):
|
if verse_desc_parts[0].startswith(u'Ver'):
|
||||||
vtype = u'V'
|
verse_type = u'V'
|
||||||
elif parts[0].startswith(u'Ch'):
|
elif verse_desc_parts[0].startswith(u'Ch'):
|
||||||
vtype = u'C'
|
verse_type = u'C'
|
||||||
elif parts[0].startswith(u'Br'):
|
elif verse_desc_parts[0].startswith(u'Br'):
|
||||||
vtype = u'B'
|
verse_type = u'B'
|
||||||
else:
|
else:
|
||||||
vtype = u'O'
|
verse_type = u'O'
|
||||||
vnumber = parts[1]
|
verse_number = verse_desc_parts[1]
|
||||||
else:
|
else:
|
||||||
vtype = u'O'
|
verse_type = u'O'
|
||||||
vnumber = 1
|
verse_number = 1
|
||||||
verse_start = True
|
verse_start = True
|
||||||
else:
|
else:
|
||||||
# We have verse content or the start of the
|
# We have verse content or the start of the
|
||||||
# last part. Add l so as to keep the CRLF
|
# last part. Add l so as to keep the CRLF
|
||||||
vcontent = vcontent + line
|
verse_text = verse_text + line
|
||||||
else:
|
else:
|
||||||
#lnum=2, copyright
|
#line_number=2, copyright
|
||||||
if (lnum==2):
|
if line_number==2:
|
||||||
lnum += 1
|
line_number += 1
|
||||||
scopyright = line
|
song_copyright = clean_line
|
||||||
#n=3, authors
|
#n=3, authors
|
||||||
elif (lnum==3):
|
elif line_number==3:
|
||||||
lnum += 1
|
line_number += 1
|
||||||
sauthor = line
|
song_author = clean_line
|
||||||
#lnum=4, comments lines before last line
|
#line_number=4, comments lines before last line
|
||||||
elif (lnum==4) and (not line.startswith(u'CCL')):
|
elif (line_number==4) and (not clean_line.startswith(u'CCL')):
|
||||||
scomments = scomments + line
|
song_comments = song_comments + clean_line
|
||||||
# split on known separators
|
# split on known separators
|
||||||
alist = sauthor.split(u'/')
|
author_list = song_author.split(u'/')
|
||||||
if len(alist) < 2:
|
if len(author_list) < 2:
|
||||||
alist = sauthor.split(u'|')
|
author_list = song_author.split(u'|')
|
||||||
new_song.authors = alist
|
#Clean spaces before and after author names
|
||||||
new_song.title = sname
|
for author_name in author_list:
|
||||||
new_song.copyright = scopyright
|
self.add_author(author_name.strip())
|
||||||
new_song.ccli_number = sccli
|
self.title = song_name
|
||||||
new_song.comments = scomments
|
self.copyright = song_copyright
|
||||||
new_song.finish()
|
self.ccli_number = song_ccli
|
||||||
|
self.comments = song_comments
|
||||||
|
self.finish()
|
||||||
|
|
||||||
|
@ -52,6 +52,11 @@ class SongImport(QtCore.QObject):
|
|||||||
"""
|
"""
|
||||||
self.manager = manager
|
self.manager = manager
|
||||||
self.stop_import_flag = False
|
self.stop_import_flag = False
|
||||||
|
self.set_defaults()
|
||||||
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||||
|
QtCore.SIGNAL(u'songs_stop_import'), self.stop_import)
|
||||||
|
|
||||||
|
def set_defaults(self):
|
||||||
self.title = u''
|
self.title = u''
|
||||||
self.song_number = u''
|
self.song_number = u''
|
||||||
self.alternate_title = u''
|
self.alternate_title = u''
|
||||||
@ -71,8 +76,6 @@ class SongImport(QtCore.QObject):
|
|||||||
'SongsPlugin.SongImport', 'copyright'))
|
'SongsPlugin.SongImport', 'copyright'))
|
||||||
self.copyright_symbol = unicode(translate(
|
self.copyright_symbol = unicode(translate(
|
||||||
'SongsPlugin.SongImport', '\xa9'))
|
'SongsPlugin.SongImport', '\xa9'))
|
||||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
||||||
QtCore.SIGNAL(u'songs_stop_import'), self.stop_import)
|
|
||||||
|
|
||||||
def stop_import(self):
|
def stop_import(self):
|
||||||
"""
|
"""
|
||||||
@ -158,8 +161,7 @@ class SongImport(QtCore.QObject):
|
|||||||
def parse_author(self, text):
|
def parse_author(self, text):
|
||||||
"""
|
"""
|
||||||
Add the author. OpenLP stores them individually so split by 'and', '&'
|
Add the author. OpenLP stores them individually so split by 'and', '&'
|
||||||
and comma.
|
and comma. However need to check for 'Mr and Mrs Smith' and turn it to
|
||||||
However need to check for 'Mr and Mrs Smith' and turn it to
|
|
||||||
'Mr Smith' and 'Mrs Smith'.
|
'Mr Smith' and 'Mrs Smith'.
|
||||||
"""
|
"""
|
||||||
for author in text.split(u','):
|
for author in text.split(u','):
|
||||||
@ -236,7 +238,7 @@ class SongImport(QtCore.QObject):
|
|||||||
"""
|
"""
|
||||||
All fields have been set to this song. Write it away
|
All fields have been set to this song. Write it away
|
||||||
"""
|
"""
|
||||||
if len(self.authors) == 0:
|
if not self.authors:
|
||||||
self.authors.append(u'Author unknown')
|
self.authors.append(u'Author unknown')
|
||||||
self.commit_song()
|
self.commit_song()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user