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 | |
386c9c7c BP |
20 | import six |
21 | ||
b43b17fc | 22 | from mediagoblin.tools.common import import_component |
029cad45 CAW |
23 | |
24 | ||
25 | SUBCOMMAND_MAP = { | |
26 | 'shell': { | |
dbb92c60 CAW |
27 | 'setup': 'mediagoblin.gmg_commands.shell:shell_parser_setup', |
28 | 'func': 'mediagoblin.gmg_commands.shell:shell', | |
029cad45 | 29 | 'help': 'Run a shell with some tools pre-setup'}, |
243c3843 | 30 | 'adduser': { |
96108ea2 AV |
31 | 'setup': 'mediagoblin.gmg_commands.users:adduser_parser_setup', |
32 | 'func': 'mediagoblin.gmg_commands.users:adduser', | |
7f4b4471 | 33 | 'help': 'Creates an user'}, |
96108ea2 AV |
34 | 'makeadmin': { |
35 | 'setup': 'mediagoblin.gmg_commands.users:makeadmin_parser_setup', | |
36 | 'func': 'mediagoblin.gmg_commands.users:makeadmin', | |
b2800598 | 37 | 'help': 'Makes user an admin'}, |
96108ea2 AV |
38 | 'changepw': { |
39 | 'setup': 'mediagoblin.gmg_commands.users:changepw_parser_setup', | |
40 | 'func': 'mediagoblin.gmg_commands.users:changepw', | |
b2800598 | 41 | 'help': 'Changes a user\'s password'}, |
8c7ba963 LLN |
42 | 'deleteuser': { |
43 | 'setup': 'mediagoblin.gmg_commands.users:deleteuser_parser_setup', | |
44 | 'func': 'mediagoblin.gmg_commands.users:deleteuser', | |
45 | 'help': 'Deletes a user'}, | |
3ea1cf36 CAW |
46 | 'dbupdate': { |
47 | 'setup': 'mediagoblin.gmg_commands.dbupdate:dbupdate_parse_setup', | |
48 | 'func': 'mediagoblin.gmg_commands.dbupdate:dbupdate', | |
49 | 'help': 'Set up or update the SQL database'}, | |
6afc8364 CAW |
50 | 'assetlink': { |
51 | 'setup': 'mediagoblin.gmg_commands.assetlink:assetlink_parser_setup', | |
52 | 'func': 'mediagoblin.gmg_commands.assetlink:assetlink', | |
53 | 'help': 'Link assets for themes and plugins for static serving'}, | |
c3071480 RE |
54 | 'reprocess': { |
55 | 'setup': 'mediagoblin.gmg_commands.reprocess:reprocess_parser_setup', | |
56 | 'func': 'mediagoblin.gmg_commands.reprocess:reprocess', | |
57 | 'help': 'Reprocess media entries'}, | |
b7a8760b CAW |
58 | 'addmedia': { |
59 | 'setup': 'mediagoblin.gmg_commands.addmedia:parser_setup', | |
60 | 'func': 'mediagoblin.gmg_commands.addmedia:addmedia', | |
61 | 'help': 'Reprocess media entries'}, | |
521824da BP |
62 | 'deletemedia': { |
63 | 'setup': 'mediagoblin.gmg_commands.deletemedia:parser_setup', | |
64 | 'func': 'mediagoblin.gmg_commands.deletemedia:deletemedia', | |
65 | 'help': 'Delete media entries'}, | |
051c728c BP |
66 | 'serve': { |
67 | 'setup': 'mediagoblin.gmg_commands.serve:parser_setup', | |
68 | 'func': 'mediagoblin.gmg_commands.serve:serve', | |
69 | 'help': 'PasteScript replacement'}, | |
8aa01597 | 70 | 'batchaddmedia': { |
71 | 'setup': 'mediagoblin.gmg_commands.batchaddmedia:parser_setup', | |
72 | 'func': 'mediagoblin.gmg_commands.batchaddmedia:batchaddmedia', | |
1d09e8b4 | 73 | 'help': 'Add many media entries at once'}, |
6afc8364 CAW |
74 | # 'theme': { |
75 | # 'setup': 'mediagoblin.gmg_commands.theme:theme_parser_setup', | |
76 | # 'func': 'mediagoblin.gmg_commands.theme:theme', | |
77 | # 'help': 'Theming commands', | |
78 | # } | |
63578ee3 CAW |
79 | |
80 | ## These might be useful, mayyyybe, but don't really work anymore | |
81 | ## due to mongo change and the "versatility" of sql options. | |
82 | ## | |
83 | ## For now, commenting out. Might re-enable soonish? | |
84 | # | |
85 | # 'env_export': { | |
86 | # 'setup': 'mediagoblin.gmg_commands.import_export:import_export_parse_setup', | |
87 | # 'func': 'mediagoblin.gmg_commands.import_export:env_export', | |
88 | # 'help': 'Exports the data for this MediaGoblin instance'}, | |
89 | # 'env_import': { | |
90 | # 'setup': 'mediagoblin.gmg_commands.import_export:import_export_parse_setup', | |
91 | # 'func': 'mediagoblin.gmg_commands.import_export:env_import', | |
92 | # 'help': 'Imports the data for this MediaGoblin instance'}, | |
029cad45 CAW |
93 | } |
94 | ||
95 | ||
029cad45 CAW |
96 | def main_cli(): |
97 | parser = argparse.ArgumentParser( | |
98 | description='GNU MediaGoblin utilities.') | |
15ac1458 | 99 | parser.add_argument( |
9d0a613b CAW |
100 | '-cf', '--conf_file', default=None, |
101 | help=( | |
102 | "Config file used to set up environment. " | |
103 | "Default to mediagoblin_local.ini if readable, " | |
104 | "otherwise mediagoblin.ini")) | |
029cad45 CAW |
105 | |
106 | subparsers = parser.add_subparsers(help='sub-command help') | |
386c9c7c | 107 | for command_name, command_struct in six.iteritems(SUBCOMMAND_MAP): |
285ffedd | 108 | if 'help' in command_struct: |
029cad45 CAW |
109 | subparser = subparsers.add_parser( |
110 | command_name, help=command_struct['help']) | |
111 | else: | |
112 | subparser = subparsers.add_parser(command_name) | |
113 | ||
b43b17fc CAW |
114 | setup_func = import_component(command_struct['setup']) |
115 | exec_func = import_component(command_struct['func']) | |
029cad45 CAW |
116 | |
117 | setup_func(subparser) | |
118 | ||
119 | subparser.set_defaults(func=exec_func) | |
120 | ||
58bacb33 CAW |
121 | args = parser.parse_args() |
122 | args.orig_conf_file = args.conf_file | |
123 | if args.conf_file is None: | |
9d0a613b CAW |
124 | if os.path.exists('mediagoblin_local.ini') \ |
125 | and os.access('mediagoblin_local.ini', os.R_OK): | |
58bacb33 | 126 | args.conf_file = 'mediagoblin_local.ini' |
9d0a613b | 127 | else: |
58bacb33 | 128 | args.conf_file = 'mediagoblin.ini' |
9d0a613b | 129 | |
58bacb33 | 130 | args.func(args) |
029cad45 CAW |
131 | |
132 | ||
133 | if __name__ == '__main__': | |
134 | main_cli() |