2 """%prog [options] [changes.pck] old_encoding
4 Re-encodes changes in a pickle file to UTF-8 from the given encoding
7 if __name__
== '__main__':
9 from cPickle
import load
, dump
10 from optparse
import OptionParser
12 parser
= OptionParser(__doc__
)
14 options
, args
= parser
.parse_args()
17 changes_file
= args
[0]
18 old_encoding
= args
[1]
20 changes_file
= "changes.pck"
21 old_encoding
= args
[0]
23 parser
.error("Need at least one argument")
25 print "opening %s" % (changes_file
,)
27 fp
= open(changes_file
)
29 parser
.error("Couldn't open %s: %s" % (changes_file
, str(e
)))
34 print "decoding bytestrings in %s using %s" % (changes_file
, old_encoding
)
35 changemgr
.recode_changes(old_encoding
)
37 changes_backup
= changes_file
+ ".old"
39 while os
.path
.exists(changes_backup
):
41 changes_backup
= changes_file
+ ".old.%i" % i
42 print "backing up %s to %s" % (changes_file
, changes_backup
)
43 os
.rename(changes_file
, changes_backup
)
45 dump(changemgr
, open(changes_file
, "w"))