summaryrefslogtreecommitdiff
path: root/src/scripts/pyolian/generator.py
diff options
context:
space:
mode:
authorDave Andreoli <dave@gurumeditation.it>2018-01-02 15:43:15 +0100
committerDave Andreoli <dave@gurumeditation.it>2018-01-02 15:44:43 +0100
commitb9ed84f4edc505737c9f9d034c24e080f5fa2242 (patch)
treeecf4a5ef8159391c2840bdd6bb1c3f77829f4e85 /src/scripts/pyolian/generator.py
parentb8f4dc296ff1e95e6c2a88b7071e3ed8e2dffd86 (diff)
Pyolian: implement an utility class: Namspace
Update tests and generator to use this new feature
Diffstat (limited to 'src/scripts/pyolian/generator.py')
-rwxr-xr-xsrc/scripts/pyolian/generator.py23
1 files changed, 7 insertions, 16 deletions
diff --git a/src/scripts/pyolian/generator.py b/src/scripts/pyolian/generator.py
index 2640bfaf40..140b620a6d 100755
--- a/src/scripts/pyolian/generator.py
+++ b/src/scripts/pyolian/generator.py
@@ -90,9 +90,9 @@ class Template(pyratemp.Template):
90 90
91 Args: 91 Args:
92 filename: Template file to load. (REQUIRED) 92 filename: Template file to load. (REQUIRED)
93 data: User provided context for the template. 93 context: User provided context for the template (dict).
94 """ 94 """
95 def __init__(self, filename, encoding='utf-8', data=None, escape=None, 95 def __init__(self, filename, encoding='utf-8', context=None, escape=None,
96 loader_class=pyratemp.LoaderFile, 96 loader_class=pyratemp.LoaderFile,
97 parser_class=pyratemp.Parser, 97 parser_class=pyratemp.Parser,
98 renderer_class=pyratemp.Renderer, 98 renderer_class=pyratemp.Renderer,
@@ -101,8 +101,8 @@ class Template(pyratemp.Template):
101 # Build the global context for the template 101 # Build the global context for the template
102 global_ctx = {} 102 global_ctx = {}
103 # user provided context (low pri) 103 # user provided context (low pri)
104 if data: 104 if context:
105 global_ctx.update(data) 105 global_ctx.update(context)
106 # standard names (not overwritables) 106 # standard names (not overwritables)
107 global_ctx.update({ 107 global_ctx.update({
108 # Template info 108 # Template info
@@ -164,23 +164,14 @@ class Template(pyratemp.Template):
164 ctx.update(kargs) 164 ctx.update(kargs)
165 if cls: 165 if cls:
166 ctx['cls'] = eolian_db.class_get_by_name(cls) 166 ctx['cls'] = eolian_db.class_get_by_name(cls)
167 if ns:
168 ctx['namespace'] = eolian_db.namespace_get_by_name(ns)
167 if struct: 169 if struct:
168 ctx['struct'] = eolian_db.typedecl_struct_get_by_name(struct) 170 ctx['struct'] = eolian_db.typedecl_struct_get_by_name(struct)
169 if enum: 171 if enum:
170 ctx['enum'] = eolian_db.typedecl_enum_get_by_name(enum) 172 ctx['enum'] = eolian_db.typedecl_enum_get_by_name(enum)
171 if alias: 173 if alias:
172 ctx['alias'] = eolian_db.typedecl_alias_get_by_name(alias) 174 ctx['alias'] = eolian_db.typedecl_alias_get_by_name(alias)
173 if ns:
174 ctx['namespace'] = ns
175 ctx['namespaces'] = ns.split('.')
176 ctx['classes'] = [ c for c in eolian_db.all_classes
177 if c.full_name.startswith(ns + '.') ]
178 ctx['aliases'] = [ a for a in eolian_db.typedecl_all_aliases
179 if a.full_name.startswith(ns + '.') ]
180 ctx['structs'] = [ s for s in eolian_db.typedecl_all_structs
181 if s.full_name.startswith(ns + '.') ]
182 ctx['enums'] = [ e for e in eolian_db.typedecl_all_enums
183 if e.full_name.startswith(ns + '.') ]
184 175
185 if verbose and filename: 176 if verbose and filename:
186 print('generating "{}" from template "{}"'.format( 177 print('generating "{}" from template "{}"'.format(
@@ -205,7 +196,7 @@ class Template(pyratemp.Template):
205if __name__ == '__main__': 196if __name__ == '__main__':
206 import argparse 197 import argparse
207 198
208 parser = argparse.ArgumentParser(description='Pyolian generator.') 199 parser = argparse.ArgumentParser(description='Pyolian template based generator.')
209 parser.add_argument('template', 200 parser.add_argument('template',
210 help='The template file to use. (REQUIRED)') 201 help='The template file to use. (REQUIRED)')
211 parser.add_argument('--output', '-o', metavar='FILE', default=None, 202 parser.add_argument('--output', '-o', metavar='FILE', default=None,