twisted :: python :: filepath :: FilePath :: Class FilePath
[hide private]

Class FilePath

_PathHelper --+
              |
             FilePath
Known Subclasses:

I am a path on the filesystem that only permits 'downwards' access.

Instantiate me with a pathname (for example, FilePath('/home/myuser/public_html')) and I will attempt to only provide access to files which reside inside that path. I may be a path to a file, a directory, or a file which does not exist.

The correct way to use me is to instantiate me, and then do ALL filesystem access through me. In other words, do not import the 'os' module; if you need to open a file, call my 'open' method. If you need to list a directory, call my 'path' method.

Even if you pass me a relative path, I will convert that to an absolute path internally.

Note: although time-related methods do return floating-point results, they may still be only second resolution depending on the platform and the last value passed to os.stat_float_times. If you want greater-than-second precision, call os.stat_float_times(True), or use Python 2.5. Greater-than-second precision is only available in Windows on Python2.5 and later.

Nested Classes [hide private]
  clonePath
I am a path on the filesystem that only permits 'downwards' access.
Instance Methods [hide private]
 
__cmp__(self, other)
 
__getstate__(self)
 
__init__(self, path, alwaysCreate=False)
 
__repr__(self)
 
basename(self)
 
child(self, path)
 
childSearchPreauth(self, *paths)
Return my first existing child with a name in 'paths'.
 
chmod(self, mode)
Changes the permissions on self, if possible.
 
copyTo(self, destination)
 
create(self)
Exclusively create a file, only if this file previously did not exist.
 
createDirectory(self)
 
dirname(self)
bool
exists(self)
Check if the path exists.
float
getAccessTime(self)
Retrieve the time that this file was last accessed.
float
getModificationTime(self)
Retrieve the time of last access from this file.
float
getStatusChangeTime(self)
Retrieve the time of the last status change for this file.
 
getsize(self)
 
globChildren(self, pattern)
Assuming I am representing a directory, return a list of FilePaths representing my children that match the given pattern.
 
isabs(self)
 
isdir(self)
 
isfile(self)
 
islink(self)
 
linkTo(self, linkFilePath)
Creates a symlink to self to at the path in the FilePath linkFilePath.
 
listdir(self)
 
makedirs(self)
Create all directories not yet existing in path segments, using os.makedirs.
 
moveTo(self, destination)
 
open(self, mode='r')
 
parent(self)
 
preauthChild(self, path)
Use me if `path' might have slashes in it, but you know they're safe.
 
remove(self)
Removes the file or directory that is represented by self.
 
requireCreate(self, val=1)
 
restat(self, reraise=True)
Re-calculate cached effects of 'stat'.
 
setContent(self, content, ext='.new')
 
siblingExtension(self, ext)
 
siblingExtensionSearch(self, *exts)
Attempt to return a path with my name, given multiple possible extensions.
 
splitext(self)
 
temporarySibling(self)
Create a path naming a temporary sibling of this path in a secure fashion.
 
touch(self)

Inherited from _PathHelper: __hash__, children, getContent, getatime, getctime, getmtime, segmentsFrom, sibling, walk

Class Variables [hide private]
  _chunkSize = 65536
  path = None
  statinfo = None
Instance Variables [hide private]
bool alwaysCreate
When opening this file, only succeed if the file does not already exist.
Method Details [hide private]

childSearchPreauth(self, *paths)

 

Return my first existing child with a name in 'paths'.

paths is expected to be a list of *pre-secured* path fragments; in most cases this will be specified by a system administrator and not an arbitrary user.

If no appropriately-named children exist, this will return None.

chmod(self, mode)

 

Changes the permissions on self, if possible. Propagates errors from os.chmod up.

Parameters:
  • mode (int) - integer representing the new permissions desired (same as the command line chmod)

exists(self)

 

Check if the path exists.

Returns: bool
True if the stats of path can be retrieved successfully, False in the other cases.

getAccessTime(self)

 

Retrieve the time that this file was last accessed.

Returns: float
a number of seconds from the epoch.

getModificationTime(self)

 

Retrieve the time of last access from this file.

Returns: float
a number of seconds from the epoch.

getStatusChangeTime(self)

 

Retrieve the time of the last status change for this file.

Returns: float
a number of seconds from the epoch.

linkTo(self, linkFilePath)

 

Creates a symlink to self to at the path in the FilePath linkFilePath. Only works on posix systems due to its dependence on os.symlink. Propagates OSErrors up from os.symlink if linkFilePath.parent() does not exist, or linkFilePath already exists.

Parameters:
  • linkFilePath (FilePath) - a FilePath representing the link to be created

preauthChild(self, path)

 

Use me if `path' might have slashes in it, but you know they're safe.

(NOT slashes at the beginning. It still needs to be a _child_).

remove(self)

 

Removes the file or directory that is represented by self. If self.path is a directory, recursively remove all its children before removing the directory. If it's a file or link, just delete it.

restat(self, reraise=True)

 

Re-calculate cached effects of 'stat'. To refresh information on this path after you know the filesystem may have changed, call this method.

Parameters:
  • reraise - a boolean. If true, re-raise exceptions from os.stat; otherwise, mark this path as not existing, and remove any cached stat information.

siblingExtensionSearch(self, *exts)

 

Attempt to return a path with my name, given multiple possible extensions.

Each extension in exts will be tested and the first path which exists will be returned. If no path exists, None will be returned. If '' is in exts, then if the file referred to by this path exists, 'self' will be returned.

The extension '*' has a magic meaning, which means "any path that begins with self.path+'.' is acceptable".