module documentation
(source)

Module with basic filesystem objects.

This module must be used by all other zim modules for filesystem interaction. It takes care of proper encoding file paths (system dependent) and file contents (UTF-8) and implements a number of sanity checks.

The main classes are File and Dir which implement file and folder objects. There is also a singleton object to represent the whole filesystem, whichprovides signals when a file or folder is created, moved or deleted. This is stored in zim.fs.FS.

Class Dir Class representing a single file system folder
Class File Class representing a single file.
Class FileUnicodeError Error raised when there is an issue decoding the file contents. Typically due to different encoding where UTF-8 is expected.
Class FileWriteError Error raised when we can not write a file. Either due to file permissions or e.g. because it is detected the file changed on disk.
Class FilteredDir Class implementing a folder with a filtered listing. Can be used to e.g. filter all objects that are also ignored by version control.
Class FSObjectMonitor Undocumented
Class FSSingletonClass Class used for the singleton 'zim.fs.FS' instance
Class PathLookupError Error raised when there is an error finding the specified path
Class TmpFile Class for temporary files. These are stored in the temp directory and by default they are deleted again when the object is destructed.
Class UnixPath Base class for Dir and File objects, represents a file path
Class WindowsPath Base class for Dir and File objects, represents a file path on windows.
Function adapt_from_newfs Undocumented
Function adapt_from_oldfs Undocumented
Function cleanup_filename No summary
Function format_file_size No summary
Function get_tmpdir No summary
Function is_hidden_file Undocumented
Function isabs Wrapper for os.path.isabs. @param path: a file system path as string @returns: True when the path is absolute instead of a relative path
Function lrmdir Wrapper for os.rmdir that also knows how to unlink symlinks. Fails when the folder is not a link and is not empty. @param path: a file system path as string
Function normalize_file_uris No summary
Function normalize_win32_share No summary
Constant FS Undocumented
Constant IMAGE_EXTENSIONS Undocumented
Variable Gio Undocumented
Variable logger Undocumented
Variable mimetypes Undocumented
Variable xdgmime Undocumented
Function _glob_to_regex Undocumented
Function _md5 Undocumented
Function _replace_file Undocumented
Variable _tmpdir Undocumented
def adapt_from_newfs(file): (source)

Undocumented

def adapt_from_oldfs(file): (source)

Undocumented

def cleanup_filename(name): (source)
Removes all characters in 'name' that are not allowed as part of a file name. This function is intended for e.g. config files etc. not for page files in a store. For file system filenames we can not use: '\', '/', ':', '*', '?', '"', '<', '>', '|' And we also exclude "\t" and "\n".
Parameters
namethe filename as string
Returns
the name with invalid characters removed
def format_file_size(bytes): (source)
Returns a human readable label for a file size E.g. 1230 becomes "1.23kb", idem for "Mb" and "Gb"
Parameters
bytesfile size in bytes as integer
Returns
size as string
def get_tmpdir(): (source)
Get a folder in the system temp dir for usage by zim. This zim specific temp folder has permission set to be readable only by the current users, and is touched if it didn't exist yet. Used as base folder by TmpFile.
Returns
a Dir object for the zim specific tmp folder
def is_hidden_file(file): (source)

Undocumented

def isabs(path): (source)
Wrapper for os.path.isabs.
Parameters
patha file system path as string
Returns
True when the path is absolute instead of a relative path
def lrmdir(path): (source)
Wrapper for os.rmdir that also knows how to unlink symlinks. Fails when the folder is not a link and is not empty.
Parameters
patha file system path as string
def normalize_file_uris(path): (source)
Function to deal with invalid or non-local file URIs. Translates file:/ to the proper file:/// form and replaces URIs of the form file://host/share to smb://host/share.
Parameters
patha filesystem path or URL
Returns
the proper URI or the original input path
def normalize_win32_share(path): (source)
Translates paths for windows shares in the platform specific form. So on windows it translates smb:// URLs to \host\share form, and vice versa on all other platforms. Just returns the original path if it was already in the right form, or when it is not a path for a share drive.
Parameters
patha filesystem path or URL
Returns
the platform specific path or the original input path

Undocumented

Value
FSSingletonClass()
IMAGE_EXTENSIONS: tuple[str, ...] = (source)

Undocumented

Value
('bmp',
 'gif',
 'icns',
 'ico',
 'cur',
 'jp2',
 'jpc',
...

Undocumented

logger = (source)

Undocumented

mimetypes = (source)

Undocumented

xdgmime = (source)

Undocumented

def _glob_to_regex(glob): (source)

Undocumented

def _md5(content): (source)

Undocumented

def _replace_file(src, dst): (source)

Undocumented

_tmpdir = (source)

Undocumented