diff --git a/examples/deviceproperties.json b/examples/deviceproperties.json new file mode 100644 index 0000000..ee38690 --- /dev/null +++ b/examples/deviceproperties.json @@ -0,0 +1,29 @@ +{ + "deviceClasses": [ { + "deviceType": + { "name": "ExampleDevice", + "properties": [ + { "Type": "list", + "name": "array_param", + "value": ["a","b"] + }, + { "Type": "int", + "name": "int_param", + "value": 4 + }, + { "Type": "boolean", + "name": "bool_param", + "value": true + }, + { "name": "string_param", + "value": "Default String" + }, + { "name": "string_param2" + } + ] + }, + "path": "Device" + } + ], + "id": "ZenPacks.training.DeviceProperties" +} diff --git a/setup.py b/setup.py index 815bab3..e653d24 100644 --- a/setup.py +++ b/setup.py @@ -52,7 +52,7 @@ setup( name="zpg", - version=defaults.get("version", "0.0.1"), # zpg.__version__ + version=defaults.get("version", "0.0.1"), # zpg.__version__ description="ZenPack Generator", long_description=open('README.rst').read() + '\n\n' + open('HISTORY.rst').read(), diff --git a/zpg/Component.py b/zpg/Component.py index c38ef9e..acf499f 100644 --- a/zpg/Component.py +++ b/zpg/Component.py @@ -338,8 +338,8 @@ def lookup(self, zenpack, component_id, create=True): def addComponentType(self, *args, **kwargs): """add a subcomponent""" - type_ = '1-1' - contained = 'True' + type_ = '1-M' + contained = True if 'zenpack' in kwargs: del(kwargs['zenpack']) if 'type_' in kwargs: @@ -350,7 +350,8 @@ def addComponentType(self, *args, **kwargs): del(kwargs['contained']) c = Component(self.zenpack, *args, **kwargs) self.components[c.id] = c - Relationship(self.zenpack, self.id, c.id, type_=type_, contained=contained) + Relationship(self.zenpack, self.id, c.id, type_=type_, + contained=contained) return c def updateImports(self): @@ -371,9 +372,10 @@ def updateImports(self): Types['ToOne'] = 1 if 'M-' in relationship.type_: Types['ToMany'] = 1 - imports = "from Products.ZenRelations.RelSchema import %s" % ", ".join( - sorted(Types.keys())) - self.imports.append(imports) + if len(Types.keys()) > 0: + imports = "from Products.ZenRelations.RelSchema import %s" %\ + ", ".join(sorted(Types.keys())) + self.imports.append(imports) def f7(seq): seen = set() diff --git a/zpg/Property.py b/zpg/Property.py index de73369..de15c37 100644 --- a/zpg/Property.py +++ b/zpg/Property.py @@ -10,6 +10,7 @@ import inflect from lxml import etree +import re plural = inflect.engine().plural @@ -48,7 +49,6 @@ def __init__(self, self.name = name self.names = plural(name) self.mode = 'w' - self.value = value self.detailDisplay = detailDisplay self.gridDisplay = gridDisplay self.sortable = True @@ -120,6 +120,27 @@ def value(self, value): """Input validation for the value""" # Valid values can be implemented later. self._value = 'None' if value is None else value + if self.type_ == 'list' or self.type_ == 'lines': + self._value = [] + for item in value: + if isinstance(item, unicode): + self._value.append(item.encode('utf-8')) + else: + self._value.append(item) + + @property + def quoted_value(self): + value = self.value + if value == 'None': + return value + if value is not None and self.type_ == 'string': + if not value.startswith('\''): + value = '\'' + value + if len(value) == 1: + value = value + '\'' + if not value.endswith('\''): + value = value + '\'' + return value def to_objects_xml(self): o = etree.Element("property") diff --git a/zpg/Templates/component.tmpl b/zpg/Templates/component.tmpl index 21d13fb..7328f73 100644 --- a/zpg/Templates/component.tmpl +++ b/zpg/Templates/component.tmpl @@ -16,7 +16,7 @@ class ${shortklass}(#echo ', '.join($klassNames)#): #if $properties #for $key in $properties #set $p=$properties[key] - $p.id = $p.value + $p.id = $p.quoted_value #end for _properties = () diff --git a/zpg/_defaults.py b/zpg/_defaults.py index 6eaec9e..e44b3e8 100644 --- a/zpg/_defaults.py +++ b/zpg/_defaults.py @@ -26,7 +26,7 @@ 'author': 'ZenossLabs ', 'author_email': 'labs@zenoss.com', 'description': 'A tool to assist building zenpacks.', - 'version': '1.0.9', + 'version': '1.0.10', 'license': 'GPLv2', 'component_classes': [ 'Products.ZenModel.DeviceComponent.DeviceComponent',