Removed some files + added .gitignore
[satega.git] / agent.py
blobf91a1cf834fd25e3db8166c6875c6f5629d078a7
2 # Copyright (C) 2008
3 # Torbjorn Soiland <tosoil@start.no>
4 # Knut Saua Mathiesen <ks.mathiesen@gmail.com>
6 # This file is part of Satega.
8 # Satega is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU 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.
13 # Satega 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 General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Satega. If not, see <http://www.gnu.org/licenses/>.
23 import SimpleXMLRPCServer
24 import UserDict
26 class ModulesList(UserDict.UserDict):
27 """ A dictionary which holds every module loaded. """
28 def __init__(self):
29 UserDict.UserDict.__init__(self)
30 self.moduledir = __import__('modules')
31 self.data = {}
33 def load(self, filename, name):
34 self.data[name] = getattr(__import__('modules.%s' % filename, fromlist=[self.moduledir]), name)()
37 def rpc(modulename, function, *args):
38 """ This is the only method that can be called from the frontend. It routes calls to the modules."""
39 # Get modulelist from globals, and get module from list.
40 module = globals()['ModulesList'][modulename]
41 # Get function from the module
42 function = getattr(module, function)
44 # TODO - block access to modules if not logged in
45 # TODO - maby do some format checking on data.
47 # Call the function. Send return values directly to frontend.
48 return function(*args)
50 if __name__ == '__main__':
51 # We get this list later with globals()
52 ModulesList = ModulesList()
53 ModulesList.load('testmodule', 'TestModule')
55 server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 8000), allow_none=True)
56 server.register_function(rpc)
57 print 'Listening on port 8000'
58 server.serve_forever()