def read_endpoint_files(root): import yaml import json import os domain = {} for path in find_yaml_files(root): with open(path, "r") as f: domain.update(yaml.safe_load(f)) for path in find_json_files(root): with open(path, "r") as f: domain.update(json.safe_load(f)) return domain
def __get_kube_job_definition(self, job_path): """ TODO: validate is yaml/json is a job """ if job_path.split('.')[-1] in ['yml', 'yaml']: with open(job_path) as f: self.log.debug('Opening kubejob "%s"' % job_path) return yaml.safe_load(f.read()) elif job_path.split('.')[-1] in ['json']: with open(job_path) as f: self.log.debug('Opening kubejob "%s"' % job_path) return json.safe_load(f.read()) else: self.log.error('Fail, jobpath: "%s" should be yml,yaml or json') exit(1)
def read_config_file(config_file): """Read an YAML config file :param config_file: [description] :type config_file: [type] """ if os.path.isfile(config_file): extension = os.path.splitext(config_file)[1] try: with open(config_file) as data_file: if extension in ['.yml', '.yaml']: config_json = yaml.safe_load(data_file.read()) elif extension in ['.json']: config_json = json.safe_load(data_file.read()) except IOError: print("Unable to read the file", config_file) exit(1) else: print("Cannot find the file", config_file) exit(1) return config_json
def dataset_dict_to_json_content(dataset_dict): if "content" in dataset_dict: return json.loads(dataset_dict["content"]) else: with open(dataset_dict["path"]) as f: return json.safe_load(f)
def loadYaml(self, filename): with open(filename, 'rU') as cfgfile: config = json.safe_load(cfgfile) return config
def get_schema(schema_path=schema_path): with open(schema_path) as json_file: config = json.safe_load(json_file) return config