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 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU 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, see <http://www.gnu.org/licenses/>.
19 import dtest
,disorder
,sys
,os
,unicodedata
21 def recode(name
, f
, t
):
23 # First recode basename
24 d
= os
.path
.dirname(name
)
25 b
= os
.path
.basename(name
)
26 nb
= unicodedata
.normalize("NFC", unicode(b
, f
)).encode(t
)
28 print " %s -> %s" %
(repr(b
), repr(nb
))
29 name
= os
.path
.join(d
, nb
)
30 os
.rename(os
.path
.join(d
, b
), name
)
32 # Recurse into directories
33 if os
.path
.isdir(name
):
34 for c
in os
.listdir(name
):
35 recoded
+= recode(os
.path
.join(name
, c
), f
, t
)
39 """Test encoding conversion"""
40 if sys
.platform
== "darwin":
41 print "Sorry, cannot run this test on Darwin"
42 # ...because local fs is always UTF-8
49 print " recoding as ISO-8859-1"
50 recoded
= recode(dtest
.tracks
, "UTF-8", "ISO-8859-1")
51 print " ...recoded %d filenames" % recoded
52 print " regenerating config"
53 dtest
.default_config(encoding
="ISO-8859-1")
54 print " checking recoded files"
59 print " recoding as UTF-8"
60 recoded
= recode(dtest
.tracks
, "ISO-8859-1", "UTF-8")
61 print " ...recoded %d filenames" % recoded
62 print " regenerating config"
63 dtest
.default_config(encoding
="UTF-8")
64 print " checking recoded files"
70 if __name__
== '__main__':