def load_model_files(args): model = json.load(open(args.modelfile), object_pairs_hook=OrderedDict) regions = json.load(open(args.regions_file), object_pairs_hook=OrderedDict) retry = json.load(open(args.retry_file), object_pairs_hook=OrderedDict) enhancements = _load_enhancements_file(args.enhancements_file) service_name = os.path.splitext(os.path.basename(args.modelfile))[0] return ModelFiles(model, regions, retry, enhancements, name=service_name)
def load_file(self, file_path): """Attempt to load the file path. :type file_path: str :param file_path: The full path to the file to load without the '.json' extension. :return: The loaded data if it exists, otherwise None. """ full_path = file_path + '.json' if not os.path.isfile(full_path): return with open(full_path) as fp: return json.load(fp, object_pairs_hook=OrderedDict)
def _load_cases(full_path): # During developement, you can set the BOTOCORE_TEST_ID # to run a specific test suite or even a specific test case. # The format is BOTOCORE_TEST_ID=suite_id:test_id or # BOTOCORE_TEST_ID=suite_id suite_id, test_id = _get_suite_test_id() all_test_data = json.load(open(full_path), object_pairs_hook=OrderedDict) basename = os.path.basename(full_path) for i, test_data in enumerate(all_test_data): if suite_id is not None and i != suite_id: continue cases = test_data.pop('cases') description = test_data['description'] for j, case in enumerate(cases): if test_id is not None and j != test_id: continue case['description'] = description case['suite_id'] = i case['test_id'] = j yield (test_data, case, basename)
def _load_data(session, data_path): logger.debug('Attempting to load: %s', data_path) data = {} file_name = data_path + '.json' for path in get_search_path(session): file_path = os.path.join(path, file_name) dir_path = os.path.join(path, data_path) # Is the path a directory? if os.path.isdir(dir_path): logger.debug('Found data dir: %s', dir_path) try: data = [] for pn in sorted(glob.glob(os.path.join(dir_path, '*.json'))): fn = os.path.split(pn)[1] fn = os.path.splitext(fn)[0] if not fn.startswith('_'): data.append(fn) except: logger.error('Unable to load dir: %s', dir_path, exc_info=True) break elif os.path.isfile(file_path): fp = open(file_path) try: new_data = json.load(fp, object_pairs_hook=OrderedDict) fp.close() logger.debug('Found data file: %s', file_path) if data is not None: data.update(new_data) else: data = new_data break except: logger.error('Unable to load file: %s', file_path, exc_info=True) else: logger.error('Unable to find file: %s', file_path) if data: _data_cache[data_path] = data return data
def _load_data(session, data_path): logger.debug('Attempting to load: %s', data_path) data = {} file_name = data_path + '.json' for path in get_search_path(session): file_path = os.path.join(path, file_name) dir_path = os.path.join(path, data_path) # Is the path a directory? if os.path.isdir(dir_path): logger.debug('Found data dir: %s', dir_path) try: data = [] for pn in sorted(glob.glob(os.path.join(dir_path, '*.json'))): fn = os.path.split(pn)[1] fn = os.path.splitext(fn)[0] if not fn.startswith('_'): data.append(fn) except Exception: logger.error('Unable to load dir: %s', dir_path, exc_info=True) break elif os.path.isfile(file_path): fp = open(file_path) try: new_data = json.load(fp, object_pairs_hook=OrderedDict) fp.close() logger.debug('Found data file: %s', file_path) if data is not None: data.update(new_data) else: data = new_data break except Exception: logger.error('Unable to load file: %s', file_path, exc_info=True) else: logger.error('Unable to find file: %s', file_path) if data: _data_cache[data_path] = data return data
def load_file(self, file_path): """ Loads a regular data file (format-specific to subclass). This load is done uncached, so that you can always get the latest data as needed. Usage:: >>> loader = JSONFileLoader() >>> loader.load_file('/path/to/some/thing.json') { # ...JSON data... } """ try: with open(file_path) as fp: return json.load(fp, object_pairs_hook=OrderedDict) except ValueError: # For backward-compatibility with the previous implementation, # if the JSON is bad, we'll raise a ``DataNotFoundError`` exception # instead of letting it propagate. raise DataNotFoundError(data_path=file_path)
def _load_enhancements_file(file_path): if not os.path.isfile(file_path): return {} else: return json.load(open(file_path), object_pairs_hook=OrderedDict)