def importprojectdir(cls, dir_project, file_type): """Imports all descriptor files under a given folder this method is specific for Srv6_net_prog project type """ project = {'srv6_net_prog': {}, 'positions': {}} for desc_type in project: cur_type_path = os.path.join(dir_project, desc_type.upper()) log.debug(cur_type_path) if os.path.isdir(cur_type_path): for file in glob.glob( os.path.join(cur_type_path, '*.' + file_type)): if file_type == 'json' and os.path.basename( file) != 'vertices.json': project[desc_type][os.path.basename(file).split('.') [0]] = Util.loadjsonfile(file) elif file_type == 'yaml': project[desc_type][os.path.basename(file).split('.') [0]] = Util.loadyamlfile(file) for vertices_file in glob.glob( os.path.join(dir_project, "SRV6_NET_PROG", '*.json')): if os.path.basename(vertices_file) == 'vertices.json': project['positions']['vertices'] = Util.loadjsonfile( vertices_file) return project
def get_descriptor_template(cls, type_descriptor): """Returns a descriptor template for a given descriptor type""" try: schema = Util.loadyamlfile( os.path.join(PATH_TO_DESCRIPTORS_TEMPLATES, type_descriptor + DESCRIPTOR_TEMPLATE_SUFFIX)) return schema except Exception as e: log.exception(e) return False
def get_graph_model(cls, file_path): """Returns the model of the graph of the project type as a yaml object Returns an empty dict if there is no file with the model """ # file_path = GRAPH_MODEL_FULL_NAME graph_model = {} try: graph_model = Util.loadyamlfile(file_path) except Exception as e: log.exception(e) pass return graph_model