33 from pkg_resources
import resource_filename
34 from lxml
import etree
35 from .
import ManifestException
39 if value ==
"yes" or \
51 tree = etree.parse(filename)
54 schemaDoc = etree.parse(resource_filename(
'emane.shell',
55 'schema/manifest.xsd'))
57 schema = etree.XMLSchema(etree=schemaDoc,attribute_defaults=
True)
61 for entry
in schema.error_log:
62 message +=
"%d: %s" % (entry.line,entry.message)
63 raise ManifestException(message)
65 self.
_name = root.xpath(
'/manifest/plugin/@name')[0]
67 for parameter
in root.xpath(
'/manifest/plugin/configuration/parameter'):
70 values = parameter.xpath(
'.//values')[0]
74 descriptions = parameter.xpath(
'.//description')
77 description = descriptions[0].text
81 regexes = parameter.xpath(
'.//regex')
84 regex = regexes[0].text
86 entry = {
'default' :
toBool(parameter.get(
'default')),
87 'required' :
toBool(parameter.get(
'required')),
88 'modifiable' :
toBool(parameter.get(
'modifiable')),
89 'description' : description,
91 'minOccurs' : int(values.get(
"minOccurs")),
92 'maxOccurs' : int(values.get(
"maxOccurs")),
93 'values' : [x.text
for x
in values.xpath(
'value')]}
95 numeric = parameter.xpath(
'numeric')
100 entry[
'numeric'] = {
'type' : numeric.get(
'type'),
101 'minValue' : numeric.get(
'minValue'),
102 'maxValue' : numeric.get(
'maxValue') }
104 nonnumeric = parameter.xpath(
'nonnumeric')[0]
105 entry[
'nonnumeric'] = {
'type' : nonnumeric.get(
'type')}
110 for element
in root.xpath(
'/manifest/plugin/statistics/element'):
113 descriptions = element.xpath(
'description')
116 description = descriptions[0].text
118 self.
_statistics[element.get(
'name')] = {
'type' : element.get(
'type'),
119 'clearable':
toBool(element.get(
'clearable')),
120 'description' : description}
122 for table
in root.xpath(
'/manifest/plugin/statistictables/table'):
125 descriptions = table.xpath(
'description')
128 description = descriptions[0].text
130 self.
_tables[table.get(
'name')] = {
'description' : description,
131 'clearable':
toBool(table.get(
'clearable'))}
142 if value[
'modifiable']]
148 return [name
for name,value
in list(self.
_statistics.items())
149 if value[
'clearable']]
152 return [name
for name,value
in list(self.
_tables.items())
153 if value[
'clearable']]
156 return list(self.
_tables.keys())
162 raise ManifestException(
"unknown configuration parameter: %s" % name)
168 raise ManifestException(
"unknown statistic element: %s" % name)
174 raise ManifestException(
"unknown table: %s" % name)
def getTableInfo(self, name)
def getAllConfiguration(self)
def getAllStatistics(self)
def getModifiableConfiguration(self)
def getClearableTables(self)
def getConfigurationInfo(self, name)
def __init__(self, filename)
def getStatisticInfo(self, name)
def getClearableStatistics(self)