确定当前(或指定)目录树中的最大深度和路径长度。

deepest的Python项目详细描述


最深

Build StatusCoverage Status

Diavik Diamond Mine, Canada

“There are older and fouler things than Orcs in the deep places of the world.”

— Gandalf, from “The Lord of the Rings: The Fellowship of the Ring”, by J.R.R. Tolkien

deep-使用的跨平台(和跨语言)命令行实用程序 确定当前(或指定的)目录树的最大深度。

在Python和C++口味中都可用(通过^ {A3}库)。

基本原理

  • 需要一种方法来确定项目与 8-由ISO-9660定义的子目录限制。
  • 需要一种方法来确定距离MAX_PATH目录有多近 正在获取。
    • MAX_PATH在Windows:3上定义为驱动器的260个字符 (C:\),1表示结尾的NULL字符,256 对于中间目录、反斜线、文件名和扩展名。
  • “是的,但是……为什么是Python?“
    • 它的原型更快。(偏见…我只是更熟悉它。)
    • 这给了我一个尝试ShedSkin的借口。:-)

要求

  • python>;=2.7、3.2、3.3、3.4、3.5、3.6
  • shedskin=0.9.3,0.9.4-可选
  • g++>;=4.6.2或clang++>;=3.2-可选
  • mingw/msys(2012-04-26目录)-可选

安装

python(用户)

pip install deepest

python(开发人员)

git clone git@github.com:markgollnick/deepest.git
cd deepest
python setup.py build install
# Alternatively...
make python
pip install dist/deepest-*.tar.gz

^ {STR 1 } $C++< /强>:

  1. 下载并安装ShedSkininstructions)。

  2. 运行以下命令:

    ./3to2  # Make some minor adjustments for ShedSkin compatibility
    cd deepest  # This is the dir INSIDE the project's root dir
    shedskin deepest.py
    make
    # Alternatively, from the project's root dir...
    make cpp
    

使用量

python:

安装后,您可以将其用作脚本…

$ deepest .
breadth of dirs examined    longest pathname    deepest directory
                      13                  58                    7

longest file: ./workspace/dwarves/digging/deep/deeper/deepest/balrog.log
deepest path: ./workspace/some/really/long/directory/chain/here

…或者,您可以将其用作库:

>>> import deepest
>>> deepest.get_depth('c:\\workspace')
('c:\\workspace\\some\\really\\long\\directory\\chain\\here', 7)
>>> deepest.get_length('c:\\workspace')
('c:\\workspace\\dwarves\\digging\\deep\\deeper\\deepest\\balrog.log', 59)

^ {STR 1 } $c++:< /强>

编译完成后,它是python脚本的一种(特别是更快的)替代方案:

$ deepest c:\\workspace
breadth of dirs examined    longest pathname    deepest directory
                      13                  59                    7

longest file: c:\workspace\dwarves\digging\deep\deeper\deepest\balrog.log
deepest path: c:\workspace\some\really\long\directory\chain\here

速度

在一个包含5000多个目录、最大深度为13的项目中, Python和C++版本(用CLAN-503.0.40编译)是针对每个 其他。这两个版本都在2013年底的MacBookPro上运行了三次。

这些是平均结果:

$ time deepest  # Python script
...
real    0m0.423s
user    0m0.244s
sys     0m0.160s

$ time deepest  # C++ binary
...
real    0m0.169s
user    0m0.063s
sys     0m0.101s
在实际观察中,使用编译后的C++版本可以在任何地方获得您。 从10%到高达60%的速度提升。:-)

许可证

Boost软件许可证,1.0版:<;http://www.boost.org/LICENSE_1_0.txt>;

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
插入表达式以完成JAVA语句块时出现语法错误   在linkedlist中的特定节点后插入java   java如何将参数传递给安卓 junit测试(参数化测试)   java在运行时将数据添加到片段中的RecyclerView,在该片段中,数据是在单独的片段中创建的   java apache CsrfPreventionFilter和404错误   java Ask是安卓 6.0的多重权限   java将字符串解析为Time并插入mysqldatabase   java扩展MyBatis映射器接口可能导致异常   java SparkSql不支持日期格式   在java中剪切字符串的一部分   将Java lambda的结果分配给字段   在Java中解析OCL?   java解析json到安卓中活动中的对象   用于时区转换的JavaAPI   在Oracle上建立与ESRI geodatabase直接连接的java在未处于调试模式时挂起   拆分文件时出错。使用Java8的xml文件   java eclipse jsp无颜色、代码完成和错误检测   java spring kafka侦听器在错误的位置查找ContainerProperty   java Springboot应用程序@EnableConfigServer无法在Eclipse中解析   当尝试使用ConstraintLayout将java视图添加到同一行时,java视图会被截断