Rev 856 | Details | Compare with Previous | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 856 | migan | 1 | ############################################################################ |
| 2 | # Copyright (C) 2008 by Mattias Runge # |
||
| 3 | # mattias@runge.se # |
||
| 4 | # # |
||
| 5 | # This program is free software; you can redistribute it and#or modify # |
||
| 6 | # it under the terms of the GNU General Public License as published by # |
||
| 7 | # the Free Software Foundation; either version 2 of the License, or # |
||
| 8 | # (at your option) any later version. # |
||
| 9 | # # |
||
| 10 | # This program is distributed in the hope that it will be useful, # |
||
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # |
||
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
||
| 13 | # GNU General Public License for more details. # |
||
| 14 | # # |
||
| 15 | # You should have received a copy of the GNU General Public License # |
||
| 16 | # along with this program; if not, write to the # |
||
| 17 | # Free Software Foundation, Inc., # |
||
| 18 | # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # |
||
| 19 | ############################################################################ |
||
| 20 | |||
| 21 | import os |
||
| 22 | import sys |
||
| 23 | import ServiceBase |
||
| 24 | import Settings |
||
| 25 | |||
| 26 | gServiceMan = False |
||
| 27 | |||
| 28 | def GetServiceManager(): |
||
| 29 | global gServiceMan |
||
| 30 | if gServiceMan == False: |
||
| 31 | gServiceMan = ServiceManager() |
||
| 32 | return gServiceMan |
||
| 33 | |||
| 857 | migan | 34 | class ServiceManager: |
| 856 | migan | 35 | services = {} |
| 36 | modules = {} |
||
| 37 | |||
| 38 | def __init__(self): |
||
| 39 | self.ImportAvailableServices() |
||
| 40 | |||
| 41 | def ImportAvailableServices(self): |
||
| 42 | servicesPath = Settings.Settings["PATH"] + "/Services" |
||
| 43 | sys.path.append(servicesPath) |
||
| 44 | |||
| 45 | for serviceName in os.listdir(servicesPath): |
||
| 46 | if serviceName[0] != '.' and serviceName.endswith(".py"): |
||
| 47 | serviceName = serviceName[:serviceName.find(".")] |
||
| 48 | self.modules[serviceName] = __import__(serviceName) |
||
| 49 | print "Loaded service: " + serviceName |
||
| 50 | |||
| 51 | print "" |
||
| 52 | |||
| 53 | def HasService(self, serviceId, serviceType): |
||
| 54 | return self.services.has_key(str(serviceType) + "_" + str(serviceId)) |
||
| 55 | |||
| 56 | def AddService(self, serviceId, serviceType): |
||
| 57 | if not self.HasService(serviceId, serviceType): |
||
| 58 | |||
| 59 | if self.modules[serviceType]: |
||
| 60 | self.services[str(serviceType) + "_" + str(serviceId)] = self.modules[serviceType].Service(serviceId) |
||
| 61 | else: |
||
| 62 | print "Warning: Unknown service: Type: " + serviceType |
||
| 63 | return False |
||
| 64 | |||
| 65 | return self.services[str(serviceType) + "_" + str(serviceId)] |
||
| 66 | |||
| 67 | def GetService(self, serviceId, serviceType): |
||
| 68 | return self.services[str(serviceType) + "_" + str(serviceId)] |
||
| 69 |