Implement ServeCommand.{loadserver, loadapp}.
[mediagoblin.git] / mediagoblin / gmg_commands / serve.py
CommitLineData
051c728c
BP
1# GNU MediaGoblin -- federated, autonomous media hosting
2# Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
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
17from __future__ import print_function
18
39a90354
BP
19from paste.deploy import loadapp, loadserver
20
051c728c
BP
21
22class ServeCommand(object):
23
39a90354
BP
24 def loadserver(self, server_spec, name, relative_to, **kwargs):
25 return loadserver(server_spec, name=name, relative_to=relative_to,
26 **kwargs)
051c728c 27
39a90354
BP
28 def loadapp(self, app_spec, name, relative_to, **kwargs):
29 return loadapp(app_spec, name=name, relative_to=relative_to, **kwargs)
051c728c
BP
30
31 def daemonize(self):
32 # TODO: pass to gunicorn if available
33 pass
34
35 def restart_with_reloader(self):
36 pass
37
38 def restart_with_monitor(self, reloader=False):
39 pass
40
41 def run(self):
42 print('Running...')
43
44
45def 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")
62
63
64def serve(args):
65 serve_cmd = ServeCommand() # TODO: pass args to it
66 serve_cmd.run()