trac#687: Add unit tests for `redirect` and `redirect_obj`.
[larjonas-mediagoblin.git] / mediagoblin / gmg_commands / serve.py
blob64400fdd5eaca2897225e1199b868e8d3ab4e9f0
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/>.
17 from __future__ import print_function
19 from paste.deploy import loadapp, loadserver
22 class ServeCommand(object):
24 def loadserver(self, server_spec, name, relative_to, **kwargs):
25 return loadserver(server_spec, name=name, relative_to=relative_to,
26 **kwargs)
28 def loadapp(self, app_spec, name, relative_to, **kwargs):
29 return loadapp(app_spec, name=name, relative_to=relative_to, **kwargs)
31 def daemonize(self):
32 # TODO: pass to gunicorn if available
33 pass
35 def restart_with_reloader(self):
36 pass
38 def restart_with_monitor(self, reloader=False):
39 pass
41 def run(self):
42 print('Running...')
45 def parser_setup(subparser):
46 subparser.add_argument('config', metavar='CONFIG_FILE')
47 subparser.add_argument('command',
48 choices=['start', 'stop', 'restart', 'status'],
49 nargs='?', default='start')
50 subparser.add_argument('-n', '--app-name',
51 dest='app_name',
52 metavar='NAME',
53 help="Load the named application (default main)")
54 subparser.add_argument('-s', '--server',
55 dest='server',
56 metavar='SERVER_TYPE',
57 help="Use the named server.")
58 subparser.add_argument('--reload',
59 dest='reload',
60 action='store_true',
61 help="Use auto-restart file monitor")
64 def serve(args):
65 serve_cmd = ServeCommand() # TODO: pass args to it
66 serve_cmd.run()