Commit | Line | Data |
---|---|---|
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 | 17 | import argparse |
9d0a613b | 18 | import os |
029cad45 | 19 | |
b43b17fc | 20 | from mediagoblin.tools.common import import_component |
029cad45 CAW |
21 | |
22 | ||
23 | SUBCOMMAND_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'}, |
243c3843 | 28 | 'adduser': { |
96108ea2 AV |
29 | 'setup': 'mediagoblin.gmg_commands.users:adduser_parser_setup', |
30 | 'func': 'mediagoblin.gmg_commands.users:adduser', | |
7f4b4471 | 31 | 'help': 'Creates an user'}, |
96108ea2 AV |
32 | 'makeadmin': { |
33 | 'setup': 'mediagoblin.gmg_commands.users:makeadmin_parser_setup', | |
34 | 'func': 'mediagoblin.gmg_commands.users:makeadmin', | |
b2800598 | 35 | 'help': 'Makes user an admin'}, |
96108ea2 AV |
36 | 'changepw': { |
37 | 'setup': 'mediagoblin.gmg_commands.users:changepw_parser_setup', | |
38 | 'func': 'mediagoblin.gmg_commands.users:changepw', | |
b2800598 | 39 | 'help': 'Changes a user\'s password'}, |
3ea1cf36 CAW |
40 | 'dbupdate': { |
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'}, | |
6afc8364 CAW |
44 | 'assetlink': { |
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'}, | |
c3071480 RE |
48 | 'reprocess': { |
49 | 'setup': 'mediagoblin.gmg_commands.reprocess:reprocess_parser_setup', | |
50 | 'func': 'mediagoblin.gmg_commands.reprocess:reprocess', | |
51 | 'help': 'Reprocess media entries'}, | |
b7a8760b CAW |
52 | 'addmedia': { |
53 | 'setup': 'mediagoblin.gmg_commands.addmedia:parser_setup', | |
54 | 'func': 'mediagoblin.gmg_commands.addmedia:addmedia', | |
55 | 'help': 'Reprocess media entries'}, | |
6afc8364 CAW |
56 | # 'theme': { |
57 | # 'setup': 'mediagoblin.gmg_commands.theme:theme_parser_setup', | |
58 | # 'func': 'mediagoblin.gmg_commands.theme:theme', | |
59 | # 'help': 'Theming commands', | |
60 | # } | |
63578ee3 CAW |
61 | |
62 | ## These might be useful, mayyyybe, but don't really work anymore | |
63 | ## due to mongo change and the "versatility" of sql options. | |
64 | ## | |
65 | ## For now, commenting out. Might re-enable soonish? | |
66 | # | |
67 | # 'env_export': { | |
68 | # 'setup': 'mediagoblin.gmg_commands.import_export:import_export_parse_setup', | |
69 | # 'func': 'mediagoblin.gmg_commands.import_export:env_export', | |
70 | # 'help': 'Exports the data for this MediaGoblin instance'}, | |
71 | # 'env_import': { | |
72 | # 'setup': 'mediagoblin.gmg_commands.import_export:import_export_parse_setup', | |
73 | # 'func': 'mediagoblin.gmg_commands.import_export:env_import', | |
74 | # 'help': 'Imports the data for this MediaGoblin instance'}, | |
029cad45 CAW |
75 | } |
76 | ||
77 | ||
029cad45 CAW |
78 | def main_cli(): |
79 | parser = argparse.ArgumentParser( | |
80 | description='GNU MediaGoblin utilities.') | |
15ac1458 | 81 | parser.add_argument( |
9d0a613b CAW |
82 | '-cf', '--conf_file', default=None, |
83 | help=( | |
84 | "Config file used to set up environment. " | |
85 | "Default to mediagoblin_local.ini if readable, " | |
86 | "otherwise mediagoblin.ini")) | |
029cad45 CAW |
87 | |
88 | subparsers = parser.add_subparsers(help='sub-command help') | |
89 | for command_name, command_struct in SUBCOMMAND_MAP.iteritems(): | |
285ffedd | 90 | if 'help' in command_struct: |
029cad45 CAW |
91 | subparser = subparsers.add_parser( |
92 | command_name, help=command_struct['help']) | |
93 | else: | |
94 | subparser = subparsers.add_parser(command_name) | |
95 | ||
b43b17fc CAW |
96 | setup_func = import_component(command_struct['setup']) |
97 | exec_func = import_component(command_struct['func']) | |
029cad45 CAW |
98 | |
99 | setup_func(subparser) | |
100 | ||
101 | subparser.set_defaults(func=exec_func) | |
102 | ||
58bacb33 CAW |
103 | args = parser.parse_args() |
104 | args.orig_conf_file = args.conf_file | |
105 | if args.conf_file is None: | |
9d0a613b CAW |
106 | if os.path.exists('mediagoblin_local.ini') \ |
107 | and os.access('mediagoblin_local.ini', os.R_OK): | |
58bacb33 | 108 | args.conf_file = 'mediagoblin_local.ini' |
9d0a613b | 109 | else: |
58bacb33 | 110 | args.conf_file = 'mediagoblin.ini' |
9d0a613b | 111 | |
58bacb33 | 112 | args.func(args) |
029cad45 CAW |
113 | |
114 | ||
115 | if __name__ == '__main__': | |
116 | main_cli() |