iro/providerlist.py
branchdevel
changeset 240 3406d3bf05d4
parent 239 4cf5e664c847
child 241 546316b0b09c
equal deleted inserted replaced
239:4cf5e664c847 240:3406d3bf05d4
     1 # -*- coding: utf-8 -*-
       
     2 #Copyright (C) 2009  Sandro Knauß <bugs@sandroknauss.de>
       
     3 
       
     4 #This program is free software; you can redistribute it and/or modify it under the terms
       
     5 #of the GNU General Public License as published by the Free Software Foundation;
       
     6 #either version 3 of the License, or any later version.
       
     7 #This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
       
     8 #without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
       
     9 #See the GNU General Public License for more details.
       
    10 
       
    11 #You should have received a copy of the GNU General Public License
       
    12 #along with this program; if not, see <http://www.gnu.org/licenses/>.
       
    13 
       
    14 class Providerlist:
       
    15     def __init__(self):
       
    16         self.provider={}
       
    17         self.types={}
       
    18         self.defaults={}
       
    19         
       
    20     def add(self, name, provider, typeslist):
       
    21         self.provider[name]={"name":name, "class":provider, "types":typeslist}
       
    22         for stype in typeslist:
       
    23             try:
       
    24                 self.types[stype].append(self.provider[name])
       
    25             except KeyError:
       
    26                 self.types[stype]=[self.provider[name]]
       
    27             
       
    28     
       
    29     def setDefault(self, stype, name):
       
    30         self.defaults[stype]=self.provider[name]
       
    31     
       
    32     def getDefault(self, stype):
       
    33         return self.defaults[stype]
       
    34     
       
    35     def getProviderlist(self, stype):
       
    36         llist=[ provider["name"] for provider in self.types[stype] ]
       
    37         llist.sort()
       
    38         return llist
       
    39 
       
    40     def status(self):
       
    41         ret="provider:%s"%self.provider
       
    42         ret +="\ntypes:%s"%self.types
       
    43         return ret+"\ndefaults:%s"%self.defaults
       
    44 
       
    45     def getProvider(self, stype,  name="default"):
       
    46         if name=="default":
       
    47             return self.getDefault(stype)["class"]
       
    48 
       
    49         if not stype in self.provider[name] ["types"]:
       
    50             raise Exception("argh")
       
    51 
       
    52         return self.provider[name]["class"]