Package portage :: Package util :: Class atomic_ofstream
[hide private]

Class atomic_ofstream

source code

                   object --+    
                            |    
proxy.objectproxy.ObjectProxy --+
                                |
                               atomic_ofstream

Write a file atomically via os.rename(). Atomic replacement prevents interprocess interference and prevents corruption of the target file when the write is interrupted (for example, when an 'out of space' error occurs).

Instance Methods [hide private]
 
__init__(self, filename, mode=u'w', follow_links=True, **kargs)
Opens a temporary filename.pid in the same directory as filename.
source code
 
_get_target(self) source code
 
__getattribute__(self, attr)
x.__getattribute__('name') <==> x.name
source code
 
write(self, s) source code
 
close(self)
Closes the temporary file, copies permissions (if possible), and performs the atomic replacement via os.rename().
source code
 
abort(self)
If an error occurs while writing the file, the user should call this method in order to leave the target file unchanged.
source code
 
__del__(self)
If the user does not explicitly call close(), it is assumed that an error has occurred, so we abort().
source code

Inherited from proxy.objectproxy.ObjectProxy: __add__, __bool__, __call__, __contains__, __delitem__, __enter__, __eq__, __exit__, __ge__, __getitem__, __gt__, __hash__, __int__, __iter__, __le__, __len__, __lt__, __ne__, __nonzero__, __repr__, __setattr__, __setitem__, __str__, __unicode__

Inherited from object: __delattr__, __format__, __new__, __reduce__, __reduce_ex__, __sizeof__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, filename, mode=u'w', follow_links=True, **kargs)
(Constructor)

source code 

Opens a temporary filename.pid in the same directory as filename.

Overrides: object.__init__

_get_target(self)

source code 
Overrides: proxy.objectproxy.ObjectProxy._get_target

__getattribute__(self, attr)

source code 

x.__getattribute__('name') <==> x.name

Overrides: object.__getattribute__
(inherited documentation)

close(self)

source code 

Closes the temporary file, copies permissions (if possible), and performs the atomic replacement via os.rename(). If the abort() method has been called, then the temp file is closed and removed.

abort(self)

source code 

If an error occurs while writing the file, the user should call this method in order to leave the target file unchanged. This will call close() automatically.