Feature #298
authorJoar Wandborg <git@wandborg.com>
Sun, 7 Aug 2011 03:00:46 +0000 (05:00 +0200)
committerJoar Wandborg <git@wandborg.com>
Sun, 7 Aug 2011 03:00:46 +0000 (05:00 +0200)
*   Added some minor things to gmg_commands.import_export

mediagoblin/gmg_commands/import_export.py

index c0ac444becf8c4d6e95abc554d5a248a103202d7..aa3fe1a1863b68904e874418e1596e831c95efb3 100644 (file)
@@ -38,6 +38,12 @@ def import_export_parse_setup(subparser):
     subparser.add_argument(
         '--mongodump_path', default='mongodump',
         help='mongodump binary')
+    subparser.add_argument(
+        '--mongorestore_path', default='mongorestore',
+        help='mongorestore binary')
+    subparser.add_argument(
+        '--extract_path', default='/tmp/mediagoblin-import',
+        help='the directory to which the tarball should be extracted temporarily')
 
 def _export_database(db, args):
     print "\n== Exporting database ==\n"
@@ -55,13 +61,22 @@ def _export_database(db, args):
     print "\n== Database exported ==\n"
 
 def _import_database(db, args):
-    pass
+    command = '{mongorestore_path} -d {database} -o {mongodump_cache}'.format(
+        mongorestore_path=args.mongorestore_path,
+        database=db.name,
+        mongodump_cache=args.mongodump_cache)
 
 def env_import(args):    
     config, validation_result = read_mediagoblin_config(args.conf_file)
     connection, db = setup_connection_and_db_from_config(
         config['mediagoblin'], use_pymongo=True)
 
+    tf = tarfile.open(
+        args.tar_file,
+        mode='r|gz')
+    
+    tf.extractall(args.extract_path)
+
 def env_export(args):
     config, validation_result = read_mediagoblin_config(args.conf_file)
     connection, db = setup_connection_and_db_from_config(