Imports all of SOF and the opensong default songs without crashing

This commit is contained in:
Martin Thompson 2010-06-24 21:13:32 +01:00
parent f7b8095f68
commit 76e3538127
2 changed files with 94 additions and 0 deletions

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<song>
<title>Martins 2nd Test</title>
<author>Martin Thompson</author>
<copyright>2010 Martin Thompson</copyright>
<hymn_number>2</hymn_number>
<presentation></presentation>
<ccli>Blah</ccli>
<capo print="false"></capo>
<key></key>
<aka></aka>
<key_line></key_line>
<user1></user1>
<user2></user2>
<user3></user3>
<theme></theme>
<tempo></tempo>
<time_sig></time_sig>
<lyrics>;Comment
[V]
. A B C
1 v1 Line 1___
2 v2 Line 1___
. A B C7
1 V1 Line 2
2 V2 Line 2
[b1]
Bridge 1
Bridge 1 line 2
[C1]
Chorus 1
[C2]
Chorus 2
</lyrics>
<style index="default_style">
<title enabled="true" valign="bottom" align="center" include_verse="false" margin-left="0" margin-right="0" margin-top="0" margin-bottom="0" font="Helvetica" size="26" bold="true" italic="true" underline="false" color="#FFFFFF" border="true" border_color="#000000" shadow="true" shadow_color="#000000" fill="false" fill_color="#000000"/>
<subtitle enabled="true" valign="bottom" align="center" descriptive="false" margin-left="0" margin-right="0" margin-top="0" margin-bottom="0" font="Helvetica" size="18" bold="true" italic="true" underline="false" color="#FFFFFF" border="true" border_color="#000000" shadow="true" shadow_color="#000000" fill="false" fill_color="#000000"/>
<song_subtitle>author</song_subtitle>
<body enabled="true" auto_scale="false" valign="middle" align="center" highlight_chorus="true" margin-left="0" margin-right="0" margin-top="0" margin-bottom="0" font="Helvetica" size="34" bold="true" italic="false" underline="false" color="#FFFFFF" border="true" border_color="#000000" shadow="true" shadow_color="#000000" fill="false" fill_color="#FF0000">
<tabs/>
</body>
<background strip_footer="0" color="#408080" position="1"/>
</style></song>

View File

@ -0,0 +1,49 @@
from openlp.plugins.songs.lib.opensongimport import OpenSongImport
from openlp.plugins.songs.lib.manager import SongManager
from glob import glob
from zipfile import ZipFile
import os
from traceback import print_exc
import sys
import codecs
def opensong_import_lots():
ziploc=u'/home/mjt/openlp/OpenSong_Data/'
files=[]
files.extend(glob(ziploc+u'Songs.zip'))
files.extend(glob(ziploc+u'SOF.zip'))
# files.extend(glob(ziploc+u'spanish_songs_for_opensong.zip'))
# files.extend(glob(ziploc+u'opensong_*.zip'))
errfile=codecs.open(u'import_lots_errors.txt', u'w', u'utf8')
manager=SongManager()
for file in files:
print u'Importing', file
z=ZipFile(file, u'r')
for song in z.infolist():
filename=song.filename.decode('cp852')
parts=os.path.split(filename)
if parts[-1] == u'':
#No final part => directory
continue
# xxx need to handle unicode filenames (CP437?? Winzip does this)
print " ", file, ":",filename,
songfile=z.open(song)
o=OpenSongImport(manager)
try:
o.do_import_file(songfile)
except:
print "Failure",
errfile.write(u'Failure: %s:%s\n' %(file, filename))
songfile=z.open(song)
for l in songfile.readlines():
l=l.decode('utf8')
print(u' |%s\n'%l.strip())
errfile.write(u' |%s\n'%l.strip())
print_exc(3, file=errfile)
continue
# o.finish()
print "OK"
# o.song.print_song()
if __name__=="__main__":
opensong_import_lots()