From baec9d5c2f2591ff835ca8768663dc02478ac204 Mon Sep 17 00:00:00 2001 From: Martin Thompson Date: Fri, 25 Jun 2010 19:20:45 +0100 Subject: [PATCH] Unicode chars in my testcase work OK --- openlp/plugins/songs/lib/test.opensong | 6 ++--- .../plugins/songs/lib/test_importing_lots.py | 22 +++++++++++-------- .../plugins/songs/lib/test_opensongimport.py | 3 ++- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/openlp/plugins/songs/lib/test.opensong b/openlp/plugins/songs/lib/test.opensong index 8533e8943..af0f039ed 100644 --- a/openlp/plugins/songs/lib/test.opensong +++ b/openlp/plugins/songs/lib/test.opensong @@ -1,7 +1,7 @@ Martins Test - Martin Thompson + MartiÑ Thómpson 2010 Martin Thompson 1 V1 C V2 C2 V3 B1 V1 @@ -25,8 +25,8 @@ 2 V2 Line 2 [3] -V3 Line 1 -V3 Line 2 + V3 Line 1 + V3 Line 2 [b1] Bridge 1 diff --git a/openlp/plugins/songs/lib/test_importing_lots.py b/openlp/plugins/songs/lib/test_importing_lots.py index 7543de60e..5161f4a30 100644 --- a/openlp/plugins/songs/lib/test_importing_lots.py +++ b/openlp/plugins/songs/lib/test_importing_lots.py @@ -9,9 +9,9 @@ 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'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() @@ -19,31 +19,35 @@ def opensong_import_lots(): print u'Importing', file z=ZipFile(file, u'r') 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) 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) - + # songfile=z.open(song) + z.extract(song) + songfile=open(filename, u'r') o=OpenSongImport(manager) try: o.do_import_file(songfile) except: 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) 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 + print_exc(3) + sys.exit(1) + # continue # o.finish() print "OK" + os.unlink(filename) # o.song.print_song() if __name__=="__main__": opensong_import_lots() diff --git a/openlp/plugins/songs/lib/test_opensongimport.py b/openlp/plugins/songs/lib/test_opensongimport.py index 40b09a23b..6291f7106 100644 --- a/openlp/plugins/songs/lib/test_opensongimport.py +++ b/openlp/plugins/songs/lib/test_opensongimport.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from openlp.plugins.songs.lib.opensongimport import OpenSongImport from openlp.plugins.songs.lib.manager import SongManager @@ -8,7 +9,7 @@ def test(): # o.finish() o.song.print_song() 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.alternate_title == u'' assert o.song.song_number == u'1'