~chris-rogers/mcdb/mice.cdb.client.api-python_devel

« back to all changes in this revision

Viewing changes to src/cdb/_alarmhandler_supermouse.py

  • Committer: Antony Wilson
  • Date: 2011-11-01 14:26:29 UTC
  • Revision ID: antony.wilson@stfc.ac.uk-20111101142629-vrhr4ip2vx08m4i4
interim commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"AlarmHandlerSuperMouse module."
 
2
 
 
3
from xml.sax import parseString
 
4
 
 
5
from cdb._alarmhandler import AlarmHandler
 
6
from cdb._base import _get_string_from_date
 
7
 
 
8
__all__ = ["AlarmHandlerSuperMouse"]
 
9
 
 
10
class AlarmHandlerSuperMouse(AlarmHandler):
 
11
    
 
12
    """
 
13
The AlarmHandlerSuperMouse class is used to store and retrieve Alarm Handlers (ALH).
 
14
 
 
15
The CDB keeps track of when an ALH was in use. An ALH is associated with a tag
 
16
and retrieved via that tag, get_tagged_alh. It is also possible to associate a
 
17
new ALH with an existing tag; the old ALH is stored for diagnostic purposes.
 
18
 
 
19
A couple of methods are provided for diagnostics. It is possible to retrieve a
 
20
list of tags that were in use over a given time period, get_used_tags, and to
 
21
retrieve the values of an ALH that was in use at a given time, get_used_alh.
 
22
 
 
23
 
 
24
        """
 
25
    
 
26
    def __init__(self):
 
27
        """
 
28
Construct an AlarmHandlerSuperMouse.
 
29
 
 
30
@exception CdbPermanentError: Unable to contact CDB server or invalid URL
 
31
 
 
32
        """
 
33
        super(AlarmHandlerSuperMouse,
 
34
              self).__init__("/cdb/alarmHandlerSuperMouse?wsdl")
 
35
       
 
36
    def __str__(self):
 
37
        return "AlarmHandlerSuperMouse \
 
38
        \n\tset_url(string url) \
 
39
        \n\tget_status() \
 
40
        \n\tget_tagged_alh(string tag) \
 
41
        \n\tget_used_alh(datetime timestamp) \
 
42
        \n\tget_used_tags(datetime start_time, datetime stop_time) \
 
43
        \n\tlist_tags() \
 
44
        \n\tset_tagged_alh(string tag, [{string name, string hihi, string hi, string lo, string lolo}] alarms) \
 
45
        \n\tset_tag_in_use(string tag, datetime creation_time)"
 
46
 
 
47
 
 
48
    def set_tagged_alh(self, tag, alarms):
 
49
        """
 
50
Set the values of the alarm handler with the given tag. If an alarm handler with
 
51
the tag already exists then the passed in alarm handler will become the new
 
52
alarm handler for that tag. If there is an old alarm handler that has been used,
 
53
it will be accessible via the get_used_tags and get_used_alh methods.
 
54
    
 
55
@param tag: the name of the tag
 
56
@param alarms: a list dictionaries containing the alarm handler data:<pre>
 
57
        keys: 'name', 'hihi', 'hi', 'lo', 'lolo'</pre>
 
58
 
 
59
@return a string containing a status message
 
60
 
 
61
@exception CdbTemporaryError: The problem maybe transient and retrying the
 
62
request MAY succeed
 
63
@exception CdbPermanentError: Maybe due to to bad data being passed in or an
 
64
unexpected internal error
 
65
 
 
66
        """
 
67
        _alarm_xml = "<alarmhandler>"
 
68
        for _alarm in alarms:
 
69
            _alarm_xml = (_alarm_xml + "<alarm>" 
 
70
                          + "<name>" + str(_alarm["name"]) + "</name>"
 
71
                          + "<hihi>" + str(_alarm["hihi"]) + "</hihi>"
 
72
                          + "<hi>" + str(_alarm["hi"]) + "</hi>"
 
73
                          + "<lo>" + str(_alarm["lo"]) + "</lo>"
 
74
                          + "<lolo>" + str(_alarm["lolo"]) + "</lolo>"
 
75
                          + "</alarm>")
 
76
        _alarm_xml = _alarm_xml + "</alarmhandler>" 
 
77
            
 
78
        xml = str(self._client.setTaggedALH(str(tag), _alarm_xml))
 
79
        parseString(xml, self._status_handler)
 
80
        return self._status_handler.get_message()
 
81
            
 
82
    def set_tag_in_use(self, tag, creation_time):
 
83
        """
 
84
Record the fact that the alarm handler with the given tag and creation time is
 
85
now in use. Only one alarm handler maybe in use at a time. A call to this method
 
86
will supersede all previous calls to this method.
 
87
    
 
88
@param tag: the name of the tag
 
89
@param creation_time: the datetime of when the alarm handler was created in UTC
 
90
 
 
91
@return a string containing a status message
 
92
 
 
93
@exception CdbTemporaryError: The problem maybe transient and retrying the
 
94
request MAY succeed
 
95
@exception CdbPermanentError: Maybe due to to bad data being passed in or an
 
96
unexpected internal error
 
97
 
 
98
        """
 
99
        creation_time = _get_string_from_date(creation_time)
 
100
        xml = str(self._client.setTagInUse(str(tag), creation_time))
 
101
        parseString(xml, self._status_handler)
 
102
        return self._status_handler.get_message()
 
103