def load_json_parameters(path, value_cast=False): # loads in json parameters and turns it into a dictionary try: with codecsopen(path, 'r', encoding='utf-8') as f: parameters = [] try: parameters = jsonload(f) if value_cast: parameters = _cast_parameters(parameters) except ValueError: raise ValueError("Parameters file is formatted incorrectly!") f.close() except IOError: raise IOError("Incorrect path to parameters given! Please try again.") return parameters
def load_json_parameters(path: str, value_cast: bool = False) -> dict: """Load JSON Parameters. Given a path to a json of parameters, convert to a dictionary and optionally cast the type. Expects the following format: "fake_data": { "value": "true", "section": "bci_config", "readableName": "Fake Data Sessions", "helpTip": "If true, fake data server used", "recommended_values": "", "type": "bool" } PARAMETERS ---------- :param: path: string path to the parameters file. :param: value_case: True/False cast values to specified type. """ # loads in json parameters and turns it into a dictionary try: with codecsopen(path, 'r', encoding='utf-8') as f: parameters = [] try: parameters = jsonload(f) if value_cast: parameters = _cast_parameters(parameters) except ValueError: raise ValueError( "Parameters file is formatted incorrectly!") f.close() except IOError: raise IOError("Incorrect path to parameters given! Please try again.") return parameters
def load_from_source(self): """Load data from the configured JSON file.""" if self.source: with codecsopen(self.source, 'r', encoding='utf-8') as json_file: data = load(json_file) self.load(data)
print _blue(string_file) parser = getParser(string_file) parser.readFile(os.path.join(base_locale, string_file)) entities = [e for e in parser] for locale in locales: added = 0 same = 0 translated = 0 path = os.path.join(locale_dir, locale, string_file) if os.path.exists(path): parser.readFile(path) locale_entities = {e.key: e for e in parser} else: locale_entities = {} output = codecsopen(path, 'w', 'utf-8') for entity in entities: key = entity.key val = entity.val locale_val = locale_entities[key].val if key in locale_entities else None if locale_val is None: added = added + 1 elif locale_val == val: same = same + 1 else: val = locale_val translated = translated + 1 if isinstance(parser, DTDParser):
print _blue(string_file) parser = getParser(string_file) parser.readFile(os.path.join(base_locale, string_file)) entities = [e for e in parser] for locale in locales: added = 0 same = 0 translated = 0 path = os.path.join(locale_dir, locale, string_file) if os.path.exists(path): parser.readFile(path) locale_entities = {e.key: e for e in parser} else: locale_entities = {} output = codecsopen(path, 'w', 'utf-8') for entity in entities: key = entity.key val = entity.val locale_val = locale_entities[ key].val if key in locale_entities else None if locale_val is None: added = added + 1 elif locale_val == val: same = same + 1 else: val = locale_val translated = translated + 1