statsdir


Namestatsdir JSON
Version 0.0.2.1 PyPI version JSON
download
home_pagehttps://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/statsdir
Summarystatsdir.
upload_time2024-10-08 03:32:29
maintainerNone
docs_urlNone
authorChenyangGao
requires_python<4.0,>=3.10
licenseMIT
keywords statsdir statistics
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Python statsdir.

## 安装

你可以通过 [pypi](https://pypi.org/project/statsdir/) 安装

```console
pip install -U statsdir
```

## 使用

### 用作模块

提供了一个函数 `statsdir()` 可用于遍历目录树

```python
>>> 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, 
                }, 
                ...
            }
        }
    。
```

### 用作命令

提供一个命令行工具,用于导出目录树

```console
$ 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         输出版本
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/statsdir",
    "name": "statsdir",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "statsdir, statistics",
    "author": "ChenyangGao",
    "author_email": "wosiwujm@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d0/9b/68c008dea69d61d4e961c5ebd60a6b0605cea5f82a43631594a823543e7b/statsdir-0.0.2.1.tar.gz",
    "platform": null,
    "description": "# Python statsdir.\n\n## \u5b89\u88c5\n\n\u4f60\u53ef\u4ee5\u901a\u8fc7 [pypi](https://pypi.org/project/statsdir/) \u5b89\u88c5\n\n```console\npip install -U statsdir\n```\n\n## \u4f7f\u7528\n\n### \u7528\u4f5c\u6a21\u5757\n\n\u63d0\u4f9b\u4e86\u4e00\u4e2a\u51fd\u6570 `statsdir()` \u53ef\u7528\u4e8e\u904d\u5386\u76ee\u5f55\u6811\n\n```python\n>>> from statsdir import statsdir\n>>> help(statsdir)\nHelp on function statsdir in module statsdir:\n\nstatsdir(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\n    \u76ee\u5f55\u6811\u904d\u5386\u7edf\u8ba1\u3002\n    \n    :param top: \u6839\u8def\u5f84\uff0c\u9ed8\u8ba4\u4e3a\u5f53\u524d\u76ee\u5f55\u3002\n    :param min_depth: \u6700\u5c0f\u6df1\u5ea6\uff0c\u5c0f\u4e8e 0 \u65f6\u4e0d\u9650\u3002\u53c2\u6570 `top` \u672c\u8eab\u7684\u6df1\u5ea6\u4e3a 0\uff0c\u5b83\u7684\u76f4\u63a5\u8ddf\u968f\u8def\u5f84\u7684\u6df1\u5ea6\u662f 1\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\n    :param max_depth: \u6700\u5927\u6df1\u5ea6\uff0c\u5c0f\u4e8e 0 \u65f6\u4e0d\u9650\u3002\n    :param predicate: \u8c03\u7528\u4ee5\u7b5b\u9009\u904d\u5386\u5f97\u5230\u7684\u8def\u5f84\u3002\u53ef\u63a5\u53d7\u7684\u53c2\u6570\u4e0e\u53c2\u6570 `top` \u7684\u7c7b\u578b\u4e00\u81f4\uff0c\u53c2\u89c1 `:return:` \u90e8\u5206\u3002\n    :param onerror: \u5904\u7406 OSError \u5f02\u5e38\u3002\u5982\u679c\u662f True\uff0c\u629b\u51fa\u5f02\u5e38\uff1b\u5982\u679c\u662f False\uff0c\u5ffd\u7565\u5f02\u5e38\uff1b\u5982\u679c\u662f\u8c03\u7528\uff0c\u4ee5\u5f02\u5e38\u4e3a\u53c2\u6570\u8c03\u7528\u4e4b\u3002\n    :param follow_symlinks: \u662f\u5426\u8ddf\u8fdb\u7b26\u53f7\u8fde\u63a5\uff08\u5982\u679c\u4e3a\u5426\uff0c\u5219\u4f1a\u628a\u7b26\u53f7\u94fe\u63a5\u89c6\u4e3a\u6587\u4ef6\uff0c\u5373\u4f7f\u5b83\u6307\u5411\u76ee\u5f55\uff09\u3002\n    :param key: \u8ba1\u7b97\u4ee5\u5f97\u5230\u4e00\u4e2a key\uff0c\u76f8\u540c\u7684 key \u4e3a\u4e00\u7ec4\uff0c\u5bf9\u8def\u5f84\u8fdb\u884c\u5206\u7ec4\u7edf\u8ba1\u3002\n    \n    :return: \u8fd4\u56de\u7edf\u8ba1\u6570\u636e\uff0c\u5f62\u5982\n        {\n            \"path\": str,     # \u6839\u8def\u5f84 \n            \"total\": int,    # \u5305\u542b\u8def\u5f84\u603b\u6570 = \u76ee\u5f55\u6570 + \u6587\u4ef6\u6570\n            \"dirs\": int,     # \u5305\u542b\u76ee\u5f55\u6570\n            \"files\": int,    # \u5305\u542b\u6587\u4ef6\u6570\n            \"size\": int,     # \u6587\u4ef6\u603b\u5927\u5c0f\uff08\u7b26\u53f7\u94fe\u63a5\u89c6\u4e3a\u6587\u4ef6\u8ba1\u5165\uff09\n            \"fmt_size\": str, # \u6587\u4ef6\u603b\u5927\u5c0f\uff0c\u6362\u7b97\u4e3a\u9002\u5f53\u7684\u5355\u4f4d\uff1aB (Byte), KB (Kilobyte), MB (Megabyte), GB (Gigabyte), TB (Terabyte), PB (Petabyte), ...\n            # OPTIONAL: \u5982\u679c\u63d0\u4f9b\u4e86 key \u51fd\u6570\n            \"keys\": {\n                a_key: {\n                    \"total\": int, \n                    \"dirs\": int, \n                    \"files\": int, \n                    \"size\": int, \n                    \"fmt_size\": str, \n                }, \n                ...\n            }\n        }\n    \u3002\n```\n\n### \u7528\u4f5c\u547d\u4ee4\n\n\u63d0\u4f9b\u4e00\u4e2a\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u7528\u4e8e\u5bfc\u51fa\u76ee\u5f55\u6811\n\n```console\n$ statsdir -h\nusage: statsdir [-h] [-m MIN_DEPTH] [-M MAX_DEPTH] [-s SELECT] [-se] [-k KEY] [-ke] [-fl] [-v] [paths ...]\n\n\u76ee\u5f55\u6811\u904d\u5386\u7edf\u8ba1\n\npositional arguments:\n  paths                 \u6587\u4ef6\u5939\u8def\u5f84\uff0c\u591a\u4e2a\u7528\u7a7a\u683c\u9694\u5f00\uff0c\u9ed8\u8ba4\u4ece stdin \u8bfb\u53d6\n\noptions:\n  -h, --help            show this help message and exit\n  -m MIN_DEPTH, --min-depth MIN_DEPTH\n                        \u6700\u5c0f\u6df1\u5ea6\uff0c\u9ed8\u8ba4\u503c 0\uff0c\u5c0f\u4e8e 0 \u65f6\u4e0d\u9650\n  -M MAX_DEPTH, --max-depth MAX_DEPTH\n                        \u6700\u5927\u6df1\u5ea6\uff0c\u9ed8\u8ba4\u503c -1\uff0c\u5c0f\u4e8e 0 \u65f6\u4e0d\u9650\n  -s SELECT, --select SELECT\n                        \u5bf9\u8def\u5f84\u8fdb\u884c\u7b5b\u9009\uff0c\u63d0\u4f9b\u4e00\u4e2a\u8868\u8fbe\u5f0f\uff08\u4f1a\u6ce8\u5165\u4e00\u4e2a\u53d8\u91cf path\uff0c\u7c7b\u578b\u662f pathlib.Path\uff09\u6216\u51fd\u6570\uff08\u4f1a\u4f20\u5165\u4e00\u4e2a\u53c2\u6570\uff0c\u7c7b\u578b\u662f pathlib.Path\uff09\n  -se, --select-exec    \u5bf9 -s/--select \u4f20\u5165\u7684\u4ee3\u7801\u7528 exec \u8fd0\u884c\uff0c\u5176\u4e2d\u5fc5\u987b\u5b58\u5728\u540d\u4e3a select \u7684\u51fd\u6570\u3002\u5426\u5219\uff0c\u89c6\u4e3a\u8868\u8fbe\u5f0f\u6216 lambda \u51fd\u6570\n  -k KEY, --key KEY     \u5bf9\u8def\u5f84\u8fdb\u884c\u5206\u7ec4\u7edf\u8ba1\uff0c\u63d0\u4f9b\u4e00\u4e2a\u8868\u8fbe\u5f0f\uff08\u4f1a\u6ce8\u5165\u4e00\u4e2a\u53d8\u91cf path\uff0c\u7c7b\u578b\u662f pathlib.Path\uff09\u6216\u51fd\u6570\uff08\u4f1a\u4f20\u5165\u4e00\u4e2a\u53c2\u6570\uff0c\u7c7b\u578b\u662f pathlib.Path\uff09\n  -ke, --key-exec       \u5bf9 -k/--key \u4f20\u5165\u7684\u4ee3\u7801\u7528 exec \u8fd0\u884c\uff0c\u5176\u4e2d\u5fc5\u987b\u5b58\u5728\u540d\u4e3a key \u7684\u51fd\u6570\u3002\u5426\u5219\uff0c\u89c6\u4e3a\u8868\u8fbe\u5f0f\u6216 lambda \u51fd\u6570\n  -fl, --follow-symlinks\n                        \u8ddf\u8fdb\u7b26\u53f7\u8fde\u63a5\uff0c\u5426\u5219\u4f1a\u628a\u7b26\u53f7\u94fe\u63a5\u89c6\u4e3a\u6587\u4ef6\uff0c\u5373\u4f7f\u5b83\u6307\u5411\u76ee\u5f55\n  -v, --version         \u8f93\u51fa\u7248\u672c\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "statsdir.",
    "version": "0.0.2.1",
    "project_urls": {
        "Homepage": "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/statsdir",
        "Repository": "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/statsdir"
    },
    "split_keywords": [
        "statsdir",
        " statistics"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1e5aadff71080e1c691728625fb96258348cc1ae8fa68aa1cd3ccc63d57a77ea",
                "md5": "bad34c4b7a1cdae68e4b89be91118502",
                "sha256": "93599a02d1d5d033d13b4fb64c72fbb6ef571aa69dcc5d4d962d035f7ea5cb0c"
            },
            "downloads": -1,
            "filename": "statsdir-0.0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bad34c4b7a1cdae68e4b89be91118502",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 8325,
            "upload_time": "2024-10-08T03:32:28",
            "upload_time_iso_8601": "2024-10-08T03:32:28.359731Z",
            "url": "https://files.pythonhosted.org/packages/1e/5a/adff71080e1c691728625fb96258348cc1ae8fa68aa1cd3ccc63d57a77ea/statsdir-0.0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d09b68c008dea69d61d4e961c5ebd60a6b0605cea5f82a43631594a823543e7b",
                "md5": "90fca9eb110bc37196e6160e363c04cb",
                "sha256": "1e02e5e14ecc6595fdad5f0577b33c6319205ae3facf38a08f9ef92424c9a1fc"
            },
            "downloads": -1,
            "filename": "statsdir-0.0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "90fca9eb110bc37196e6160e363c04cb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 5447,
            "upload_time": "2024-10-08T03:32:29",
            "upload_time_iso_8601": "2024-10-08T03:32:29.904702Z",
            "url": "https://files.pythonhosted.org/packages/d0/9b/68c008dea69d61d4e961c5ebd60a6b0605cea5f82a43631594a823543e7b/statsdir-0.0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-08 03:32:29",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ChenyangGao",
    "github_project": "web-mount-packs",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "statsdir"
}
        
Elapsed time: 0.36552s