pykit3 is is a collection of toolkit in python3.
k3fs is collection of file-system operation utilities.
>>> fwrite('/tmp/foo', "content") >>> fread('/tmp/foo') 'content' >>> 'foo' in ls_files('/tmp/') True
Get sorted sub directories of paths.
paths – is the directory path.
of all sub directory names.
- Return type
List all files that match pattern in path.
paths – is a directory path.
pattern (str) – is a regular expression that matches wanted file names.
of sorted file names.
- Return type
Make directory. If intermediate directory does not exist, create them too.
paths – is a single part path such as /tmp/foo or a separated path such as (‘/tmp’, ‘foo’).
mode (int) – specifies permission mode for the dir created or existed. By defaul it is 0755.
uid (int) – specifies uid for the created dir. By default they are None and the created dir inherits ownership from the running python program.
gid (int) – specifies uid for the created dir. By default they are None and the created dir inherits ownership from the running python program.
OSError – if trying to create dir with the same path of a non-dir file, or having other issue like permission denied.
Read and return the entire file specified by path
paths – is the path of the file to read.
mode (str) – If mode=’b’ it returns bytes. If mode=’‘ it returns a str decoded from bytes.
file content in string or bytes.
fwrite(*paths_content, uid=None, gid=None, atomic=False, fsync=True)¶
Write fcont into file path.
is the file path to write to and the content to write. The last elt is content, e.g.: fwrite(‘/tmp’, ‘foo’, ‘bar’) write ‘bar’ into file ‘/tmp/foo’.
specifies the user_id the file belongs to.
specifies the group_id the file belongs to.
By default they are None, which means the file that has been written inheirts ownership of the running python script.
atomically write fcont to the path.
Write fcont to a temporary file, then rename to the path. The temporary file names of same path in one process distinguish with nanosecond, it is not atomic if the temporary files of same path created at the same nanosecond. The renaming will be an atomic operation (this is a POSIX requirement).
specify if need to synchronize data to storage device.
Recursively delete path, the path is file, directory or symbolic link.
paths – is the path to remove.
onerror (str or callable) –
“raise”: when error occur it raises the original error.
”ignore”: ignore error and go on.
- A callable:
it is called to handle the error with arguments (func, path, exc_info) where func is os.listdir, os.remove, os.rmdir or os.path.isdir.