Skip to content

Commit

Permalink
Rename class and attribute property "is_a_primitive"-->"is_a_primitiv…
Browse files Browse the repository at this point in the history
…e_class", "is_a_cim_datatype" --> "is_a_datatype_class", "is_cim_datatype" --> "is_datatype_attribute"

Signed-off-by: HUG0-D <[email protected]>
  • Loading branch information
HUG0-D committed Nov 18, 2024
1 parent df38527 commit 73ff2ac
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
23 changes: 11 additions & 12 deletions cimgen/cimgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ def is_a_float_class(self):
return False
return True

def is_a_primitive(self):
def is_a_primitive_class(self):
return self.stereotype == "Primitive"

def is_a_cim_datatype(self):
def is_a_datatype_class(self):
return self.stereotype == "CIMDatatype"


Expand Down Expand Up @@ -475,13 +475,13 @@ def _write_python_files(elem_dict, lang_pack, output_path, version):
lang_pack.setup(output_path, _get_profile_details(package_listed_by_short_name), cim_namespace)

primitive_classes = []
cim_data_type_classes = []
datatype_classes = []
# Iterate over Classes
for class_definition in elem_dict:
if elem_dict[class_definition].is_a_primitive():
if elem_dict[class_definition].is_a_primitive_class():
primitive_classes.append(class_definition)
if elem_dict[class_definition].is_a_cim_datatype():
cim_data_type_classes.append(class_definition)
if elem_dict[class_definition].is_a_datatype_class():
datatype_classes.append(class_definition)

recommended_class_profiles = _get_recommended_class_profiles(elem_dict)

Expand All @@ -495,8 +495,8 @@ def _write_python_files(elem_dict, lang_pack, output_path, version):
"enum_instances": elem_dict[class_name].enum_instances(),
"is_an_enum_class": elem_dict[class_name].is_an_enum_class(),
"is_a_float_class": elem_dict[class_name].is_a_float_class(),
"is_a_primitive": elem_dict[class_name].is_a_primitive(),
"is_a_cim_data_type": elem_dict[class_name].is_a_cim_datatype(),
"is_a_primitive_class": elem_dict[class_name].is_a_primitive_class(),
"is_a_datatype_class": elem_dict[class_name].is_a_datatype_class(),
"langPack": lang_pack,
"sub_class_of": elem_dict[class_name].superClass(),
"sub_classes": elem_dict[class_name].subClasses(),
Expand Down Expand Up @@ -527,13 +527,12 @@ def _write_python_files(elem_dict, lang_pack, output_path, version):
attribute["attribute_class"] = attribute_class

is_an_enum_class = attribute_class in elem_dict and elem_dict[attribute_class].is_an_enum_class()
attribute_type = _get_attribute_type(attribute, is_an_enum_class, primitive_classes, cim_data_type_classes)
attribute_type = _get_attribute_type(attribute, is_an_enum_class, primitive_classes, datatype_classes)
attribute["is_class_attribute"] = _get_bool_string(attribute_type == "class")
attribute["is_enum_attribute"] = _get_bool_string(attribute_type == "enum")
attribute["is_list_attribute"] = _get_bool_string(attribute_type == "list")
attribute["is_primitive_attribute"] = _get_bool_string(attribute_type == "primitive")
attribute["is_cim_datatype"] = _get_bool_string(attribute_type == "cim_datatype")
attribute["attribute_class"] = attribute_class
attribute["is_datatype_attribute"] = _get_bool_string(attribute_type == "datatype")

class_details["attributes"].sort(key=lambda d: d["label"])
_write_files(class_details, output_path, version)
Expand Down Expand Up @@ -869,7 +868,7 @@ def _get_attribute_type(attribute: dict, is_an_enum_class: bool, primitive_class
if attribute["attribute_class"] in primitive_classes:
attribute_type = "primitive"
elif attribute["attribute_class"] in cim_data_type_classes:
attribute_type = "cim_datatype"
attribute_type = "datatype"
elif attribute["attribute_class"] == "String":
attribute_type = ""
elif is_an_enum_class:
Expand Down
8 changes: 4 additions & 4 deletions cimgen/languages/modernpython/lang_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _primitive_to_data_type(datatype):
def _set_imports(attributes):
classes = set()
for attribute in attributes:
if attribute["is_cim_datatype"] or attribute["is_primitive_attribute"]:
if attribute["is_datatype_attribute"] or attribute["is_primitive_attribute"]:
classes.add(attribute["attribute_class"])

result = ""
Expand Down Expand Up @@ -151,7 +151,7 @@ def _compute_cim_data_type(attributes) -> dict:
def _set_cim_data_type(text, render) -> str:
attribute = eval(render(text))
cim_data_type = ""
if attribute["is_cim_datatype"] or attribute["is_primitive_attribute"]:
if attribute["is_datatype_attribute"] or attribute["is_primitive_attribute"]:
cim_data_type += "\n "
cim_data_type += """"cim_data_type": """ + attribute["attribute_class"] + ","
return cim_data_type
Expand All @@ -171,12 +171,12 @@ def _set_instances(text, render):


def run_template(output_path, class_details):
if class_details["is_a_primitive"]:
if class_details["is_a_primitive_class"]:
# Primitives are never used in the in memory representation but only for
# the schema
template = primitive_template_files
class_details["python_type"] = _primitive_to_data_type(class_details["class_name"])
elif class_details["is_a_cim_data_type"]:
elif class_details["is_a_datatype_class"]:
# Datatypes based on primitives are never used in the in memory
# representation but only for the schema
template = cimdatatype_template_files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class {{class_name}}({{sub_class_of}}):
"is_enum_attribute": {{#is_enum_attribute}}True{{/is_enum_attribute}}{{^is_enum_attribute}}False{{/is_enum_attribute}},
"is_list_attribute": {{#is_list_attribute}}True{{/is_list_attribute}}{{^is_list_attribute}}False{{/is_list_attribute}},
"is_primitive_attribute": {{#is_primitive_attribute}}True{{/is_primitive_attribute}}{{^is_primitive_attribute}}False{{/is_primitive_attribute}},
"is_cim_datatype": {{#is_cim_datatype}}True{{/is_cim_datatype}}{{^is_cim_datatype}}False{{/is_cim_datatype}},{{#setCimDataType}}{{.}}{{/setCimDataType}}
"is_datatype_attribute": {{#is_datatype_attribute}}True{{/is_datatype_attribute}}{{^is_datatype_attribute}}False{{/is_datatype_attribute}},{{#setCimDataType}}{{.}}{{/setCimDataType}}
},
)

Expand Down

0 comments on commit 73ff2ac

Please sign in to comment.