server fix
[systematiki.git] / systematikid.py
blob30ac890fb34c4d20ced5195a26238c2f09e5426e
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 """
4 Systematiki server.
6 The client is called 'systematiki.py'.
7 """
9 # Copyright (C) 2007 Felix Rabe <public@felixrabe.textdriven.com>
11 # This library is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU Lesser General Public
13 # License as published by the Free Software Foundation; either
14 # version 2.1 of the License, or (at your option) any later version.
16 # This library is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 # Lesser General Public License for more details.
21 # You should have received a copy of the GNU Lesser General Public License
22 # along with this library; if not, write to the Free Software Foundation,
23 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 # Recommended line length or text width: 75 characters.
27 from Systematiki.Database.Dummy import Database
28 from Systematiki.Networking.BlockingStringProtocol import StringProtocol
29 from Systematiki.Networking.XDRRPC import XDRRPC
32 class ServerConfig(object):
33 """
34 Server configuration class.
36 TODO: Proper configuration using either command-line arguments,
37 configuration files, or a GUI.
38 """
40 def __init__(self, argv):
41 self.host = "localhost"
42 self.port = 6420
43 self.database_class = Database
44 self.ui = "cli"
47 def cli_ui(config):
48 database = config.database_class(config)
49 server_proto = StringProtocol()
50 server_proto.listen((config.host, config.port))
51 cb = lambda p: cli_ui_cb_1(p, database)
52 server_proto.accept(cb)
55 def cli_ui_cb_1(client_proto, database):
56 rpc = XDRRPC(client_proto, database)
59 def main(argv):
60 config = ServerConfig(argv) # Might run and quit a gobject.MainLoop
61 if config.ui == "cli":
62 cli_ui(config)
63 # TODO: GTK interface, web interface, brain interface, ...
64 return 0
67 if __name__ == "__main__":
68 import sys
69 sys.exit(main(sys.argv))