Skip to content
Snippets Groups Projects
Commit 93875f6b authored by jkerdreu's avatar jkerdreu
Browse files

Better way to produce files..=> next step use this to build JS ?

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2638 b32b6428-25c9-4566-ad07-03861ab6144f
parent 3738eb6d
No related branches found
No related tags found
No related merge requests found
from mako.template import Template
import sys
import os
import ujson
import json
from pprint import pprint
SCHEMA_DIR = '/home/jkx/Devel/xaal_schemas/branches/schemas-0.7'
BLACK_LIST=['application-layer.cddl',
......@@ -26,6 +26,15 @@ def name_to_method(name):
return name.replace('.','_')
def name_to_class(name):
if name.endswith('.basic'):
tmp = name.split('.basic')[0]
else:
tmp = name.replace('.','_')
return tmp[0].upper() + tmp[1:]
def dump(jsonDict):
print("=" * 80)
keys = list(jsonDict.keys())
......@@ -52,7 +61,7 @@ class Schemas:
path = os.path.join(SCHEMA_DIR,filename)
#print("Loading %s" % path)
data = open(path,'r').read()
jsonDict = ujson.decode(data)
jsonDict = json.loads(data)
self.__cache.update({filename:jsonDict})
return jsonDict
......@@ -139,9 +148,9 @@ class DeviceBuilder:
def get_schema(self,name):
return self.schemas.get(name)
def build(self,name):
def build(self,name,template):
data = self.schemas.get(name)
tmpl = Template(filename='dev.mako')
tmpl = Template(filename=template)
attributes = {}
for k in data['attributes']:
......@@ -164,6 +173,7 @@ class DeviceBuilder:
args = {}
args['name'] = name_to_method(name)
args['Name'] = name_to_class(name)
args['doc'] = data['description']
args['devtype'] = name
args['attributes'] = attributes
......@@ -173,22 +183,22 @@ class DeviceBuilder:
print(tmpl.render(**args))
#return args
def build_all(self):
def build_all(self,template):
devs = self.schemas.get_devtypes()
for k in devs:
self.build(k)
#print()
self.build(k,template)
def build_py(self):
head = open('./head_py.txt','r').read()
print(head)
self.build_all('devices_py.mako')
def build_js(self):
head = open('./head_js.txt','r').read()
print(head)
self.build_all('devices_js.mako')
db = DeviceBuilder()
#r = db.get_schema('thermometer.basic')
#r = db.build('lamp.dimmer')
#pprint(r)
#db.build('lamp.dimmer')
head = open('./head.txt','r').read()
print(head)
db.build_all()
#db.build_py()
db.build_js()
......@@ -28,8 +28,11 @@ def ${name}(addr=None):
% for meth in methods:
<%
keys = list(methods[meth].get('in',{}).keys())
tmp = map(lambda x: '_%s' % x,keys)
tmp = map(lambda x: '_%s=None' % x,keys)
args = ','.join(tmp)
print_keys = ','.join(map(lambda x: '_%s' % x,keys))
buf= ""
for k in keys:
buf=buf+"%s=[%%s]" % k+","
......@@ -38,7 +41,7 @@ def ${name}(addr=None):
% if len(args) == 0:
logger.info("default_${meth}()")
% else:
logger.info("default_${meth}(${buf})" % (${args}))
logger.info("default_${meth}(${buf})" % (${print_keys}))
% endif
% endfor
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment