Issue #362 - Updated `mediagoblin.user_pages.views` to handle new "Simple comments...
[mediagoblin.git] / mediagoblin / gmg_commands / __init__.py
CommitLineData
029cad45
CAW
1# GNU MediaGoblin -- federated, autonomous media hosting
2# Copyright (C) 2011 Free Software Foundation, Inc
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
029cad45 18
8820121a 19from mediagoblin import util as mg_util
029cad45
CAW
20
21
22SUBCOMMAND_MAP = {
23 'shell': {
dbb92c60
CAW
24 'setup': 'mediagoblin.gmg_commands.shell:shell_parser_setup',
25 'func': 'mediagoblin.gmg_commands.shell:shell',
029cad45 26 'help': 'Run a shell with some tools pre-setup'},
757f37a5
CAW
27 'migrate': {
28 'setup': 'mediagoblin.gmg_commands.migrate:migrate_parser_setup',
29 'func': 'mediagoblin.gmg_commands.migrate:migrate',
30 'help': 'Apply all unapplied bulk migrations to the database'},
96108ea2
AV
31 'adduser':{
32 'setup': 'mediagoblin.gmg_commands.users:adduser_parser_setup',
33 'func': 'mediagoblin.gmg_commands.users:adduser',
7f4b4471 34 'help': 'Creates an user'},
96108ea2
AV
35 'makeadmin': {
36 'setup': 'mediagoblin.gmg_commands.users:makeadmin_parser_setup',
37 'func': 'mediagoblin.gmg_commands.users:makeadmin',
7f4b4471 38 'help': 'Changes a user\'s password'},
96108ea2
AV
39 'changepw': {
40 'setup': 'mediagoblin.gmg_commands.users:changepw_parser_setup',
41 'func': 'mediagoblin.gmg_commands.users:changepw',
7f4b4471 42 'help': 'Makes admin an user'},
029cad45
CAW
43 }
44
45
029cad45
CAW
46def main_cli():
47 parser = argparse.ArgumentParser(
48 description='GNU MediaGoblin utilities.')
49
50 subparsers = parser.add_subparsers(help='sub-command help')
51 for command_name, command_struct in SUBCOMMAND_MAP.iteritems():
52 if command_struct.has_key('help'):
53 subparser = subparsers.add_parser(
54 command_name, help=command_struct['help'])
55 else:
56 subparser = subparsers.add_parser(command_name)
57
8820121a
CAW
58 setup_func = mg_util.import_component(command_struct['setup'])
59 exec_func = mg_util.import_component(command_struct['func'])
029cad45
CAW
60
61 setup_func(subparser)
62
63 subparser.set_defaults(func=exec_func)
64
65 args = parser.parse_args()
66 args.func(args)
67
68
69if __name__ == '__main__':
70 main_cli()
96108ea2 71