1
0
Fork 0
gnuviechadmin-historic/backend/GnuviechAdmin/ServiceFacade.py
Jan Dittberner bf7992a600 - initial work on a mod_python based web frontend
- add logs to svn:ignore
- use psycopg2 in backend


git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/gnuviech.info/gnuviechadmin/trunk@198 a67ec6bc-e5d5-0310-a910-815c51eb3124
2006-11-04 20:24:36 +00:00

62 lines
2 KiB
Python

#
# Service facade for gnuviech-admin tool backend
# (c) 2006 Jan Dittberner <jan@dittberner.info>
# $Id$
#
from SessionManager import *
from DomainManager import *
import Settings
import psycopg2
class ServiceFacade:
"""
This class implements the facade to the services provided by the
gnuviech admin backend.
"""
def __init__(self):
connstr = 'host=%(dbhost)s user=%(dbuser)s ' + \
'password=%(dbpassword)s dbname=%(dbname)s'
dbconn = psycopg2.connect(connstr % Settings.DBSETTINGS)
self.sessionManager = SessionManager(dbconn)
self.domainManager = DomainManager(dbconn)
def _dispatch(self, method, params):
try:
func = getattr(self, method)
except AttributeError:
raise Exception('method "%s" is not supported' % method)
else:
if method != 'login' and method != 'logout':
sessionid = params[0]
try:
session = self.sessionManager.getSession(sessionid)
except InvalidSessionError:
return ""
nparams = [session]
for item in params[1:]:
nparams.append(item)
params = nparams
self.sessionManager.updateSession(sessionid)
return func(*params)
def login(self, login, password):
"""
Logs in the user specified by the given login and password.
The method creates a session and returns the session id which
has to be sent back by subsequent requests. If the login is
invalid the returned id is 0
"""
try:
return self.sessionManager.newSession(login, password)
except InvalidLoginError, ile:
return 0
def logout(self, sessionid):
self.sessionManager.deleteSession(sessionid)
return 0
def listdomains(self, session):
"""
Lists the domains the given session may see.
"""
return self.domainManager.listDomains(session)