Beispiel #1
0
def _ensure_parent_dir(filepath):
    """ Ensures that the parent directory of the given file path exists. """
    try:
        parentpath = os.path.abspath(os.path.join(filepath, os.pardir))
        if not os.path.isdir(parentpath):
            os.makedirs(parentpath)
    except IOError as ioe:
        raise CannotWriteConfigException(str(ioe))
Beispiel #2
0
    def save_volume_file(self, filename, flask_file):
        filepath = os.path.join(self.config_volume, filename)
        _ensure_parent_dir(filepath)

        # Write the file.
        try:
            flask_file.save(filepath)
        except IOError as ioe:
            raise CannotWriteConfigException(str(ioe))

        return filepath
Beispiel #3
0
    def write_volume_file(self, filename, contents):
        filepath = os.path.join(self.config_volume, filename)
        _ensure_parent_dir(filepath)

        try:
            with open(filepath, mode="w") as f:
                f.write(contents)
        except IOError as ioe:
            raise CannotWriteConfigException(str(ioe))

        return filepath