#!/usr/bin/env python # Copyright (C) 2012, Aleksey Lim # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . import sys import optparse from os.path import dirname, join, realpath from gettext import gettext as _ from gevent.wsgi import WSGIServer from sugar_network import client from sugar_network.toolkit.http import Connection from sugar_network.toolkit import application,Option from sugar_network_webui import get_app SRC_ROOT = dirname(realpath(__file__)) host = optparse.Option("-h", "--host", type="string", help=_('address to listen for Web clients'), default='127.0.0.1') port = optparse.Option("-p", "--port", type="int", help=_('address to listen for Web clients'), default=5000) api_url = optparse.Option("-a", "--api_url", type="string", help=_('address of node server to connect to'), default='http://node-devel.sugarlabs.org/') anonymous = optparse.Option("--anonymous", action="store_true", help=_('connect as anonymous user'), default=False) class Application(application.Daemon): httpd = None def start(self): application.logdir.value = client.profile_path('logs') application.rundir.value = client.profile_path('run') application.Daemon.start(self) def run(self): app = self._get_app() self.httpd = WSGIServer((host.default, port.default), app) self.httpd.serve_forever() def shutdown(self): if self.httpd is not None: self.httpd.stop() @application.command(_('Run application in debug mode')) def debug(self): app = self._get_app() app.debug = True app.run(host=host.default, port=port.default) def _get_app(self): self.connection = Connection(api_url) return get_app(self.connection.call, api_url, anonymous) Option.seek('mejorar-sistema') Option.seek('mejorar-sistema', [application.debug, application.foreground]) app = Application( name='mejorar-sistema', description=_('Flask server to serve Sugar Network users'), epilog=_('See http://wiki.sugarlabs.org/go/Platform_Team/' \ 'Sugar_Network/Browser.'), config_files=[ '/etc/sweets.conf', '~/.config/sweets/config', client.profile_path('sweets.conf'), ]) app.start()