Module domain
[hide private]
[frames] | no frames]

Source Code for Module domain

  1  # -*- coding: utf-8 -*-
 
  2  
 
  3  ############################################################################
 
  4  # domain.py
 
  5  #
 
  6  # Main domain module for MOCOP.
 
  7  #
 
  8  # (C) 2008 Likya Software Ltd.
 
  9  ############################################################################
 
 10  
 
 11  import os, sys, time 
 12  
 
 13  from twisted.python import log 
 14  
 
 15  from ConfigParser import SafeConfigParser 
 16  from constants import Constants 
 17  
 
18 -class DomainManager(object):
19 ''' 20 DomainManager class that coordinates the requests about domains. 21 '''
22 - def __init__(self, appserver):
23 self._appServer = appserver 24 self._domains = {}
25
26 - def domain(self, domainID):
27 ''' 28 Returns the domain with the domainID. 29 ''' 30 return self._domains.get(domainID)
31
32 - def allDomains(self):
33 ''' 34 Returns a dict of all domains. 35 ''' 36 return self._domains
37
38 - def load(self):
39 ''' 40 Reload the configuration from the conf file 41 ''' 42 try: 43 confParser = SafeConfigParser() 44 confParser.read(os.path.join(self._appServer.directory(), Constants.DOMAIN_CONF_FILE)) 45 # Read all domains in the configuration file 46 for section in confParser.sections(): 47 newDomain = Domain(section) 48 for option in confParser.options(section): 49 setattr(newDomain, "_%s" % option, confParser.get(section, option)) 50 self._domains[section] = newDomain 51 except Exception, e: 52 log.msg('Error in DomainManager.load(): %s', e) 53 sys.exit(1)
54 55 from twisted.spread import pb 56
57 -class Domain(object):
58 ''' 59 Domain class that represends the customers of the applciation 60 '''
61 - def __init__(self, name):
62 self._name = name 63 self._desc = None 64 self._manager = None 65 self._db = None 66 self._dist = None 67 self._license = None
68
69 - def toDict(self):
70 ''' 71 Convert to a dict holding only standard python types. 72 ''' 73 __slots__ = ['_name', '_desc', '_db', '_dist', '_license'] 74 return dict([(k, getattr(self, k, None)) for k in __slots__])
75
76 - def name(self):
77 ''' 78 Return the name of the Domain. 79 ''' 80 return self._name
81
82 - def desc(self):
83 ''' 84 Return the description of the Domain. 85 ''' 86 return self._desc
87
88 - def manager(self):
89 ''' 90 Return the manager server address of the Domain. 91 ''' 92 return self._server
93
94 - def db(self):
95 ''' 96 Return the DB Server URL for the Domain. 97 ''' 98 return self._db
99
100 - def dist(self):
101 ''' 102 Return the disturibution of the Domain. 103 ''' 104 return self._dist
105
106 - def license(self):
107 ''' 108 Return the license of the Domain. 109 ''' 110 return self._license
111