跳转到主要内容

通过os.scandir()进行多进程目录迭代,并通过tqdm进度条显示进度。

项目描述

IterFilesystem

通过 os.scandir() 进行多进程目录迭代

这个库适合谁使用?

您想处理大量文件和/或几个非常大的文件,并给用户反馈处理所需时间。

特性

  • 进度指示器

    • 启动后立即:通过多进程处理文件,并通过进度条显示进度

    • 使用 tqdm 进度条

    • 基于文件数量和大小估算时间

  • 易于实现针对大文件处理的额外进度条。

  • 通过fnmatch跳过目录和文件名。

工作原理

主进程通过Python多进程在后台启动 统计 进程,并直接开始工作。

有两个后台 统计 进程收集进度条的必要信息

  • 计算所有目录和文件的数量。

  • 累积所有文件的大小。

为什么需要两个进程?

因为仅通过 os.scandir() 收集所有文件系统的项目计数非常快。这是预测处理时间最快的方法。

使用 os.DirEntry.stat() 来获取文件大小会慢得多:它需要另一个系统调用。

好吧,但为什么有两个处理过程呢?

仅使用所有 DirEntry 的总数可能会导致进度指示的估计时间不准确。它取决于实际工作的性质:当处理大文件的正文内容时,了解要处理的总数据量是很好的。

这就是为什么我们使用了两种方法:使用 DirEntry 计数来非常快速地预测处理时间,并使用大小来改进预测时间。

需求

  • Python 3.6 或更高版本。

  • tqdm 用于进度条

  • psutils 用于设置进程优先级

  • 对于开发者:[Pipenv](https://pipenv.readthedocs.io/en/latest/install/#installing-pipenv)。包和虚拟环境管理器

贡献

请:尝试、分支并贡献! ;)

Build Status on travis-ci.org

travis-ci.org/jedie/IterFilesystem

Build Status on appveyor.com

ci.appveyor.com/project/jedie/IterFilesystem

Coverage Status on codecov.io

codecov.io/gh/jedie/IterFilesystem

Coverage Status on coveralls.io

coveralls.io/r/jedie/IterFilesystem

Requirements Status on requires.io

requires.io/github/jedie/IterFilesystem/requirements/

示例

使用示例 CLI,例如。

~$ git clone https://github.com/jedie/IterFilesystem.git
~$ cd IterFilesystem
~/IterFilesystem$ pipenv install
~/IterFilesystem$ pipenv shell
(IterFilesystem) ~/IterFilesystem$ print_fs_stats --help
(IterFilesystem) ~/IterFilesystem$ pip install -e .
...
Successfully installed iterfilesystem

~/IterFilesystem$ $ poetry run print_fs_stats --help
usage: print_fs_stats.py [-h] [-v] [--debug] [--path PATH]
                         [--skip_dir_patterns [SKIP_DIR_PATTERNS [SKIP_DIR_PATTERNS ...]]]
                         [--skip_file_patterns [SKIP_FILE_PATTERNS [SKIP_FILE_PATTERNS ...]]]

Scan filesystem and print some information

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  --debug               enable DEBUG
  --path PATH           The file path that should be scanned e.g.: "~/foobar/"
                        default is "~"
  --skip_dir_patterns [SKIP_DIR_PATTERNS [SKIP_DIR_PATTERNS ...]]
                        Directory names to exclude from scan.
  --skip_file_patterns [SKIP_FILE_PATTERNS [SKIP_FILE_PATTERNS ...]]
                        File names to ignore.

示例输出如下

(IterFilesystem) ~/IterFilesystem$ $ print_fs_stats --path ~/IterFilesystem --skip_dir_patterns ".*" "*.egg-info" --skip_file_patterns ".*"
Read/process: '~/IterFilesystem'...
Skip directory patterns:
    * .*
    * *.egg-info

Skip file patterns:
    * .*

Filesystem items..:Read/process: '~/IterFilesystem'...

...

Filesystem items..: 100%|█████████████████████████████████████████|135/135 13737.14entries/s [00:00<00:00, 13737.14entries/s]
File sizes........: 100%|██████████████████████████████████████████████████████████████|843k/843k [00:00<00:00, 88.5MBytes/s]
Average progress..: 100%|███████████████████████████████████████████████████████████████████████████████████████|00:00<00:00
Current File......:, /home/jens/repos/IterFilesystem/Pipfile


Processed 135 filesystem items in 0.02 sec
SHA515 hash calculated over all file content: 10f9475b21977f5aea1d4657a0e09ad153a594ab30abc2383bf107dbc60c430928596e368ebefab3e78ede61dcc101cb638a845348fe908786cb8754393439ef
File count: 109
Total file size: 843.5 KB
6 directories skipped.
6 files skipped.

历史记录

捐赠


注意:此文件由 README.creole 于 2020-03-16 18:09:30 生成,使用 "python-creole"。

项目详细信息


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

IterFilesystem-1.4.3.tar.gz (20.5 kB 查看哈希值)

上传时间 源代码

构建分发

IterFilesystem-1.4.3-py3-none-any.whl (23.5 kB 查看哈希值)

上传时间 Python 3