view src/twisted/plugins/libervia_server.py @ 449:981ed669d3b3

/!\ reorganize all the file hierarchy, move the code and launching script to src: - browser_side --> src/browser - public --> src/browser_side/public - libervia.py --> src/browser/libervia_main.py - libervia_server --> src/server - libervia_server/libervia.sh --> src/libervia.sh - twisted --> src/twisted - new module src/common - split constants.py in 3 files: - src/common/constants.py - src/browser/constants.py - src/server/constants.py - output --> html (generated by pyjsbuild during the installation) - new option/parameter "data_dir" (-d) to indicates the directory containing html and server_css - setup.py installs libervia to the following paths: - src/common --> <LIB>/libervia/common - src/server --> <LIB>/libervia/server - src/twisted --> <LIB>/twisted - html --> <SHARE>/libervia/html - server_side --> <SHARE>libervia/server_side - LIBERVIA_INSTALL environment variable takes 2 new options with prompt confirmation: - clean: remove previous installation directories - purge: remove building and previous installation directories You may need to update your sat.conf and/or launching script to update the following options/parameters: - ssl_certificate - data_dir
author souliane <souliane@mailoo.org>
date Tue, 20 May 2014 06:41:16 +0200
parents twisted/plugins/libervia.py@c406e46fe9c0
children 1a0cec9b0f1e
line wrap: on
line source

#!/usr/bin/python
# -*- coding: utf-8 -*-

# Libervia: a Salut à Toi frontend
# Copyright (C) 2013  Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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 Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

from twisted.internet import defer
if defer.Deferred.debug:
    # if we are in debug mode, we want to use ipdb instead of pdb
    try:
        import ipdb
        import pdb
        pdb.set_trace = ipdb.set_trace
        pdb.post_mortem = ipdb.post_mortem
    except ImportError:
        pass

# XXX: We need to configure logs before any log method is used, so here is the best place.
from libervia.server.constants import Const as C
from sat.core import log_config
log_config.satConfigure(C.LOG_BACKEND_TWISTED, C)

from zope.interface import implements

from twisted.python import usage
from twisted.plugin import IPlugin
from twisted.application.service import IServiceMaker

from ConfigParser import SafeConfigParser, NoSectionError, NoOptionError
try:
    from libervia.server.server import Libervia
    opt_params = Libervia.OPT_PARAMETERS
except (ImportError, SystemExit):
    # avoid raising an error when you call twisted and sat is not launched
    opt_params = []


class Options(usage.Options):

    # optArgs is not really useful in our case, we need more than a flag
    optParameters = opt_params

    def __init__(self):
        """You want to read SàT configuration file now in order to overwrite the hard-coded default values.
        This is because the priority for the usage of the values is (from lowest to highest):
        - hard-coded default values
        - values from SàT configuration files
        - values passed on the command line
        If you do it later: after the command line options have been parsed, there's no good way to know
        if the  options values are the hard-coded ones or if they have been passed on the command line.
        """
        config = SafeConfigParser()
        config.read(C.CONFIG_FILES)
        for index, param in list(enumerate(self.optParameters)):
            # index is only used to not modify the loop variable "param"
            name = param[0]
            try:
                value = config.get('libervia', name)
                self.optParameters[index][2] = param[4](value)
            except (NoSectionError, NoOptionError):
                pass
        usage.Options.__init__(self)


class LiberviaMaker(object):
    implements(IServiceMaker, IPlugin)

    tapname = 'libervia'
    # FIXME: twistd bugs when printing 'à' on "Unknown command" error (works on normal command listing)
    description = u'The web frontend of Salut a Toi'
    options = Options

    def makeService(self, options):
        return Libervia(**dict(options))  # get rid of the usage.Option overload


# affectation to some variable is necessary for twisted introspection to work
serviceMaker = LiberviaMaker()