mate_tool_box#
File system utility tool box. mimic linux md5
, zip
, etc…
- class pathlib_mate.mate_tool_box.ToolBox[source]#
- get_dir_fingerprint(hash_meth)[source]#
Return md5 fingerprint of a directory. Calculation is based on iterate recursively through all files, ordered by absolute path, and stream in md5 for each file.
- Return type:
- property dir_md5#
Return md5 fingerprint of a directory.
See
ToolBox.get_dir_fingerprint()
for details- Return type:
- property dir_sha256#
Return sha256 fingerprint of a directory.
See
ToolBox.get_dir_fingerprint()
for details- Return type:
- property dir_sha512#
Return sha512 fingerprint of a directory.
See
ToolBox.get_dir_fingerprint()
for details- Return type:
- is_empty(strict=True)[source]#
If it’s a file, check if it is a empty file. (0 bytes content)
- If it’s a directory, check if there’s no file and dir in it.
But if
strict = False
, then only check if there’s no file in it.
- auto_complete_choices(case_sensitive=False)[source]#
A command line auto complete similar behavior. Find all item with same prefix of this one.
- Parameters:
case_sensitive (bool) – toggle if it is case sensitive.
- Return type:
List[Path]
- Returns:
list of
pathlib_mate.pathlib2.Path
.
- file_stat_for_all(filters=<function all_true>)[source]#
Find out how many files, directories and total size (Include file in it’s sub-folder) it has for each folder and sub-folder.
- Return type:
- Returns:
stat, a dict like
{"directory path": { "file": number of files, "dir": number of directories, "size": total size in bytes}}
中文文档
返回一个目录中的每个子目录的, 文件, 文件夹, 大小的统计数据。
- file_stat(filters=<function all_true>)[source]#
Find out how many files, directorys and total size (Include file in it’s sub-folder).
- Return type:
- Returns:
stat, a dict like
{"file": number of files, "dir": number of directorys, "size": total size in bytes}
中文文档
返回一个目录中的文件, 文件夹, 大小的统计数据。
- mirror_to(dst)[source]#
Create a new folder having exactly same structure with this directory. However, all files are just empty file with same file name.
- Parameters:
dst (str) – destination directory. The directory can’t exists before
you execute this.
中文文档
创建一个目录的镜像拷贝, 与拷贝操作不同的是, 文件的副本只是在文件名上 与原件一致, 但是是空文件, 完全没有内容, 文件大小为0。
- execute_pyfile(py_exe=None)[source]#
Execute every
.py
file as main script.- Parameters:
py_exe (str) – python command or python executable path.
中文文档
将目录下的所有 Python 文件作为主脚本用当前解释器运行。
- trail_space(filters=<function ToolBox.<lambda>>)[source]#
Trail white space at end of each line for every
.py
file.中文文档
将目录下的所有被选择的文件中行末的空格删除.
- autopep8(**kwargs)[source]#
Auto convert your python code in a directory to pep8 styled code.
- Parameters:
kwargs – arguments for
autopep8.fix_code
method.
中文文档
将目录下的所有 Python 文件用 pep8 风格格式化. 增加其可读性和规范性.
- temp_cwd()[source]#
Temporarily set the current working directory and automatically switch back when it’s done.
- Return type:
- atomic_write_bytes(data, overwrite=False)[source]#
An atomic write action for binary data. Either fully done or nothing happen. Preventing overwriting existing file with incomplete data.
Reference:
- atomic_write_text(data, encoding='utf-8', overwrite=False)[source]#
An atomic write action for text. Either fully done or nothing happen. Preventing overwriting existing file with incomplete data.
Reference:
- Returns:
- atomic_open(mode='r', buffering=-1, encoding=None, errors=None, newline=None, overwrite=None, file_perms=None, part_file=None, overwrite_part=None)[source]#
A context manager that support
- Parameters:
buffering – original argument for
pathlib.Path.open()
encoding – original argument for
pathlib.Path.open()
errors – original argument for
pathlib.Path.open()
newline – original argument for
pathlib.Path.open()
overwrite – original argument for
boltons.fileutils.atomic_save()
file_perms – original argument for
boltons.fileutils.atomic_save()
part_file – original argument for
boltons.fileutils.atomic_save()
overwrite_part – original argument for
boltons.fileutils.atomic_save()
Reference: