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.users:adduser_parser_setup',
30 'func': 'mediagoblin.gmg_commands.users:adduser',
31 'help': 'Creates an user'},
33 'setup': 'mediagoblin.gmg_commands.users:makeadmin_parser_setup',
34 'func': 'mediagoblin.gmg_commands.users:makeadmin',
35 'help': 'Makes user an admin'},
37 'setup': 'mediagoblin.gmg_commands.users:changepw_parser_setup',
38 'func': 'mediagoblin.gmg_commands.users:changepw',
39 'help': 'Changes a user\'s password'},
41 'setup': 'mediagoblin.gmg_commands.dbupdate:dbupdate_parse_setup',
42 'func': 'mediagoblin.gmg_commands.dbupdate:dbupdate',
43 'help': 'Set up or update the SQL database'},
45 'setup': 'mediagoblin.gmg_commands.assetlink:assetlink_parser_setup',
46 'func': 'mediagoblin.gmg_commands.assetlink:assetlink',
47 'help': 'Link assets for themes and plugins for static serving'},
49 # 'setup': 'mediagoblin.gmg_commands.theme:theme_parser_setup',
50 # 'func': 'mediagoblin.gmg_commands.theme:theme',
51 # 'help': 'Theming commands',
54 ## These might be useful, mayyyybe, but don't really work anymore
55 ## due to mongo change and the "versatility" of sql options.
57 ## For now, commenting out. Might re-enable soonish?
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'},
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'},
71 parser
= argparse
.ArgumentParser(
72 description
='GNU MediaGoblin utilities.')
74 '-cf', '--conf_file', default
=None,
76 "Config file used to set up environment. "
77 "Default to mediagoblin_local.ini if readable, "
78 "otherwise mediagoblin.ini"))
80 subparsers
= parser
.add_subparsers(help='sub-command help')
81 for command_name
, command_struct
in SUBCOMMAND_MAP
.iteritems():
82 if 'help' in command_struct
:
83 subparser
= subparsers
.add_parser(
84 command_name
, help=command_struct
['help'])
86 subparser
= subparsers
.add_parser(command_name
)
88 setup_func
= import_component(command_struct
['setup'])
89 exec_func
= import_component(command_struct
['func'])
93 subparser
.set_defaults(func
=exec_func
)
95 args
= parser
.parse_args()
96 args
.orig_conf_file
= args
.conf_file
97 if args
.conf_file
is None:
98 if os
.path
.exists('mediagoblin_local.ini') \
99 and os
.access('mediagoblin_local.ini', os
.R_OK
):
100 args
.conf_file
= 'mediagoblin_local.ini'
102 args
.conf_file
= 'mediagoblin.ini'
107 if __name__
== '__main__':