Skip to content

Commit

Permalink
Merge branch 'release/1.0.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
eedgar committed Aug 7, 2013
2 parents 0f7a227 + f3c3dc3 commit ce3b198
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 10 deletions.
29 changes: 29 additions & 0 deletions examples/deviceproperties.json
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
14 changes: 8 additions & 6 deletions zpg/Component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand All @@ -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()
Expand Down
23 changes: 22 additions & 1 deletion zpg/Property.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import inflect
from lxml import etree
import re

plural = inflect.engine().plural

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion zpg/Templates/component.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ()
Expand Down
2 changes: 1 addition & 1 deletion zpg/_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'author': 'ZenossLabs <[email protected]>',
'author_email': '[email protected]',
'description': 'A tool to assist building zenpacks.',
'version': '1.0.9',
'version': '1.0.10',
'license': 'GPLv2',
'component_classes': [
'Products.ZenModel.DeviceComponent.DeviceComponent',
Expand Down

0 comments on commit ce3b198

Please sign in to comment.