Mercurial > libervia-web
comparison twisted/plugins/plugin.py @ 329:c144b603fb93
server side: make Libervia a Twisted plugin, and add it the --port argument + add a config file for the port.
Fixes bug 16.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sat, 23 Feb 2013 16:27:32 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
328:835a8ae799e7 | 329:c144b603fb93 |
---|---|
1 #!/usr/bin/python | |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 Libervia: a Salut à Toi frontend | |
6 Copyright (C) 2013 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | |
7 | |
8 This program is free software: you can redistribute it and/or modify | |
9 it under the terms of the GNU Affero General Public License as published by | |
10 the Free Software Foundation, either version 3 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU Affero General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU Affero General Public License | |
19 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 """ | |
21 | |
22 from zope.interface import implements | |
23 | |
24 from twisted.python import usage | |
25 from twisted.plugin import IPlugin | |
26 from twisted.application.service import IServiceMaker | |
27 from twisted.application import internet | |
28 | |
29 from xdg.BaseDirectory import save_config_path | |
30 from ConfigParser import SafeConfigParser, NoSectionError | |
31 from os.path import expanduser | |
32 | |
33 from libervia import Libervia | |
34 | |
35 | |
36 class Options(usage.Options): | |
37 optParameters = [['port', 'p', 8080, 'The port number to listen on.']] | |
38 | |
39 | |
40 class LiberviaMaker(object): | |
41 implements(IServiceMaker, IPlugin) | |
42 tapname = 'libervia' | |
43 description = 'The web frontend of Salut à Toi' | |
44 options = Options | |
45 | |
46 def makeService(self, options): | |
47 if not isinstance(options['port'], int): | |
48 port = int(options['port']) | |
49 else: | |
50 try: | |
51 port = config.getint('libervia', 'port') | |
52 except NoSectionError: | |
53 port = 8080 | |
54 return Libervia(port=port) | |
55 | |
56 | |
57 config_path = save_config_path('sat') | |
58 config = SafeConfigParser() | |
59 config.read(map(expanduser, ['/etc/sat.conf', config_path + '/sat.conf', 'sat.conf', '.sat.conf'])) | |
60 | |
61 serviceMaker = LiberviaMaker() |