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/>.
23 from mediagoblin
.tools
.common
import import_component
26 _log
= logging
.getLogger(__name__
)
32 'setup': 'mediagoblin.gmg_commands.shell:shell_parser_setup',
33 'func': 'mediagoblin.gmg_commands.shell:shell',
34 'help': 'Run a shell with some tools pre-setup'},
36 'setup': 'mediagoblin.gmg_commands.users:adduser_parser_setup',
37 'func': 'mediagoblin.gmg_commands.users:adduser',
38 'help': 'Creates an user'},
40 'setup': 'mediagoblin.gmg_commands.users:makeadmin_parser_setup',
41 'func': 'mediagoblin.gmg_commands.users:makeadmin',
42 'help': 'Makes user an admin'},
44 'setup': 'mediagoblin.gmg_commands.users:changepw_parser_setup',
45 'func': 'mediagoblin.gmg_commands.users:changepw',
46 'help': 'Changes a user\'s password'},
48 'setup': 'mediagoblin.gmg_commands.users:deleteuser_parser_setup',
49 'func': 'mediagoblin.gmg_commands.users:deleteuser',
50 'help': 'Deletes a user'},
52 'setup': 'mediagoblin.gmg_commands.dbupdate:dbupdate_parse_setup',
53 'func': 'mediagoblin.gmg_commands.dbupdate:dbupdate',
54 'help': 'Set up or update the SQL database'},
56 'setup': 'mediagoblin.gmg_commands.assetlink:assetlink_parser_setup',
57 'func': 'mediagoblin.gmg_commands.assetlink:assetlink',
58 'help': 'Link assets for themes and plugins for static serving'},
60 'setup': 'mediagoblin.gmg_commands.reprocess:reprocess_parser_setup',
61 'func': 'mediagoblin.gmg_commands.reprocess:reprocess',
62 'help': 'Reprocess media entries'},
64 'setup': 'mediagoblin.gmg_commands.addmedia:parser_setup',
65 'func': 'mediagoblin.gmg_commands.addmedia:addmedia',
66 'help': 'Reprocess media entries'},
68 'setup': 'mediagoblin.gmg_commands.deletemedia:parser_setup',
69 'func': 'mediagoblin.gmg_commands.deletemedia:deletemedia',
70 'help': 'Delete media entries'},
72 'setup': 'mediagoblin.gmg_commands.serve:parser_setup',
73 'func': 'mediagoblin.gmg_commands.serve:serve',
74 'help': 'PasteScript replacement'},
76 'setup': 'mediagoblin.gmg_commands.batchaddmedia:parser_setup',
77 'func': 'mediagoblin.gmg_commands.batchaddmedia:batchaddmedia',
78 'help': 'Add many media entries at once'},
80 'setup': 'mediagoblin.gmg_commands.alembic_commands:parser_setup',
81 'func': 'mediagoblin.gmg_commands.alembic_commands:raw_alembic_cli',
83 'Run raw alembic commands with our local database. '
84 '(Unless you know what you\'re doing, use dbupdate instead!)')},
86 # 'setup': 'mediagoblin.gmg_commands.theme:theme_parser_setup',
87 # 'func': 'mediagoblin.gmg_commands.theme:theme',
88 # 'help': 'Theming commands',
94 parser
= argparse
.ArgumentParser(
95 description
='GNU MediaGoblin utilities.')
97 '-cf', '--conf_file', default
=None,
99 "Config file used to set up environment. "
100 "Default to mediagoblin_local.ini if readable, "
101 "otherwise mediagoblin.ini"))
103 subparsers
= parser
.add_subparsers(help='sub-command help')
104 for command_name
, command_struct
in six
.iteritems(SUBCOMMAND_MAP
):
105 if 'help' in command_struct
:
106 subparser
= subparsers
.add_parser(
107 command_name
, help=command_struct
['help'])
109 subparser
= subparsers
.add_parser(command_name
)
111 setup_func
= import_component(command_struct
['setup'])
112 exec_func
= import_component(command_struct
['func'])
114 setup_func(subparser
)
116 subparser
.set_defaults(func
=exec_func
)
118 args
= parser
.parse_args()
119 args
.orig_conf_file
= args
.conf_file
120 if args
.conf_file
is None:
121 if os
.path
.exists('mediagoblin_local.ini') \
122 and os
.access('mediagoblin_local.ini', os
.R_OK
):
123 args
.conf_file
= 'mediagoblin_local.ini'
125 args
.conf_file
= 'mediagoblin.ini'
127 # This is a hopefully TEMPORARY hack for adding a mediagoblin.ini
128 # if none exists, to make up for a deficiency as we are migrating
129 # our docs to the new "no mediagoblin.ini by default" workflow.
130 # Normally, the docs should provide instructions for this, but
131 # since 0.7.1 docs say "install from master!" and yet we removed
132 # mediagoblin.ini, we need to cover our bases...
134 parent_directory
= os
.path
.split(os
.path
.abspath(args
.conf_file
))[0]
135 if os
.path
.split(args
.conf_file
)[1] == 'mediagoblin.ini' \
136 and not os
.path
.exists(args
.conf_file
) \
139 parent_directory
, 'mediagoblin.example.ini')):
140 # Do the copy-over of the mediagoblin config for the user
142 "No mediagoblin.ini found and no other path given, "
143 "so making one for you.")
145 os
.path
.join(parent_directory
, "mediagoblin.example.ini"),
146 os
.path
.join(parent_directory
, "mediagoblin.ini"))
150 except AttributeError: # no subcommand or no func of subcommand
154 if __name__
== '__main__':