annotate twisted/plugins/libervia.py @ 438:582c435dab6b

server side: new log system is used
author Goffi <goffi@goffi.org>
date Thu, 08 May 2014 17:21:30 +0200
parents fa3b65b68971
children eca26481176f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 #!/usr/bin/python
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
4 # Libervia: a Salut à Toi frontend
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
5 # Copyright (C) 2013 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
7 # This program is free software: you can redistribute it and/or modify
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
10 # (at your option) any later version.
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
12 # This program is distributed in the hope that it will be useful,
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
15 # GNU Affero General Public License for more details.
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16
339
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
2067d6241927 fixed docstrings wrong usage for licence informations
Goffi <goffi@goffi.org>
parents: 331
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19
437
fa3b65b68971 server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents: 433
diff changeset
20 from twisted.internet import defer
fa3b65b68971 server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents: 433
diff changeset
21 if defer.Deferred.debug:
fa3b65b68971 server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents: 433
diff changeset
22 # if we are in debug mode, we want to use ipdb instead of pdb
fa3b65b68971 server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents: 433
diff changeset
23 try:
fa3b65b68971 server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents: 433
diff changeset
24 import ipdb
fa3b65b68971 server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents: 433
diff changeset
25 import pdb
fa3b65b68971 server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents: 433
diff changeset
26 pdb.set_trace = ipdb.set_trace
fa3b65b68971 server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents: 433
diff changeset
27 pdb.post_mortem = ipdb.post_mortem
fa3b65b68971 server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents: 433
diff changeset
28 except ImportError:
fa3b65b68971 server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents: 433
diff changeset
29 pass
fa3b65b68971 server side: ipdb is used instead of pdb in debug mode
Goffi <goffi@goffi.org>
parents: 433
diff changeset
30
438
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 437
diff changeset
31 # XXX: We need to configure logs before any log method is used, so here is the best place.
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 437
diff changeset
32 from constants import Const as C
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 437
diff changeset
33 from sat.core import log
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 437
diff changeset
34 log.satConfigure(C.LOG_BACKEND_TWISTED, C)
582c435dab6b server side: new log system is used
Goffi <goffi@goffi.org>
parents: 437
diff changeset
35
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 from zope.interface import implements
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 from twisted.python import usage
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 from twisted.plugin import IPlugin
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40 from twisted.application.service import IServiceMaker
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
42 from ConfigParser import SafeConfigParser, NoSectionError, NoOptionError
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 432
diff changeset
43 from sat.core.constants import Const as C
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents: 339
diff changeset
44 try:
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents: 339
diff changeset
45 from libervia_server import Libervia
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
46 opt_params = Libervia.OPT_PARAMETERS
360
9834136b15ed added setup.py for the installation with setuptools
souliane <souliane@mailoo.org>
parents: 339
diff changeset
47 except (ImportError, SystemExit):
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
48 # avoid raising an error when you call twisted and sat is not launched
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
49 opt_params = []
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52 class Options(usage.Options):
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
53
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
54 # optArgs is not really useful in our case, we need more than a flag
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
55 optParameters = opt_params
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
56
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
57 def __init__(self):
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
58 """You want to read SàT configuration file now in order to overwrite the hard-coded default values.
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
59 This is because the priority is (form lowest to highest):
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
60 - use hard-coded default values
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
61 - use the values from SàT configuration files
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
62 - use the values passes on the command line
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
63 If you do it later: after the command line options have been parsed, there's no good way to know
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
64 if the options values are the hard-coded ones or if they have been passed on the command line.
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
65 """
421
39b07289ff42 server_side: added parameter port_https_ext (external port for HTTPS, used for example for the redirection)
souliane <souliane@mailoo.org>
parents: 417
diff changeset
66 config = SafeConfigParser()
433
bbdbee25123a import constants.Const as C (according to the coding rules)
souliane <souliane@mailoo.org>
parents: 432
diff changeset
67 config.read(C.CONFIG_FILES)
432
8ecc5a7062e4 browser and server sides: fixes module import + use enumerate instead of xrange
souliane <souliane@mailoo.org>
parents: 421
diff changeset
68 for index, param in list(enumerate(self.optParameters)):
8ecc5a7062e4 browser and server sides: fixes module import + use enumerate instead of xrange
souliane <souliane@mailoo.org>
parents: 421
diff changeset
69 # index is only used to not modify the loop variable "param"
8ecc5a7062e4 browser and server sides: fixes module import + use enumerate instead of xrange
souliane <souliane@mailoo.org>
parents: 421
diff changeset
70 name = param[0]
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
71 try:
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
72 value = config.get('libervia', name)
432
8ecc5a7062e4 browser and server sides: fixes module import + use enumerate instead of xrange
souliane <souliane@mailoo.org>
parents: 421
diff changeset
73 self.optParameters[index][2] = param[4](value)
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
74 except (NoSectionError, NoOptionError):
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
75 pass
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
76 usage.Options.__init__(self)
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 class LiberviaMaker(object):
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 implements(IServiceMaker, IPlugin)
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81 tapname = 'libervia'
415
fadbba1d793f server_side: added support for SSL and related parameters:
souliane <souliane@mailoo.org>
parents: 360
diff changeset
82 description = u'The web frontend of Salut à Toi'
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 options = Options
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85 def makeService(self, options):
416
e9bc7854bce6 server_side: bug fix passing twistd arguments to Libervia
souliane <souliane@mailoo.org>
parents: 415
diff changeset
86 return Libervia(**dict(options)) # get rid of the usage.Option overload
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88
421
39b07289ff42 server_side: added parameter port_https_ext (external port for HTTPS, used for example for the redirection)
souliane <souliane@mailoo.org>
parents: 417
diff changeset
89 # affectation to some variable is necessary for twisted introspection to work
331
06a48d805547 server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 serviceMaker = LiberviaMaker()