1 #! /usr/bin/env python -u
3 # This file is part of DisOrder.
4 # Copyright (C) 2008 Richard Kettlewell
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 import dtest
,disorder
,sys
,os
,unicodedata
23 def recode(name
, f
, t
):
25 # First recode basename
26 d
= os
.path
.dirname(name
)
27 b
= os
.path
.basename(name
)
28 nb
= unicodedata
.normalize("NFC", unicode(b
, f
)).encode(t
)
30 print " %s -> %s" %
(repr(b
), repr(nb
))
31 name
= os
.path
.join(d
, nb
)
32 os
.rename(os
.path
.join(d
, b
), name
)
34 # Recurse into directories
35 if os
.path
.isdir(name
):
36 for c
in os
.listdir(name
):
37 recoded
+= recode(os
.path
.join(name
, c
), f
, t
)
41 """Test encoding conversion"""
42 if sys
.platform
== "darwin":
43 print "Sorry, cannot run this test on Darwin"
44 # ...because local fs is always UTF-8
51 print " recoding as ISO-8859-1"
52 recoded
= recode(dtest
.tracks
, "UTF-8", "ISO-8859-1")
53 print " ...recoded %d filenames" % recoded
54 print " regenerating config"
55 dtest
.default_config(encoding
="ISO-8859-1")
56 print " checking recoded files"
61 print " recoding as UTF-8"
62 recoded
= recode(dtest
.tracks
, "ISO-8859-1", "UTF-8")
63 print " ...recoded %d filenames" % recoded
64 print " regenerating config"
65 dtest
.default_config(encoding
="UTF-8")
66 print " checking recoded files"
72 if __name__
== '__main__':