Make filestorage available to code that only imports storage.
[mediagoblin.git] / mediagoblin / gmg_commands / __init__.py
CommitLineData
029cad45 1# GNU MediaGoblin -- federated, autonomous media hosting
cf29e8a8 2# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
029cad45
CAW
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
029cad45 17import argparse
9d0a613b 18import os
029cad45 19
b43b17fc 20from mediagoblin.tools.common import import_component
029cad45
CAW
21
22
23SUBCOMMAND_MAP = {
24 'shell': {
dbb92c60
CAW
25 'setup': 'mediagoblin.gmg_commands.shell:shell_parser_setup',
26 'func': 'mediagoblin.gmg_commands.shell:shell',
029cad45 27 'help': 'Run a shell with some tools pre-setup'},
757f37a5
CAW
28 'migrate': {
29 'setup': 'mediagoblin.gmg_commands.migrate:migrate_parser_setup',
30 'func': 'mediagoblin.gmg_commands.migrate:migrate',
088644a8
CAW
31 'help': ('Migrate your Mongo database. '
32 '[DEPRECATED!] use convert_mongo_to_sql and dbupdate.')},
243c3843 33 'adduser': {
96108ea2
AV
34 'setup': 'mediagoblin.gmg_commands.users:adduser_parser_setup',
35 'func': 'mediagoblin.gmg_commands.users:adduser',
7f4b4471 36 'help': 'Creates an user'},
96108ea2
AV
37 'makeadmin': {
38 'setup': 'mediagoblin.gmg_commands.users:makeadmin_parser_setup',
39 'func': 'mediagoblin.gmg_commands.users:makeadmin',
7f4b4471 40 'help': 'Changes a user\'s password'},
96108ea2
AV
41 'changepw': {
42 'setup': 'mediagoblin.gmg_commands.users:changepw_parser_setup',
43 'func': 'mediagoblin.gmg_commands.users:changepw',
7f4b4471 44 'help': 'Makes admin an user'},
3ea1cf36
CAW
45 'dbupdate': {
46 'setup': 'mediagoblin.gmg_commands.dbupdate:dbupdate_parse_setup',
47 'func': 'mediagoblin.gmg_commands.dbupdate:dbupdate',
48 'help': 'Set up or update the SQL database'},
98913512
E
49 'convert_mongo_to_sql': {
50 'setup': 'mediagoblin.gmg_commands.mongosql:mongosql_parser_setup',
51 'func': 'mediagoblin.gmg_commands.mongosql:mongosql',
52 'help': 'Convert Mongo DB data to SQL DB data'},
63578ee3
CAW
53
54 ## These might be useful, mayyyybe, but don't really work anymore
55 ## due to mongo change and the "versatility" of sql options.
56 ##
57 ## For now, commenting out. Might re-enable soonish?
58 #
59 # 'env_export': {
60 # 'setup': 'mediagoblin.gmg_commands.import_export:import_export_parse_setup',
61 # 'func': 'mediagoblin.gmg_commands.import_export:env_export',
62 # 'help': 'Exports the data for this MediaGoblin instance'},
63 # 'env_import': {
64 # 'setup': 'mediagoblin.gmg_commands.import_export:import_export_parse_setup',
65 # 'func': 'mediagoblin.gmg_commands.import_export:env_import',
66 # 'help': 'Imports the data for this MediaGoblin instance'},
029cad45
CAW
67 }
68
69
029cad45
CAW
70def main_cli():
71 parser = argparse.ArgumentParser(
72 description='GNU MediaGoblin utilities.')
15ac1458 73 parser.add_argument(
9d0a613b
CAW
74 '-cf', '--conf_file', default=None,
75 help=(
76 "Config file used to set up environment. "
77 "Default to mediagoblin_local.ini if readable, "
78 "otherwise mediagoblin.ini"))
029cad45
CAW
79
80 subparsers = parser.add_subparsers(help='sub-command help')
81 for command_name, command_struct in SUBCOMMAND_MAP.iteritems():
285ffedd 82 if 'help' in command_struct:
029cad45
CAW
83 subparser = subparsers.add_parser(
84 command_name, help=command_struct['help'])
85 else:
86 subparser = subparsers.add_parser(command_name)
87
b43b17fc
CAW
88 setup_func = import_component(command_struct['setup'])
89 exec_func = import_component(command_struct['func'])
029cad45
CAW
90
91 setup_func(subparser)
92
93 subparser.set_defaults(func=exec_func)
94
95 args = parser.parse_args()
9d0a613b
CAW
96 if args.conf_file is None:
97 if os.path.exists('mediagoblin_local.ini') \
98 and os.access('mediagoblin_local.ini', os.R_OK):
99 args.conf_file = 'mediagoblin_local.ini'
100 else:
101 args.conf_file = 'mediagoblin.ini'
102
029cad45
CAW
103 args.func(args)
104
105
106if __name__ == '__main__':
107 main_cli()