예제 #1
0
 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
예제 #2
0
 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
예제 #3
0
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('[]')
예제 #4
0
 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()
예제 #5
0
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('[]')
예제 #6
0
 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()
예제 #7
0
    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
예제 #8
0
    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
예제 #9
0
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)
예제 #10
0
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)
예제 #11
0
 def _jsonify_or_string(item):
     try:
         return decode(item)
     except DecodeError:
         return item
예제 #12
0
 def _jsonify_or_string(item):
     try:
         return decode(item)
     except DecodeError:
         return item