Multiprocess directory iteration via os.scandir() with progress indicator via tqdm bars.
Project description
IterFilesystem
Multiprocess directory iteration via os.scandir()
Who’s this Lib for?
You want to process a large number of files and/or a few very big files and give feedback to the user on how long it will take.
Features:
Progress indicator:
Immediately after start: process files and indication of progress via multiprocess
process bars via tqdm
Estimated time based on file count and size
Easy to implement extra process bar for big file processing.
Skip directories and file name via fnmatch.
How it works:
The main process starts statistic processes in background via Python multiprocess and starts directly with the work.
There are two background statistic processes collects information for the process bars:
Count up all directories and files.
Accumulates the sizes of all files.
Why two processes?
Because collect only the count of all filesystem items via os.scandir() is very fast. This is the fastest way to predict a processing time.
Use os.DirEntry.stat() to get the file size is significantly slower: It requires another system call.
OK, but why two processed?
Use only the total count of all DirEntry may result in bad estimated time Progress indication. It depends on what the actual work is about: When processing the contents of large files, it is good to know how much total data to be processed.
That’s why we used two ways: the DirEntry count to forecast a processing time very quickly and the size to improve the predicted time.
requirements:
Python 3.6 or newer.
tqdm for process bars
psutils for setting process priority
For dev.: Pipenv. Packages and virtual environment manager
contribute
Please: try, fork and contribute! ;)
Example
Use example CLI, e.g.:
~$ 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.
example output looks like this:
(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.
History
**dev** - compare v1.4.3…master
TBC
-
Use logging and remove “verbose mode”
Nicer “Average progess” bar
Bugfix “Current File” bar: remove comma
-
iterate over sorted dir entries
update CI pipelines
-
Bugfix human_filesize
-
stats_helper.abort exists always usefull to get information if KeyboardInterrupt was used
use poetry and modernize project setup
-
Bugfix if scan directory is completely empty
-
Set ionice and nice priority via psutils
-
Refactor API
cleanup statistics and process bar
handle access errors like: Permission denied
fix tests
-
don’t create separate process for worker: Just do the work in main process
dir/file filter uses now fnmatch
-
refactoring:
don’t use persist-queue
switch from threading to multiprocessing
enhance progress display with multiple tqdm process bars
-
store persist queue in temp directory
Don’t catch process_path_item errors, this should be made in child class
-
add some project meta files and tests
setup CI
fix tests
-
first Release on PyPi
Links
Donating
Note: this file is generated from README.creole 2020-03-16 18:09:30 with "python-creole"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file IterFilesystem-1.4.3.tar.gz
.
File metadata
- Download URL: IterFilesystem-1.4.3.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a51eb6e7dc365dcf82aac0cbd244189d3dbb4243f54887033ee634565f0ac03 |
|
MD5 | 4ab123434c034157ffc49d9144d5818e |
|
BLAKE2b-256 | fb2a7b3bf7367a0722cfd4b3e0abdb845216944e54184dc628ae15dba7714703 |
File details
Details for the file IterFilesystem-1.4.3-py3-none-any.whl
.
File metadata
- Download URL: IterFilesystem-1.4.3-py3-none-any.whl
- Upload date:
- Size: 23.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f6d97369ffce0bff16c17d7d47b1af5d5a8d9c42a14eed7b90247ed9ce65c76 |
|
MD5 | c26732f830d268e7679147b2b02cf33e |
|
BLAKE2b-256 | e25e2d061c014f8edce4383737729ba49a24d0fd4693f56813fe0c1c44d56bdf |