Python statsdir.
安装
你可以通过 pypi 安装
pip install -U statsdir
使用
用作模块
提供了一个函数 statsdir() 可用于遍历目录树
>>> from statsdir import statsdir
>>> help(statsdir)
Help on function statsdir in module statsdir:
statsdir(top=None, /, min_depth: int = 0, max_depth: int = -1, predicate: None | collections.abc.Callable[..., None | bool] = None, onerror: bool | collections.abc.Callable[[OSError], Any] = False, follow_symlinks: bool = False, key: None | collections.abc.Callable = None) -> dict
目录树遍历统计。
:param top: 根路径,默认为当前目录。
:param min_depth: 最小深度,小于 0 时不限。参数 `top` 本身的深度为 0,它的直接跟随路径的深度是 1,以此类推。
:param max_depth: 最大深度,小于 0 时不限。
:param predicate: 调用以筛选遍历得到的路径。可接受的参数与参数 `top` 的类型一致,参见 `:return:` 部分。
:param onerror: 处理 OSError 异常。如果是 True,抛出异常;如果是 False,忽略异常;如果是调用,以异常为参数调用之。
:param follow_symlinks: 是否跟进符号连接(如果为否,则会把符号链接视为文件,即使它指向目录)。
:param key: 计算以得到一个 key,相同的 key 为一组,对路径进行分组统计。
:return: 返回统计数据,形如
{
"path": str, # 根路径
"total": int, # 包含路径总数 = 目录数 + 文件数
"dirs": int, # 包含目录数
"files": int, # 包含文件数
"size": int, # 文件总大小(符号链接视为文件计入)
"fmt_size": str, # 文件总大小,换算为适当的单位:B (Byte), KB (Kilobyte), MB (Megabyte), GB (Gigabyte), TB (Terabyte), PB (Petabyte), ...
# OPTIONAL: 如果提供了 key 函数
"keys": {
a_key: {
"total": int,
"dirs": int,
"files": int,
"size": int,
"fmt_size": str,
},
...
}
}
。
用作命令
提供一个命令行工具,用于导出目录树
$ statsdir -h
usage: statsdir [-h] [-m MIN_DEPTH] [-M MAX_DEPTH] [-s SELECT] [-se] [-k KEY] [-ke] [-fl] [-v] [paths ...]
目录树遍历统计
positional arguments:
paths 文件夹路径,多个用空格隔开,默认从 stdin 读取
options:
-h, --help show this help message and exit
-m MIN_DEPTH, --min-depth MIN_DEPTH
最小深度,默认值 0,小于 0 时不限
-M MAX_DEPTH, --max-depth MAX_DEPTH
最大深度,默认值 -1,小于 0 时不限
-s SELECT, --select SELECT
对路径进行筛选,提供一个表达式(会注入一个变量 path,类型是 pathlib.Path)或函数(会传入一个参数,类型是 pathlib.Path)
-se, --select-exec 对 -s/--select 传入的代码用 exec 运行,其中必须存在名为 select 的函数。否则,视为表达式或 lambda 函数
-k KEY, --key KEY 对路径进行分组统计,提供一个表达式(会注入一个变量 path,类型是 pathlib.Path)或函数(会传入一个参数,类型是 pathlib.Path)
-ke, --key-exec 对 -k/--key 传入的代码用 exec 运行,其中必须存在名为 key 的函数。否则,视为表达式或 lambda 函数
-fl, --follow-symlinks
跟进符号连接,否则会把符号链接视为文件,即使它指向目录
-v, --version 输出版本
Metadata
Release files for statsdir 0.0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| statsdir-0.0.2.1.tar.gz | 5.4 kB | Without provenance | Details for statsdir-0.0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| statsdir-0.0.2.1-py3-none-any.whl | Python 3 | none | any | Details for statsdir-0.0.2.1-py3-none-any.whl |
Total release size: 13.8 kB
Release files / statsdir-0.0.2.1.tar.gz
| Download URL | statsdir-0.0.2.1.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1e02e5e14ecc6595fdad5f0577b33c6319205ae3facf38a08f9ef92424c9a1fc
|
|
BLAKE2b-256 checksum How to use checksums |
d09b68c008dea69d61d4e961c5ebd60a6b0605cea5f82a43631594a823543e7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.0 CPython/3.11.8 Darwin/23.5.0
|
Release files / statsdir-0.0.2.1-py3-none-any.whl
| Download URL | statsdir-0.0.2.1-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
93599a02d1d5d033d13b4fb64c72fbb6ef571aa69dcc5d4d962d035f7ea5cb0c
|
|
BLAKE2b-256 checksum How to use checksums |
1e5aadff71080e1c691728625fb96258348cc1ae8fa68aa1cd3ccc63d57a77ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.0 CPython/3.11.8 Darwin/23.5.0
|
Security for statsdir 0.0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.