Allow specifying a non-utf8 encoding.
authorMiklos Vajna <vmiklos@frugalware.org>
Fri, 17 Oct 2008 19:30:28 +0000 (17 21:30 +0200)
committerMiklos Vajna <vmiklos@frugalware.org>
Fri, 17 Oct 2008 19:30:28 +0000 (17 21:30 +0200)
Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
darcs2git.py

index a3e8f6f..cbcd784 100755 (executable)
@@ -145,6 +145,12 @@ This program comes with NO WARRANTY.
 don\'t clean conversion repo;
 test end result.""")
 
+    p.add_option ('-e', '--encoding', action='store',
+                  type='string',
+                 default='UTF-8',
+                  nargs=1,
+                  help='specify encoding, for example ISO-8859-2')
+
     global options
     options, args = p.parse_args ()
     if not args:
@@ -280,7 +286,7 @@ class InventoryPatch:
         if self.inverted:
             inv = '-'
         
-        return unicode('%s%s*%s%s' % (self.name, self.author, inv, self.hash.split ('-')[0]), 'UTF-8')
+        return unicode('%s%s*%s%s' % (self.name, self.author, inv, self.hash.split ('-')[0]), options.encoding)
     
     @property 
     def hash(self):
@@ -592,7 +598,7 @@ class DarcsPatch:
         patch_name = ''
         try:
             name_elt = self.xml.getElementsByTagName ('name')[0]
-            patch_name = unicode(fix_braindead_darcs_escapes(str(name_elt.childNodes[0].data)), 'UTF-8')
+            patch_name = unicode(fix_braindead_darcs_escapes(str(name_elt.childNodes[0].data)), options.encoding)
         except IndexError:
             pass
         return patch_name