1 # vim: set encoding=utf-8 et sw=4 sts=4 :
3 from pymin.seqtools import Sequence
4 from pymin.dispatcher import handler
5 from pymin.service.util import SubHandler, ContainerNotFoundError, \
6 ItemNotFoundError, ItemAlreadyExistsError
8 __all__ = ('ClassHandler',)
11 class Class(Sequence):
13 def __init__(self, cid, rate=None):
19 return (self.cid, self.rate)
21 def __cmp__(self, other):
22 if self.cid == other.cid:
24 return cmp(id(self), id(other))
27 class ClassHandler(SubHandler):
29 def __init__(self, parent):
32 @handler('Adds a class : add <id> <device> <rate>')
33 def add(self, dev, cid, rate):
34 if not dev in self.parent.devices:
35 raise ContainerNotFoundError(dev)
38 self.parent.devices[dev].classes[cid] = Class(cid, rate)
40 raise ItemAlreadyExistsError(cid + ' -> ' + dev)
42 @handler(u'Deletes a class : delete <id> <device>')
43 def delete(self, dev, cid):
44 if not dev in self.parent.devices:
45 raise ContainerNotFoundError(dev)
48 del self.parent.devices[dev].classes[cid]
50 raise ItemNotFoundError(cid + ' -> ' + dev)
52 @handler(u'Lists classes : list <dev>')
55 k = self.parent.devices[dev].classes.items()