From 9188f3afe24a52fff3262360a0896cc521546fa8 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Mon, 8 Aug 2011 03:47:17 +0200 Subject: [PATCH] Feature #298 - Changed some defaults in gmg_commands.import_export --- mediagoblin/gmg_commands/import_export.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/mediagoblin/gmg_commands/import_export.py b/mediagoblin/gmg_commands/import_export.py index aa3fe1a1..c05a48d9 100644 --- a/mediagoblin/gmg_commands/import_export.py +++ b/mediagoblin/gmg_commands/import_export.py @@ -19,6 +19,7 @@ from mediagoblin import mg_globals from mediagoblin.db import util as db_util from mediagoblin.db.open import setup_connection_and_db_from_config from mediagoblin.init.config import read_mediagoblin_config +from mediagoblin import util as mg_util import shlex import tarfile @@ -33,7 +34,7 @@ def import_export_parse_setup(subparser): '-cf', '--conf_file', default='mediagoblin.ini', help='Config file used to set up environment') subparser.add_argument( - '--mongodump_cache', default='mongodump', + '--mongodump_cache', default='/tmp/mediagoblin/mongodump', help='mongodump cache directory') subparser.add_argument( '--mongodump_path', default='mongodump', @@ -42,12 +43,15 @@ def import_export_parse_setup(subparser): '--mongorestore_path', default='mongorestore', help='mongorestore binary') subparser.add_argument( - '--extract_path', default='/tmp/mediagoblin-import', + '--extract_path', default='/tmp/mediagoblin/import', help='the directory to which the tarball should be extracted temporarily') + subparser.add_argument( + '--media_cache_path', default='/tmp/mediagoblin/mediaentries', + help='') def _export_database(db, args): print "\n== Exporting database ==\n" - + command = '{mongodump_path} -d {database} -o {mongodump_cache}'.format( mongodump_path=args.mongodump_path, database=db.name, @@ -60,6 +64,13 @@ def _export_database(db, args): print "\n== Database exported ==\n" +def _export_media(db, args): + for entry in db.media_entries.find(): + storage = mg_util.import_component( + 'mediagoblin.storage:BasicFileStorage')() + print(storage.get_file(entry['media_files']['medium'])) + print(entry) + def _import_database(db, args): command = '{mongorestore_path} -d {database} -o {mongodump_cache}'.format( mongorestore_path=args.mongorestore_path, @@ -74,7 +85,7 @@ def env_import(args): tf = tarfile.open( args.tar_file, mode='r|gz') - + tf.extractall(args.extract_path) def env_export(args): @@ -91,6 +102,8 @@ def env_export(args): print "Aborting." return + _export_media(db, args) + tf = tarfile.open( args.tar_file, mode='w|gz') -- 2.25.1