Class implementation of an BOSWatch packet.
More...
|
| | __init__ (self, bwPacket=None) |
| | Build a new BOSWatch packet or copy existing data in it.
|
| |
| | __str__ (self) |
| | Return the intern _packet dict as string.
|
| |
| | set (self, fieldName, value) |
| | Set a field in the intern _packet dict.
|
| |
| | get (self, fieldName) |
| | Returns the value from a single field.
|
| |
| | printInfo (self) |
| | Print a info message to the log on INFO level.
|
| |
Class implementation of an BOSWatch packet.
◆ __init__()
| boswatch.packet.Packet.__init__ |
( |
|
self, |
|
|
|
bwPacket = None |
|
) |
| |
Build a new BOSWatch packet or copy existing data in it.
- Parameters
-
| bwPacket | Existing data to copy |
27 def __init__(self, bwPacket=None):
28 r"""!Build a new BOSWatch packet or copy existing data in it
29
30 @param bwPacket: Existing data to copy"""
31 if bwPacket is None:
32 logging.debug("create new bwPacket")
33 self._packet = {"timestamp": time.time()}
34 else:
35 logging.debug("create bwPacket from string")
36 try:
37 self._packet = ast.literal_eval(str(bwPacket).strip())
38 except (ValueError, SyntaxError) as e:
39 logging.error("Failed to parse bwPacket (Size: %d): %s | Data: %.1000s", len(str(bwPacket)), e, str(bwPacket).strip())
40 raise
41
◆ __str__()
| boswatch.packet.Packet.__str__ |
( |
|
self | ) |
|
Return the intern _packet dict as string.
42 def __str__(self):
43 r"""!Return the intern _packet dict as string"""
44 return str(self._packet)
45
◆ set()
| boswatch.packet.Packet.set |
( |
|
self, |
|
|
|
fieldName, |
|
|
|
value |
|
) |
| |
Set a field in the intern _packet dict.
- Parameters
-
| fieldName | Name of the data to set |
| value | Value to set |
46 def set(self, fieldName, value):
47 r"""!Set a field in the intern _packet dict
48
49 @param fieldName: Name of the data to set
50 @param value: Value to set"""
51 self._packet[fieldName] = str(value)
52
◆ get()
| boswatch.packet.Packet.get |
( |
|
self, |
|
|
|
fieldName |
|
) |
| |
Returns the value from a single field.
If field not existing None is returned
- Parameters
-
| fieldName | Name of the field |
- Returns
- Value or None
53 def get(self, fieldName):
54 r"""!Returns the value from a single field.
55 If field not existing `None` is returned
56
57 @param fieldName: Name of the field
58 @return Value or None"""
59 try:
60 return str(self._packet[fieldName])
61 except:
62 logging.warning("field not found: %s", fieldName)
63 return None
64
◆ printInfo()
| boswatch.packet.Packet.printInfo |
( |
|
self | ) |
|
Print a info message to the log on INFO level.
Contains the most useful info about this packet.
- Todo:
- not complete yet - must be edit to print nice formatted messages on console
65 def printInfo(self):
66 r"""!Print a info message to the log on INFO level.
67 Contains the most useful info about this packet.
68 @todo not complete yet - must be edit to print nice formatted messages on console
69 """
70 logging.info("[%s]", self.get("mode"))
◆ _packet
| boswatch.packet.Packet._packet |
|
protected |