def reload_configuration_from_disk(self): with fopen(self.filepath) as fd: kwargs = decode(fd.read()) kwargs['filepath'] = self.filepath for key, value in kwargs.items(): setattr(self, key, value) return self
def reload_configuration_from_disk(self): with fopen(self.filepath) as fd: kwargs = decode(fd.read()) kwargs['filepath'] = self.filepath for key, value in kwargs.iteritems(): setattr(self, key, value) return self
def ensure_packages_json_file_exists_in_directory(dirpath): filepath = path.join(dirpath, 'packages.json') if path.exists(filepath): try: with fopen(filepath) as fd: if isinstance(decode(fd.read()), list): return except: pass with fopen(filepath, 'w') as fd: fd.write('[]')
def _get_custom_installation_instructions(self, package): filepath = path.join(package['abspath'], 'installation_instructions.json') try: if not path.exists(filepath): return dict() with fopen(filepath) as fd: result = decode(fd.read()) return result if isinstance(result, dict) else dict() except: logger.exception("failed to read custom installation instructions from {0}".format(filepath)) return dict()
def from_disk(cls, filepath): filepath = filepath or cls.get_default_config_file() if not path.exists(filepath): self = cls() self.filepath = filepath else: with fopen(filepath) as fd: kwargs = decode(fd.read()) kwargs['filepath'] = filepath self = cls() for key, value in kwargs.items(): setattr(self, key, value) assert self.webserver.default_index is None or self.webserver.default_index in self.indexes return self
def from_disk(cls, filepath): filepath = filepath or cls.get_default_config_file() if not path.exists(filepath): self = cls() self.filepath = filepath else: with fopen(filepath) as fd: kwargs = decode(fd.read()) kwargs['filepath'] = filepath self = cls() for key, value in kwargs.iteritems(): setattr(self, key, value) assert self.webserver.default_index is None or self.webserver.default_index in self.indexes return self
def safe_json_repr(value, length_limit=1024): try: encoded_string = encode(value) if length_limit and len(encoded_string) > length_limit: raise AssertionError() return decode(encoded_string) except: pass try: encoded_string = repr(value) if length_limit and len(encoded_string) > length_limit: raise AssertionError() return encoded_string except: pass return object.__repr__(value)
def _jsonify_or_string(item): try: return decode(item) except DecodeError: return item