Switch to side-by-side view

--- a/migrate-3rdparty/allura_import.py
+++ b/migrate-3rdparty/allura_import.py
@@ -20,7 +20,7 @@
     optparser.add_option('-t', '--tracker', dest='tracker', help='Tracker to import to')
     optparser.add_option('-u', '--base-url', dest='base_url', default='https://sourceforge.net', help='Base Allura URL (%default)')
     optparser.add_option('-o', dest='import_opts', default=[], action='append', help='Specify import option(s)', metavar='opt=val')
-    optparser.add_option('-m', dest='user_map', default=[], action='append', help='Map users', metavar='import_user=allura_user')
+    optparser.add_option('--user-map', dest='user_map_file', help='Map original users to SF.net users', metavar='JSON_FILE')
     optparser.add_option('--validate', dest='validate', action='store_true', help='Validate import data')
     optparser.add_option('-v', '--verbose', dest='verbose', action='store_true', help='Verbose operation')
     options, args = optparser.parse_args()
@@ -30,7 +30,7 @@
         optparser.error("Keys are required")
     if not options.project or not options.tracker:
         optparser.error("Target project and tracker are required")
-    return options, args
+    return optparser, options, args
 
 
 class AlluraRestClient(object):
@@ -63,7 +63,7 @@
 
     
 if __name__ == '__main__':
-    options, args = parse_options()
+    optparser, options, args = parse_options()
     url = '/rest/p/' + options.project + '/' + options.tracker
     if options.validate:
         url += '/validate_import'
@@ -76,11 +76,24 @@
         if v == 'false':
             v = False
         import_options[k] = v
-        
-    import_options['user_map'] = {}
-    for s in options.user_map:
-        k, v = s.split('=', 1)
-        import_options['user_map'][k] = v
+
+    user_map = {}
+    if options.user_map_file:
+        f = open(options.user_map_file)
+        try:
+            user_map = json.load(f)
+            if type(user_map) is not type({}):
+                raise ValueError
+            for k, v in user_map.iteritems():
+                print k, v
+                if not isinstance(k, basestring) or not isinstance(v, basestring):
+                    raise ValueError
+        except ValueError:
+            optparser.error('--user-map should specify JSON file with format {"original_user": "sf_user", ...}')
+        finally:
+            f.close()
+
+    import_options['user_map'] = user_map
 
     cli = AlluraRestClient(options.base_url, options.api_key, options.secret_key)
     print cli.call(url, doc=open(args[0]).read(), options=json.dumps(import_options))