get rid of svn keywords once and for good
[plcapi.git] / PLC / Methods / UpdatePCUType.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.PCUTypes import PCUType, PCUTypes
5 from PLC.Auth import Auth
6
7 can_update = lambda (field, value): field in \
8              ['model', 'name']
9
10 class UpdatePCUType(Method):
11     """
12     Updates a PCU type. Only the fields specified in
13     pcu_typee_fields are updated, all other fields are left untouched.
14
15     Returns 1 if successful, faults otherwise.
16     """
17
18     roles = ['admin']
19
20     pcu_type_fields = dict(filter(can_update, PCUType.fields.items()))
21
22     accepts = [
23         Auth(),
24         PCUType.fields['pcu_type_id'],
25         pcu_type_fields
26         ]
27
28     returns = Parameter(int, '1 if successful')
29
30     def call(self, auth, pcu_type_id, pcu_type_fields):
31         pcu_type_fields = dict(filter(can_update, pcu_type_fields.items()))
32
33         pcu_types = PCUTypes(self.api, [pcu_type_id])
34         if not pcu_types:
35             raise PLCInvalidArgument, "No such pcu type"
36
37         pcu_type = pcu_types[0]
38         pcu_type.update(pcu_type_fields)
39         pcu_type.sync()
40         self.event_objects = {'PCUType': [pcu_type['pcu_type_id']]}
41
42         return 1