class_generator module

Created on Tue Nov 04 09:01:21 2014 @author: pierre_b

generate_class(gen_dict, class_name, path_to_gen)[source]

generate the corresponding class file (erase the previous code)

Parameters:
  • gen_dict (dict) – Dict with key = class name and value = class dict (name, package, properties, methods…)
  • class_name (str) – name of the class to generate
  • path_to_gen (str) – path to the file to save the class code
Returns:

Return type:

None

generate_init(gen_dict, class_dict)[source]

Generate the code for the __init__ method for the class

Parameters:
  • gen_dict (dict) – Dict with key = class name and value = class dict (name, package, properties, methods…)
  • class_dict (dict) – Dictionnary of the class to generate (keys are name, package, properties, methods…)
Returns:

init_str – String containing the __init__ method code

Return type:

str

generate_set_class_by_dict_list(prop_name, prop_type, daug_list)[source]

Generate the code to set a list of pyleecan class property with a dictionary

Parameters:
  • prop_name (str) – Name of the property to set
  • prop_type (str) – Type of the property to set
  • daug_list (list) – List of the Daughter of the class
Returns:

class_dict_str – String containing the code to set a list of pyleecan class property with a dictionary

Return type:

str

generate_set_class_by_dict(prop_name, prop_type, daug_list)[source]

Generate the code to set a pyleecan class property with a dictionary

Parameters:
  • prop_name (str) – Name of the property to set
  • prop_type (str) – Type of the property to set
  • daug_list (list) – List of the Daughter of the class
Returns:

class_dict_str – String containing the code to set a pyleecan class property with a dictionary

Return type:

str

generate_init_void()[source]

Generate the code for the init method with no property

Returns:init_str – String containing the code to initialize a class with no property
Return type:str
generate_str(gen_dict, class_dict)[source]

Generate the code for the __str__ method of the class

Parameters:
  • gen_dict (dict) – Dict with key = class name and value = class dict (name, package, properties, methods…)
  • class_dict (dict) – Dictionnary of the class to generate (keys are name, package, properties, methods…)
Returns:

str_str – String containing the code for the __str__ method of the class

Return type:

str

generate_eq(gen_dict, class_dict)[source]

Generate the code for the __eq__ method of the class

Parameters:
  • gen_dict (dict) – Dict with key = class name and value = class dict (name, package, properties, methods…)
  • class_dict (dict) – Dictionnary of the class to generate (keys are name, package, properties, methods…)
Returns:

eq_str – String containing the code for the __eq__ method of the class

Return type:

str

generate_as_dict(gen_dict, class_dict)[source]

Generate the code for the as_dict method of the class

Parameters:
  • gen_dict (dict) – Dict with key = class name and value = class dict (name, package, properties, methods…)
  • class_dict (dict) – Dictionnary of the class to generate (keys are name, package, properties, methods…)
Returns:

dict_str – String containing the code for the as_dict method of the class

Return type:

str

generate_set_None(gen_dict, class_dict)[source]

Generate the code for the _set_None method of the class

Parameters:
  • gen_dict (dict) – Dict with key = class name and value = class dict (name, package, properties, methods…)
  • class_dict (dict) – Dictionnary of the class to generate (keys are name, package, properties, methods…)
Returns:

None_str – String containing the code for the _set_None method of the class

Return type:

str

generate_properties(gen_dict, class_dict)[source]

Generate the code for the getter and setter of the properties of the class

Parameters:
  • gen_dict (dict) – Dict with key = class name and value = class dict (name, package, properties, methods…)
  • class_dict (dict) – Dictionnary of the class to generate (keys are name, package, properties, methods…)
Returns:

prop_str – String containing the code for the getter and setter of the properties of the class

Return type:

str

get_mother_attr(gen_dict, class_dict, key)[source]

Get the list of the key value from the class, including mother ones. Used to get all the properties or method of a class

Parameters:
  • gen_dict (dict) – Dict with key = class name and value = class dict (name, package, properties, methods…)
  • class_dict (dict) – Dictionnary of the class to generate (keys are name, package, properties, methods…)
  • key (str) – Key to extract from the mother class(es) (“properties” or “methods”)
Returns:

(all_list, mother_list) – all_list: List of all the “key” of the class including mother class(es) ones mother_list: List of the “key” from the mother class(es) only

Return type:

tuple