/usr/lib/python2.7/dist-packages/pyrrd/mapper.py is in python-pyrrd 0.1.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | from pyrrd.node import RRDXMLNode
class DSMixin(object):
def __init__(self):
self.ds = []
class Mapper(object):
"""
"""
__slots__ = []
__skip_repr__ = []
def setAttributes(self, attributes):
for name, value in attributes.items():
if name not in self.__skip_repr__:
setattr(self, name, value)
def getData(self):
items = {}
for name in self.__slots__:
if name not in self.__skip_repr__:
items[name] = getattr(self, name, None)
return items
def map(self, node):
"""
"""
self.setAttributes(node.attributes)
def printInfo(self):
for name, value in self.getData().items():
if value is None:
continue
print "%s = %s" % (name, unicode(value))
class RowMapper(Mapper):
"""
"""
__slots__ = ["v"]
class DatabaseMapper(Mapper):
"""
"""
__slots__ = ["rows"]
__skip_repr__ = ["rows"]
def __init__(self):
self.rows = []
class CDPrepDSMapper(Mapper):
"""
"""
__slots__ = [
"primary_value",
"secondary_value",
"value",
"unknown_datapoints",
]
def printInfo(self, prefix, index):
for name, value in self.getData().items():
if value is None:
continue
print "%s.cdp_prep[%s].%s = %s" % (
prefix, index, name, unicode(value))
class CDPPrepMapper(Mapper, DSMixin):
"""
"""
__slots__ = ["ds"]
__skip_repr__ = ["ds"]
class RRAMapper(Mapper, DSMixin):
"""
"""
__slots__ = [
"cf",
"pdp_per_row",
"xff",
"cdp_prep",
"ds",
"steps",
"rows",
"alpha",
"beta",
"seasonal_period",
"rra_num",
"gamma",
"threshold",
"window_length",
"database",
]
__skip_repr__ = ["ds"]
def map(self, node):
super(RRAMapper, self).map(node)
for subNode in node.cdp_prep.ds:
ds = CDPrepDSMapper()
ds.map(subNode)
self.ds.append(ds)
def getData(self):
data = super(RRAMapper, self).getData()
data["ds"] = [ds.getData() for ds in self.ds]
return data
def printInfo(self, index):
prefix = "rra[%s]" % index
for name, value in self.getData().items():
if value is None:
continue
print "%s.%s = %s" % (prefix, name, unicode(value))
for index, ds in enumerate(self.ds):
ds.printInfo(prefix, index)
class DSMapper(Mapper):
"""
"""
__slots__ = [
"name",
"type",
"minimal_heartbeat",
"min",
"max",
"last_ds",
"value",
"unknown_sec",
"rpn",
]
def printInfo(self):
for name, value in self.getData().items():
if value is None:
continue
if name != self.name:
print "ds[%s].%s = %s" % (self.name, name, unicode(value))
class RRDMapper(Mapper, DSMixin):
"""
"""
__slots__ = [
"version",
"step",
"lastupdate",
"ds",
"rra",
"values",
"start",
"mode",
"filename",
]
__skip_repr__ = ["ds", "rra", "mode"]
def __init__(self):
self.mode = None
super(RRDMapper, self).__init__()
self.rra = []
def getData(self):
"""
"""
if not (self.ds or self.rra):
self.map()
data = super(RRDMapper, self).getData()
data["ds"] = [ds.getData() for ds in self.ds]
data["rra"] = [rra.getData() for rra in self.rra]
return data
def printInfo(self):
super(RRDMapper, self).printInfo()
for ds in self.ds:
ds.printInfo()
for index, rra in enumerate(self.rra):
rra.printInfo(index)
def map(self):
"""
The map method does several things:
1) if the RRD object (instantiated from this class or a subclass)
is in "write" mode, there is no need to parse the XML and map
it; there is already an object representation. In this case, the
majority of this method is skipped.
2) if the RRD object is in "read" mode, it needs to pull data out
of the rrd file; it does this by loading (which dumps to XML and
then reads in the XML).
3) once the XML has been parsed, it maps the XML to objects.
"""
if self.mode == "w":
return
# The backend is defined by the subclass of this class, as is the
# filename.
tree = self.backend.load(self.filename)
node = RRDXMLNode(tree)
super(RRDMapper, self).map(node)
for subNode in node.ds:
ds = DSMapper()
ds.map(subNode)
self.ds.append(ds)
for subNode in node.rra:
rra = RRAMapper()
rra.map(subNode)
self.rra.append(rra)
|