1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
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.
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.
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/>.
20 from mediagoblin
.tools
.common
import import_component
25 'setup': 'mediagoblin.gmg_commands.shell:shell_parser_setup',
26 'func': 'mediagoblin.gmg_commands.shell:shell',
27 'help': 'Run a shell with some tools pre-setup'},
29 'setup': 'mediagoblin.gmg_commands.migrate:migrate_parser_setup',
30 'func': 'mediagoblin.gmg_commands.migrate:migrate',
31 'help': ('Migrate your Mongo database. '
32 '[DEPRECATED!] use convert_mongo_to_sql and dbupdate.')},
34 'setup': 'mediagoblin.gmg_commands.users:adduser_parser_setup',
35 'func': 'mediagoblin.gmg_commands.users:adduser',
36 'help': 'Creates an user'},
38 'setup': 'mediagoblin.gmg_commands.users:makeadmin_parser_setup',
39 'func': 'mediagoblin.gmg_commands.users:makeadmin',
40 'help': 'Changes a user\'s password'},
42 'setup': 'mediagoblin.gmg_commands.users:changepw_parser_setup',
43 'func': 'mediagoblin.gmg_commands.users:changepw',
44 'help': 'Makes admin an user'},
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'},
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'},
54 'setup': 'mediagoblin.gmg_commands.theme:theme_parser_setup',
55 'func': 'mediagoblin.gmg_commands.theme:theme',
56 'help': 'Theming commands',
59 ## These might be useful, mayyyybe, but don't really work anymore
60 ## due to mongo change and the "versatility" of sql options.
62 ## For now, commenting out. Might re-enable soonish?
65 # 'setup': 'mediagoblin.gmg_commands.import_export:import_export_parse_setup',
66 # 'func': 'mediagoblin.gmg_commands.import_export:env_export',
67 # 'help': 'Exports the data for this MediaGoblin instance'},
69 # 'setup': 'mediagoblin.gmg_commands.import_export:import_export_parse_setup',
70 # 'func': 'mediagoblin.gmg_commands.import_export:env_import',
71 # 'help': 'Imports the data for this MediaGoblin instance'},
76 parser
= argparse
.ArgumentParser(
77 description
='GNU MediaGoblin utilities.')
79 '-cf', '--conf_file', default
=None,
81 "Config file used to set up environment. "
82 "Default to mediagoblin_local.ini if readable, "
83 "otherwise mediagoblin.ini"))
85 subparsers
= parser
.add_subparsers(help='sub-command help')
86 for command_name
, command_struct
in SUBCOMMAND_MAP
.iteritems():
87 if 'help' in command_struct
:
88 subparser
= subparsers
.add_parser(
89 command_name
, help=command_struct
['help'])
91 subparser
= subparsers
.add_parser(command_name
)
93 setup_func
= import_component(command_struct
['setup'])
94 exec_func
= import_component(command_struct
['func'])
98 subparser
.set_defaults(func
=exec_func
)
100 args
= parser
.parse_args()
101 args
.orig_conf_file
= args
.conf_file
102 if args
.conf_file
is None:
103 if os
.path
.exists('mediagoblin_local.ini') \
104 and os
.access('mediagoblin_local.ini', os
.R_OK
):
105 args
.conf_file
= 'mediagoblin_local.ini'
107 args
.conf_file
= 'mediagoblin.ini'
112 if __name__
== '__main__':