Esempio n. 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
Esempio n. 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
Esempio n. 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('[]')
Esempio n. 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()
Esempio n. 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('[]')
Esempio n. 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()
Esempio n. 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
Esempio n. 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
Esempio n. 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)
Esempio n. 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)
Esempio n. 11
0
 def _jsonify_or_string(item):
     try:
         return decode(item)
     except DecodeError:
         return item
Esempio n. 12
0
 def _jsonify_or_string(item):
     try:
         return decode(item)
     except DecodeError:
         return item