python绑定到linux系统调用getdents64。
getdents的Python项目详细描述
使用python有效地迭代大目录。
关于
python-getdents是Linux系统调用getdents64的简单包装(有关详细信息,请参见man getdents)。More details进近。
待办事项
- 验证实现是否在x86_64以外的平台上工作。
安装
pip install getdents
用于开发
python3 -m venv env . env/bin/activate pip install -e .[test]
运行测试
ulimit -v 33554432&& py.test tests/
或
ulimit -v 33554432&& ./setup.py test
用法
fromgetdentsimportgetdentsforinode,type,nameingetdents('/tmp',32768):print(name)
高级
importosfromgetdentsimport*fd=os.open('/tmp',O_GETDENTS)forinode,type,nameingetdents_raw(fd,2**20):print({DT_BLK:'blockdev',DT_CHR:'chardev ',DT_DIR:'dir ',DT_FIFO:'pipe ',DT_LNK:'symlink ',DT_REG:'file ',DT_SOCK:'socket ',DT_UNKNOWN:'unknown ',}[type],{True:'d',False:' ',}[inode==0],name,)os.close(fd)
cli
用法
python-getdents [-h] [-b N] [-o NAME] PATH
选项
Option | Description |
---|---|
^{tt5}$ | Buffer size (in bytes) to allocate when iterating over directory. Default is 32768, the same value used by glibc, you probably want to increase this value. Try starting with 16777216 (16 MiB). Best performance is achieved when buffer size rounds to size of the file system block. |
^{tt6}$ | |
^{tt7}$ | Output format:
|
^{tt14}$ |
< H4>退出代码< /H4>
- 3-请求的缓冲区太大
- 找不到4-PATH。
- 5-PATH不是目录。
- 6-权限不足,无法读取PATH的内容。
示例
python-getdents /path/to/large/dir
python -m getdents /path/to/large/dir
python-getdents /path/to/large/dir -o csv -b 16777216 > dir.csv