示例#1
0
    def writelines(self, lines):
        '''Write file contents from a list of lines.
		Like L{write()} but input is a list instead of a string.
		@param lines: new content as list of lines
		@emits: path-created if the file did not yet exist
		'''
        self._assertoverwrite()
        isnew = not os.path.isfile(self.path)
        newline = self.get_endofline()
        self._write_check()
        with AtomicWriteContext(self, newline=newline) as fh:
            fh.writelines(lines)

        self._checkoverwrite(lines)
        if isnew:
            FS.emit('path-created', self)
示例#2
0
    def write(self, text):
        '''Write file contents from string. This overwrites the current
		content. Will automatically create all parent folders.
		If writing fails the file will either have the new content or the
		old content, but it should not be possible to have the content
		truncated.
		@param text: new content as (unicode) string
		@emits: path-created if the file did not yet exist
		'''
        self._assertoverwrite()
        isnew = not os.path.isfile(self.path)
        newline = self.get_endofline()
        self._write_check()
        with AtomicWriteContext(self, newline=newline) as fh:
            fh.write(text)

        self._checkoverwrite(text)
        if isnew:
            FS.emit('path-created', self)