Unicode chars in my testcase work OK

This commit is contained in:
Martin Thompson 2010-06-25 19:20:45 +01:00
parent 76e3538127
commit baec9d5c2f
3 changed files with 18 additions and 13 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<song> <song>
<title>Martins Test</title> <title>Martins Test</title>
<author>Martin Thompson</author> <author>MartiÑ Thómpson</author>
<copyright>2010 Martin Thompson</copyright> <copyright>2010 Martin Thompson</copyright>
<hymn_number>1</hymn_number> <hymn_number>1</hymn_number>
<presentation>V1 C V2 C2 V3 B1 V1</presentation> <presentation>V1 C V2 C2 V3 B1 V1</presentation>

View File

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

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from openlp.plugins.songs.lib.opensongimport import OpenSongImport from openlp.plugins.songs.lib.opensongimport import OpenSongImport
from openlp.plugins.songs.lib.manager import SongManager from openlp.plugins.songs.lib.manager import SongManager
@ -8,7 +9,7 @@ def test():
# o.finish() # o.finish()
o.song.print_song() o.song.print_song()
assert o.song.copyright == u'2010 Martin Thompson' assert o.song.copyright == u'2010 Martin Thompson'
assert o.song.authors == [u'Martin Thompson'] assert o.song.authors == [u'MartiÑ Thómpson']
assert o.song.title == u'Martins Test' assert o.song.title == u'Martins Test'
assert o.song.alternate_title == u'' assert o.song.alternate_title == u''
assert o.song.song_number == u'1' assert o.song.song_number == u'1'