class documentation

class Dir(FilePath): (source)

Known subclasses: zim.fs.FilteredDir

View In Hierarchy

Class representing a single file system folder
Method __eq__ Undocumented
Method cleanup No summary
Method copyto No summary
Method exists No summary
Method file Get a File object for a path below this folder
Method get_file_tree_as_text No summary
Method list List the file contents
Method new_file No summary
Method new_subdir No summary
Method remove Remove this folder, fails if it is not empty.
Method remove_children Recursively remove everything below this folder .
Method resolve_dir Get a Dir object for a path relative to this folder
Method resolve_file Get a File object for a path relative to this folder
Method subdir Get a Dir object for a path below this folder
Method touch Create this folder and any parent folders that do not yet exist. @param mode: creation mode (e.g. 0700)
Method walk No summary
Method _list Undocumented

Inherited from UnixPath:

Class Method new_from_zim_config Returns a new object based on the string representation for that path
Method __add__ Concatenates paths, only creates objects of the same class. See Dir.file() and Dir.subdir() instead to create other objects.
Method __init__ Constructor
Method __iter__ Undocumented
Method __ne__ Undocumented
Method __repr__ Undocumented
Method __str__ Undocumented
Method commonparent No summary
Method ctime Get the creation time of the file path. @returns: the mtime timestamp
Method ischild Check if this path is a child path of a folder @returns: True if this path is a child path of parent
Method isdir Check if this path is a folder or not. Used to detect if e.g. a File object should have really been a Dir object. @returns: True when this path is a folder
Method isequal No summary
Method iswritable Check if a file or folder is writable. Uses permissions of parent folder if the file or folder does not (yet) exist. @returns: True if the file or folder is writable
Method monitor Creates a FSObjectMonitor for this path
Method mtime Get the modification time of the file path. @returns: the mtime timestamp
Method relpath No summary
Method rename No summary
Method serialize_zim_config Returns the file path as string for serializing the object
Method size Get file size in bytes See format_file_size() to get a human readable label @returns: file size in bytes
Method split No summary
Instance Variable path the absolute file path as string file system encoding (should only be used by low-level functions)
Property basename Basename property
Property dir Returns a Dir object for the parent dir
Property dirname Dirname property
Property uri File uri property
Property user_path User_path property
Static Method _parse_uri Undocumented
Method _set_path Undocumented
Instance Variable _serialized Undocumented
def __eq__(self, other): (source)

Undocumented

def cleanup(self): (source)
Remove this foldder and any empty parent folders. If the folder does not exist, still check for empty parent folders. Fails silently if the folder is not empty.
Returns
True when successfull (so False means it still exists).
def copyto(self, dest): (source)
Recursively copy the contents of this folder. When the destination folder already exists the contents will be merged, so you need to check existence of the destination first if you want a clean new copy.
Parameters
desta Dir object
def exists(self): (source)
Check if a file or folder exists.
Returns
True if the file or folder exists
Unknown Field: implementation
must be implemented by sub classes in order that they enforce the type of the resource as well
def file(self, path): (source)
Get a File object for a path below this folder
Parameters
patha (relative) file path as string, tuple or FilePath object. When path is a File object already this method still enforces it is below this folder. So this method can be used as check as well.
Returns
a File object
Raises
PathLookupErrorif the path is not below this folder
def get_file_tree_as_text(self, raw=True): (source)
Returns an overview of files and folders below this dir as text. Used in tests.
Parameters
rawsee list()
Returns
file listing as string
def list(self, glob=None, includehidden=False, includetmp=False, raw=False): (source)
overridden in zim.fs.FilteredDir
List the file contents
Parameters
globa file name glob to filter the listed files, e.g "*.png"
includehiddenif True include hidden files (e.g. names starting with "."), ignore otherwise
includetmpif True include temporary files (e.g. names ending in "~"), ignore otherwise
rawfor filtered folders (FilteredDir instances) setting raw to True will disable filtering
Returns
a sorted list of names for files and subdirectories. Will not return names that could not be decoded properly and will throw warnings if those are encountered. Hidden files are silently ignored.
def new_file(self, path): (source)
Get a File object for a new file below this folder. Like file() but guarantees the file does not yet exist by adding sequential numbers if needed. So the resulting file may have a modified name.
Parameters
patha (relative) file path as string, tuple or FilePath object.
Returns
a File object
Raises
PathLookupErrorif the path is not below this folder
def new_subdir(self, path): (source)
Get a Dir object for a new sub-folder below this folder. Like subdir() but guarantees the folder does not yet exist by adding sequential numbers if needed. So the resulting folder may have a modified name.
Parameters
patha (relative) file path as string, tuple or FilePath object.
Returns
a Dir object
Raises
PathLookupErrorif the path is not below this folder
def remove(self): (source)
Remove this folder, fails if it is not empty.
def remove_children(self): (source)

Recursively remove everything below this folder .

WARNING: This is quite powerful and can do a lot of damage when executed for the wrong folder, so pleae make sure to double check the dir is actually what you think it is before calling this.

def resolve_dir(self, path): (source)

Get a Dir object for a path relative to this folder

Like subdir() but allows the path to start with "../" as well, so can handle any relative path.

Parameters
patha (relative) file path as string, tuple or FilePath object.
Returns
a Dir object
def resolve_file(self, path): (source)

Get a File object for a path relative to this folder

Like file() but allows the path to start with "../" as well, so can handle any relative path.

Parameters
patha (relative) file path as string, tuple or FilePath object.
Returns
a File object
def subdir(self, path): (source)
Get a Dir object for a path below this folder
Parameters
patha (relative) file path as string, tuple or FilePath object. When path is a Dir object already this method still enforces it is below this folder. So this method can be used as check as well.
Returns
a Dir object
Raises
PathLookupErrorif the path is not below this folder
def touch(self, mode=None): (source)
Create this folder and any parent folders that do not yet exist.
Parameters
modecreation mode (e.g. 0700)
def walk(self, raw=True): (source)
Generator that yields all files and folders below this dir as objects.
Parameters
rawsee list()
Returns
yields File and Dir objects, depth first
def _list(self, includehidden, includetmp): (source)

Undocumented