aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/gmg_commands
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/gmg_commands')
-rw-r--r--mediagoblin/gmg_commands/__init__.py29
-rw-r--r--mediagoblin/gmg_commands/dbupdate.py11
-rw-r--r--mediagoblin/gmg_commands/import_export.py8
-rw-r--r--mediagoblin/gmg_commands/migrate.py11
-rw-r--r--mediagoblin/gmg_commands/wipealldata.py55
5 files changed, 32 insertions, 82 deletions
diff --git a/mediagoblin/gmg_commands/__init__.py b/mediagoblin/gmg_commands/__init__.py
index 054e2616..4a608a69 100644
--- a/mediagoblin/gmg_commands/__init__.py
+++ b/mediagoblin/gmg_commands/__init__.py
@@ -28,7 +28,8 @@ SUBCOMMAND_MAP = {
'migrate': {
'setup': 'mediagoblin.gmg_commands.migrate:migrate_parser_setup',
'func': 'mediagoblin.gmg_commands.migrate:migrate',
- 'help': 'Apply all unapplied bulk migrations to the database'},
+ 'help': ('Migrate your Mongo database. '
+ '[DEPRECATED!] use convert_mongo_to_sql and dbupdate.')},
'adduser': {
'setup': 'mediagoblin.gmg_commands.users:adduser_parser_setup',
'func': 'mediagoblin.gmg_commands.users:adduser',
@@ -41,18 +42,6 @@ SUBCOMMAND_MAP = {
'setup': 'mediagoblin.gmg_commands.users:changepw_parser_setup',
'func': 'mediagoblin.gmg_commands.users:changepw',
'help': 'Makes admin an user'},
- 'wipealldata': {
- 'setup': 'mediagoblin.gmg_commands.wipealldata:wipe_parser_setup',
- 'func': 'mediagoblin.gmg_commands.wipealldata:wipe',
- 'help': 'Wipes **all** the data for this MediaGoblin instance'},
- 'env_export': {
- 'setup': 'mediagoblin.gmg_commands.import_export:import_export_parse_setup',
- 'func': 'mediagoblin.gmg_commands.import_export:env_export',
- 'help': 'Exports the data for this MediaGoblin instance'},
- 'env_import': {
- 'setup': 'mediagoblin.gmg_commands.import_export:import_export_parse_setup',
- 'func': 'mediagoblin.gmg_commands.import_export:env_import',
- 'help': 'Exports the data for this MediaGoblin instance'},
'dbupdate': {
'setup': 'mediagoblin.gmg_commands.dbupdate:dbupdate_parse_setup',
'func': 'mediagoblin.gmg_commands.dbupdate:dbupdate',
@@ -61,6 +50,20 @@ SUBCOMMAND_MAP = {
'setup': 'mediagoblin.gmg_commands.mongosql:mongosql_parser_setup',
'func': 'mediagoblin.gmg_commands.mongosql:mongosql',
'help': 'Convert Mongo DB data to SQL DB data'},
+
+ ## These might be useful, mayyyybe, but don't really work anymore
+ ## due to mongo change and the "versatility" of sql options.
+ ##
+ ## For now, commenting out. Might re-enable soonish?
+ #
+ # 'env_export': {
+ # 'setup': 'mediagoblin.gmg_commands.import_export:import_export_parse_setup',
+ # 'func': 'mediagoblin.gmg_commands.import_export:env_export',
+ # 'help': 'Exports the data for this MediaGoblin instance'},
+ # 'env_import': {
+ # 'setup': 'mediagoblin.gmg_commands.import_export:import_export_parse_setup',
+ # 'func': 'mediagoblin.gmg_commands.import_export:env_import',
+ # 'help': 'Imports the data for this MediaGoblin instance'},
}
diff --git a/mediagoblin/gmg_commands/dbupdate.py b/mediagoblin/gmg_commands/dbupdate.py
index 27698170..dc36be82 100644
--- a/mediagoblin/gmg_commands/dbupdate.py
+++ b/mediagoblin/gmg_commands/dbupdate.py
@@ -17,8 +17,7 @@
from sqlalchemy.orm import sessionmaker
from mediagoblin.db.sql.open import setup_connection_and_db_from_config
-from mediagoblin.db.sql.util import (
- MigrationManager, assure_migrations_table_setup)
+from mediagoblin.db.sql.util import MigrationManager
from mediagoblin.init import setup_global_and_app_config
from mediagoblin.tools.common import import_component
@@ -65,14 +64,13 @@ def gather_database_data(media_types):
return managed_dbdata
-def dbupdate(args):
+def run_dbupdate(app_config):
"""
Initialize or migrate the database as specified by the config file.
Will also initialize or migrate all extensions (media types, and
in the future, plugins)
"""
- globa_config, app_config = setup_global_and_app_config(args.conf_file)
# Gather information from all media managers / projects
dbdatas = gather_database_data(app_config['media_types'])
@@ -87,3 +85,8 @@ def dbupdate(args):
for dbdata in dbdatas:
migration_manager = dbdata.make_migration_manager(Session())
migration_manager.init_or_migrate()
+
+
+def dbupdate(args):
+ global_config, app_config = setup_global_and_app_config(args.conf_file)
+ run_dbupdate(app_config)
diff --git a/mediagoblin/gmg_commands/import_export.py b/mediagoblin/gmg_commands/import_export.py
index 20cc8fe4..72ebd8a8 100644
--- a/mediagoblin/gmg_commands/import_export.py
+++ b/mediagoblin/gmg_commands/import_export.py
@@ -61,13 +61,12 @@ def _import_media(db, args):
args._cache_path['media'])
# TODO: Add import of queue files
- queue_cache = BasicFileStorage(
- args._cache_path['queue'])
+ queue_cache = BasicFileStorage(args._cache_path['queue'])
for entry in db.MediaEntry.find():
for name, path in entry.media_files.items():
_log.info('Importing: {0} - {1}'.format(
- entry.title,
+ entry.title.encode('ascii', 'replace'),
name))
media_file = mg_globals.public_store.get_file(path, mode='wb')
@@ -203,8 +202,7 @@ def _export_media(db, args):
args._cache_path['media'])
# TODO: Add export of queue files
- queue_cache = BasicFileStorage(
- args._cache_path['queue'])
+ queue_cache = BasicFileStorage(args._cache_path['queue'])
for entry in db.MediaEntry.find():
for name, path in entry.media_files.items():
diff --git a/mediagoblin/gmg_commands/migrate.py b/mediagoblin/gmg_commands/migrate.py
index af541786..b915a528 100644
--- a/mediagoblin/gmg_commands/migrate.py
+++ b/mediagoblin/gmg_commands/migrate.py
@@ -16,13 +16,8 @@
import sys
-from mediagoblin.db.mongo import util as db_util
-from mediagoblin.db.mongo.open import setup_connection_and_db_from_config
from mediagoblin.init import setup_global_and_app_config
-# This MUST be imported so as to set up the appropriate migrations!
-from mediagoblin.db.mongo import migrations
-
def migrate_parser_setup(subparser):
pass
@@ -45,6 +40,12 @@ def migrate(args):
def run_migrate(conf_file):
+ # This MUST be imported so as to set up the appropriate migrations!
+ from mediagoblin.db.mongo import migrations
+
+ from mediagoblin.db.mongo import util as db_util
+ from mediagoblin.db.mongo.open import setup_connection_and_db_from_config
+
global_config, app_config = setup_global_and_app_config(conf_file)
connection, db = setup_connection_and_db_from_config(
diff --git a/mediagoblin/gmg_commands/wipealldata.py b/mediagoblin/gmg_commands/wipealldata.py
deleted file mode 100644
index 3081bbc0..00000000
--- a/mediagoblin/gmg_commands/wipealldata.py
+++ /dev/null
@@ -1,55 +0,0 @@
-# GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-import sys
-import pymongo
-import sys
-import os
-import shutil
-
-
-def wipe_parser_setup(subparser):
- pass
-
-
-def wipe(args):
- print "*** WARNING! ***"
- print ""
- print "Running this will destroy your mediagoblin database,"
- print "remove all your media files in user_dev/, etc."
- print ""
- print "ALSO: This command is currently a hack and will only remove"
- print " things properly on the default setup! If you've customized"
- print " your mediagoblin configs, it won't work (for now)."
-
- drop_it = raw_input(
- 'Are you **SURE** you want to destroy your environment? '
- '(if so, type "yes")> ')
-
- if not drop_it == 'yes':
- return
-
- print "nixing data in mongodb...."
- conn = pymongo.Connection()
- conn.drop_database('mediagoblin')
-
- for directory in [os.path.join(os.getcwd(), "user_dev", "media"),
- os.path.join(os.getcwd(), "user_dev", "beaker")]:
- if os.path.exists(directory):
- print "nixing %s...." % directory
- shutil.rmtree(directory)
-
- print "removed all your stuff!"