@@ -33,6 +33,8 @@ def location(version):
3333template_files = [{"filename" : "cimpy_class_template.mustache" , "ext" : ".py" }]
3434enum_template_files = [{"filename" : "pydantic_enum_template.mustache" , "ext" : ".py" }]
3535
36+ required_profiles = ["EQ" , "GL" ] #temporary
37+
3638def get_class_location (class_name , class_map , version ):
3739 # Check if the current class has a parent class
3840 if class_map [class_name ].superClass ():
@@ -53,7 +55,7 @@ def _compute_data_type(attribute):
5355
5456 if "range" in attribute :
5557 # return "'"+attribute["range"].split("#")[1]+"'"
56- return "'" + attribute ["range" ].split ("#" )[1 ]+ "'"
58+ return attribute ["range" ].split ("#" )[1 ]
5759 if "dataType" in attribute and "class_name" in attribute :
5860 # for whatever weird reason String is not created as class from CIMgen
5961 if is_primitive_class (attribute ["class_name" ]) or attribute ["class_name" ] == "String" :
@@ -84,7 +86,7 @@ def _compute_data_type(attribute):
8486 if is_cim_data_type_class (attribute ["class_name" ]):
8587 return "float"
8688 # this is for example the case for 'StreetAddress.streetDetail'
87- return "'" + attribute ["dataType" ].split ("#" )[1 ]+ "'"
89+ return attribute ["dataType" ].split ("#" )[1 ]
8890
8991def _ends_with_s (attribute_name ):
9092 return attribute_name .endswith ("s" )
@@ -252,6 +254,12 @@ def has_unit_attribute(attributes):
252254 return True
253255 return False
254256
257+ def is_required_profile (class_origin ):
258+ for origin in class_origin :
259+ if origin ["origin" ] in required_profiles :
260+ return True
261+ return False
262+
255263def run_template (version_path , class_details ):
256264 if (
257265 # Primitives are never used in the in memory representation but only for
@@ -260,6 +268,7 @@ def run_template(version_path, class_details):
260268 # Datatypes based on primitives are never used in the in memory
261269 # representation but only for the schema
262270 or class_details ["is_a_cim_data_type" ] == True
271+ or class_details ["class_name" ] == 'PositionPoint'
263272 ):
264273 return
265274 elif class_details ["has_instances" ] == True :
@@ -269,47 +278,59 @@ def run_template(version_path, class_details):
269278
270279def run_template_enum (version_path , class_details , templates ):
271280 for template_info in templates :
272- class_file = os .path .join (version_path , class_details [ "class_name" ] + template_info ["ext" ])
281+ class_file = os .path .join (version_path , "enum" + template_info ["ext" ])
273282 if not os .path .exists (class_file ):
274283 with open (class_file , "w" , encoding = "utf-8" ) as file :
275- template_path = os .path .join (os .getcwd (), "modernpython/templates" , template_info ["filename" ])
276- class_details ["setInstances" ] = _set_instances
277- with open (template_path , encoding = "utf-8" ) as f :
278- args = {
279- "data" : class_details ,
280- "template" : f ,
281- "partials_dict" : partials ,
282- }
283- output = chevron .render (** args )
284- file .write (output )
284+ header_file_path = os .path .join (
285+ os .getcwd (), "modernpython" , "enum_header.py"
286+ )
287+ header_file = open (header_file_path , "r" )
288+ file .write (header_file .read ())
289+ with open (class_file , "a" , encoding = "utf-8" ) as file :
290+ template_path = os .path .join (os .getcwd (), "modernpython/templates" , template_info ["filename" ])
291+ class_details ["setInstances" ] = _set_instances
292+ with open (template_path , encoding = "utf-8" ) as f :
293+ args = {
294+ "data" : class_details ,
295+ "template" : f ,
296+ "partials_dict" : partials ,
297+ }
298+ output = chevron .render (** args )
299+ file .write (output )
285300
286301def run_template_schema (version_path , class_details , templates ):
287302 for template_info in templates :
288- class_file = os .path .join (version_path , class_details [ "class_name" ] + template_info ["ext" ])
303+ class_file = os .path .join (version_path , "schema" + template_info ["ext" ])
289304 if not os .path .exists (class_file ):
290305 with open (class_file , "w" , encoding = "utf-8" ) as file :
291- template_path = os .path .join (os .getcwd (), "modernpython/templates" , template_info ["filename" ])
292- class_details ["setDefault" ] = _set_default
293- class_details ["setType" ] = _set_type
294- class_details ["setImports" ] = _set_imports
295- class_details ["setValidator" ] = _set_validator
296- class_details ["setNormalizedName" ] = _set_normalized_name
297- with open (template_path , encoding = "utf-8" ) as f :
298- args = {
299- "data" : class_details ,
300- "template" : f ,
301- "partials_dict" : partials ,
302- }
303- output = chevron .render (** args )
304- file .write (output )
306+ schema_file_path = os .path .join (
307+ os .getcwd (), "modernpython" , "schema_header.py"
308+ )
309+ schema_file = open (schema_file_path , "r" )
310+ file .write (schema_file .read ())
311+ with open (class_file , "a" , encoding = "utf-8" ) as file :
312+ template_path = os .path .join (os .getcwd (), "modernpython/templates" , template_info ["filename" ])
313+ class_details ["setDefault" ] = _set_default
314+ class_details ["setType" ] = _set_type
315+ class_details ["setImports" ] = _set_imports
316+ class_details ["setValidator" ] = _set_validator
317+ class_details ["setNormalizedName" ] = _set_normalized_name
318+ with open (template_path , encoding = "utf-8" ) as f :
319+ args = {
320+ "data" : class_details ,
321+ "template" : f ,
322+ "partials_dict" : partials ,
323+ }
324+ output = chevron .render (** args )
325+ file .write (output )
305326
306327
307328def _create_init (path ):
308329 init_file = path + "/__init__.py"
309330
310331 with open (init_file , "w" , encoding = "utf-8" ) as init :
311- init .write ("# pylint: disable=too-many-lines,missing-module-docstring\n " )
312-
332+ # init.write("# pylint: disable=too-many-lines,missing-module-docstring\n")
333+ pass
313334
314335# creates the Base class file, all classes inherit from this class
315336def _create_base (path ):
0 commit comments