Mongo -> SQL conversion tool: UI improvements
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Mon, 2 Apr 2012 10:58:29 +0000 (12:58 +0200)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Mon, 2 Apr 2012 11:51:52 +0000 (13:51 +0200)
Output some headers while converting things.
And indent some info.
Also some DRY things.

mediagoblin/db/sql/convert.py

index ec308f6cd2964deea7f68ac6752d4b7c34384121..2589d94319ded919be0e1f2b99e40c71d642100a 100644 (file)
@@ -34,7 +34,7 @@ obj_id_table = dict()
 
 def add_obj_ids(entry, new_entry):
     global obj_id_table
-    print "%r -> %r" % (entry._id, new_entry.id)
+    print "\t%r -> SQL id %r" % (entry._id, new_entry.id)
     obj_id_table[entry._id] = new_entry.id
 
 
@@ -198,13 +198,30 @@ def convert_add_migration_versions():
                  "mediagoblin.media_types.image",
                  "mediagoblin.media_types.video",
                  ):
-        m = MigrationData(name=name, version=0)
+        m = MigrationData(name=unicode(name), version=0)
         session.add(m)
 
     session.commit()
     session.close()
 
 
+def print_header(title):
+    print "\n=== %s ===" % (title,)
+
+
+convert_call_list = (
+    ("Converting Users", convert_users),
+    ("Converting Media Entries", convert_media_entries),
+    ("Converting Media Data for Images", convert_image),
+    ("Cnnverting Media Data for Videos", convert_video),
+    ("Converting Tags for Media", convert_media_tags),
+    ("Converting Media Comments", convert_media_comments),
+    )
+
+sql_call_list = (
+    ("Filling Migration Tables", convert_add_migration_versions),
+    )
+
 def run_conversion(config_name):
     global_config, app_config = setup_global_and_app_config(config_name)
 
@@ -213,20 +230,15 @@ def run_conversion(config_name):
 
     Base_v0.metadata.create_all(sql_db.engine)
 
-    convert_users(mk_db)
-    Session.remove()
-    convert_media_entries(mk_db)
-    Session.remove()
-    convert_image(mk_db)
-    Session.remove()
-    convert_video(mk_db)
-    Session.remove()
-    convert_media_tags(mk_db)
-    Session.remove()
-    convert_media_comments(mk_db)
-    Session.remove()
-    convert_add_migration_versions()
-    Session.remove()
+    for title, func in convert_call_list:
+        print_header(title)
+        func(mk_db)
+        Session.remove()
+    
+    for title, func in sql_call_list:
+        print_header(title)
+        func()
+        Session.remove()
 
 
 if __name__ == '__main__':