Ejemplo n.º 1
0
Archivo: editor.py Proyecto: jab/lektor
    def _save_impl(self):
        if not self._changed and self.exists:
            return

        try:
            os.makedirs(os.path.dirname(self.fs_path))
        except OSError:
            pass

        with atomic_open(self.fs_path, 'wb') as f:
            for chunk in serialize(self.iteritems(), encoding='utf-8'):
                f.write(chunk)
Ejemplo n.º 2
0
    def _save_impl(self):
        if not self._changed and self.exists:
            return

        try:
            os.makedirs(os.path.dirname(self.fs_path))
        except OSError:
            pass

        with atomic_open(self.fs_path, 'wb') as f:
            for chunk in serialize(self.iteritems(), encoding='utf-8'):
                f.write(chunk)
Ejemplo n.º 3
0
    def _save_impl(self):
        # When creating a new alt from a primary self.exists is True but
        # the file does not exist yet.  In this case we want to explicitly
        # create it anyways instead of bailing.
        if not self._changed and self.exists and os.path.exists(self.fs_path):
            return

        try:
            os.makedirs(os.path.dirname(self.fs_path))
        except OSError:
            pass

        with atomic_open(self.fs_path, 'wb') as f:
            for chunk in serialize(self.iteritems(), encoding='utf-8'):
                f.write(chunk)
Ejemplo n.º 4
0
    def _save_impl(self):
        # When creating a new alt from a primary self.exists is True but
        # the file does not exist yet.  In this case we want to explicitly
        # create it anyways instead of bailing.
        if not self._changed and self.exists and os.path.exists(self.fs_path):
            return

        try:
            os.makedirs(os.path.dirname(self.fs_path))
        except OSError:
            pass

        with atomic_open(self.fs_path, 'wb') as f:
            for chunk in serialize(self.iteritems(), encoding='utf-8'):
                f.write(chunk)
Ejemplo n.º 5
0
    def add_attachment(self, filename, fp):
        """Stores a new attachment.  Returns `None` if the file already"""
        if not self.exists:
            raise BadEdit('Record does not exist.')
        if self.is_attachment:
            raise BadEdit('Cannot attach something to an attachment.')
        directory = self.pad.db.to_fs_path(self.path)

        safe_filename = secure_filename(filename)

        while 1:
            fn = os.path.join(directory, safe_filename)
            if not os.path.isfile(fn):
                break
            safe_filename = increment_filename(fn)

        with atomic_open(fn, 'wb') as f:
            shutil.copyfileobj(fp, f)
        return safe_filename
Ejemplo n.º 6
0
Archivo: editor.py Proyecto: jab/lektor
    def add_attachment(self, filename, fp):
        """Stores a new attachment.  Returns `None` if the file already"""
        if not self.exists:
            raise BadEdit('Record does not exist.')
        if self.is_attachment:
            raise BadEdit('Cannot attach something to an attachment.')
        directory = self.pad.db.to_fs_path(self.path)

        safe_filename = secure_filename(filename)

        while 1:
            fn = os.path.join(directory, safe_filename)
            if not os.path.isfile(fn):
                break
            safe_filename = increment_filename(fn)

        with atomic_open(fn, 'w') as f:
            shutil.copyfileobj(fp, f)
        return safe_filename
Ejemplo n.º 7
0
    def add_attachment(self, filename, fp):
        """Stores a new attachment.  Returns `None` if the file already"""
        if not self.exists:
            raise BadEdit("Record does not exist.")
        if self.is_attachment:
            raise BadEdit("Cannot attach something to an attachment.")
        if not self.datamodel.has_own_attachments:
            raise BadEdit("Attachments are disabled for this page.")
        directory = self.pad.db.to_fs_path(self.path)

        safe_filename = secure_filename(filename)

        while 1:
            fn = os.path.join(directory, safe_filename)
            if not os.path.isfile(fn):
                break
            safe_filename = increment_filename(fn)

        with atomic_open(fn, "wb") as f:
            shutil.copyfileobj(fp, f)
        return safe_filename