pyleecan.Functions.Save.save_json module¶
- save_json(obj, save_path='', is_folder=False, type_handle_old=2, type_compression=0, class_to_split=('Simulation', 'Machine', 'Material', 'HoleUD', 'SlotUD', 'SlotUD2'))[source]¶
Save the object to the save_path
- Parameters:
obj – A pyleecan object to save
save_path (str) – path to the folder to save the object
is_folder (bool) – to split the object in different files
type_handle_old (int) – How to handle old file in folder mode (0:Nothing, 1:Delete, 2:Move to “Backup” folder)
type_compression (int) – 0: no compression, 1: gzip
class_to_split (list) – list of classes (and daughter classes) that should be split only for is_folder == True
- setup_save_path(save_path, obj, is_folder, type_handle_old, file_ext, logger)[source]¶
Check save_path and modify or create it if needed, i.e. add or remove file extension .json or create new name based on class name.
- Parameters:
save_path (str) – File/Folder path
obj – Pyleecan object to save
is_folder (bool) – object is saved if folder mode
type_handle_old (int) – How to handle old file in folder mode (0:Nothing, 1:Delete, 2:Move to “Backup” folder)
file_ext (str) – File extension e.g. “.json”
logger – Logger to use
- build_data(obj, logger)[source]¶
Build a json serializable data structure of lists, dicts and pyleecan objects. Data that can not be serialized will be set to None. Tuples will also be None.
- Parameters:
obj – An object to serialize
- Returns:
A serializable data structure
- Return type:
data
- split_obj_dict(cls_tupel, obj_dict, folder, split_list, file_ext, logger)[source]¶
Store classes_tuple objects contained in obj_dict in split_list and modify the obj_dict.
- Parameters:
classes_tuple (tuple) – tuple containing the classe names to save separately
obj_dict (dict) – object dictionary to save
folder_path (str) – directory to save all the files
logger (logging.Logger) – logger to display information
- Returns:
obj_dict – object dictionnary to save
- Return type:
dict
- create_folder(name, logger)[source]¶
Create a new non existing the folder: “YYYY_mm_dd-HH_MM_SS-name”.
- get_filename(obj, folder, split_list, file_ext, logger)[source]¶
Get a filename for the object that doesn’t exists.
- Parameters:
obj (dict) – object dictionary to save
folder_path (str) – directory to save all the files
split_list (list) – list of objects to be saved seperately
logger (logging.Logger) – logger to display information
- Returns:
name – name of the file containing the object
- Return type:
str