PyFinder

介绍

PyFinder是由 这里是小邓 编写的一个 Python 本地文件查找解决方案。此库支持传统递归查找和多线程查找,是Python文件查找较好的解决方案之一。

仓库

https://gitee.com/This-is-XiaoDeng/py-finder

PS:有条件的建议直接去仓库看,毕竟下文是我从README.md照搬的

  • 注意:此项目目前未以【PyFinder】上传至pypi,至于pypi那个PyFinder只是重名了而已

软件架构

主要文件结构:

py-finder

|-README.md 自述文件

|- pyfinder.py 主库文件

安装方法

  1. 克隆本仓库
git clone https://gitee.com/This-is-XiaoDeng/py-finder.git
  1. pyfinder.py复制到(您要使用这个库的程序)的目录下
  2. 导入库
import pyfinder

or

from pyfinder import *

使用说明

我之后会上传几个Demo,到时候问题就不大了

函数列表

函数参数列表支持最大文件夹深度说明返回值
find()name = 文件名关键字 start=起始目录 wait=防死机等级(默认0.1)无限传统单线程递归查找法(不受递归次数约束)符合筛选条件的文件路径列表(list)
find_threads()name = 文件名关键字 start=起始目录 wait=防死机等级(默认0.01)约800层多线程查找法(受threading最大线程影响)符合筛选条件的文件路径列表(list)

调用示例

import pyfinder
f = pyfinder.find_threads(name="exe",start="C:\\")
print(f)

千万表像上面那么做,相信我,查找的时候永远也不要让符合筛选的文件过多,会内存溢出的(我就这么做过)

参与贡献

  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request

许可证

此程序采用 MIT 许可证

TODO

  •  完成多线程查找
  •  写demo
  •  打包上pypi
  •  大力宣传
  •  修复内存溢出的bug

贡献名单

代码

这里是小邓

调试

这里是小邓 熊熊糖果

Python3 PIP 安装

pip is the package installer for Python. You can use it to install packages from the Python Package Index and other indexes.

——pip.pypa.io

鲁迅先生曾经说过这样一句话:“没有pip的Python是没有灵魂的(是不是有点过了)。”

但是,很多人在使用pip的时候,或多或少会遇到这种情况:

[xiaodeng@xd-pc ~]$ python3 -m pip
/usr/bin/python3: No module named pip

如果你遇到了这个提示,那么恭喜你,你 的 Python 没 装 pip!

其实,这种情况很好解决,但是我曾经也被整的晕头转向,话不多说,上解决方案!

解决方案

通用

  1. 下载https://bootstrap.pypa.io/get-pip.py;
  2. 执行

Linux

可以吧这一段代码复制到终端执行:

wget https://bootstrap.pypa.io/get-pip.py
python3 ./get-pip.py
rm ./get-pip.py

输出(因人而异):

[xiaodeng@xd-pc ~]$ wget https://bootstrap.pypa.io/get-pip.py
--2021-12-11 15:07:06--  https://bootstrap.pypa.io/get-pip.py
SSL_INIT
已载入 CA 证书“/etc/ssl/certs/ca-certificates.crt”
正在解析主机 bootstrap.pypa.io (bootstrap.pypa.io)... 151.101.76.175, 2a04:4e42:12::175
正在连接 bootstrap.pypa.io (bootstrap.pypa.io)|151.101.76.175|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2159352 (2.1M) [text/x-python]
正在保存至: “get-pip.py”

get-pip.py          100%[===================>]   2.06M  3.34MB/s  用时 0.6s    

2021-12-11 15:07:07 (3.34 MB/s) - 已保存 “get-pip.py” [2159352/2159352])

[xiaodeng@xd-pc ~]$ python3 ./get-pip.py
Defaulting to user installation because normal site-packages is not writeable
Collecting pip
  Downloading pip-21.3.1-py3-none-any.whl (1.7 MB)
     |████████████████████████████████| 1.7 MB 1.7 MB/s            
Collecting wheel
  Downloading wheel-0.37.0-py2.py3-none-any.whl (35 kB)
Installing collected packages: wheel, pip
Successfully installed pip-21.3.1 wheel-0.37.0
[xiaodeng@xd-pc ~]$ rm ./get-pip.py
[xiaodeng@xd-pc ~]$ 

验证安装

[xiaodeng@xd-pc ~]$ python3 -m pip

Usage:   
  /usr/bin/python3 -m pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  cache                       Inspect and manage pip's wheel cache.
  index                       Inspect information available from package indexes.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  debug                       Show information useful for debugging.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --debug                     Let unhandled exceptions propagate outside the
                              main subroutine, instead of logging them to
                              stderr.
  --isolated                  Run pip in an isolated mode, ignoring
                              environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be
                              used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be
                              used up to 3 times (corresponding to WARNING,
                              ERROR, and CRITICAL logging levels).
  --log <path>                Path to a verbose appending log.
  --no-input                  Disable prompting for input.
  --proxy <proxy>             Specify a proxy in the form
                              [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should
                              attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists:
                              (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
  --trusted-host <hostname>   Mark this host or host:port pair as trusted,
                              even though it does not have valid or any HTTPS.
  --cert <path>               Path to PEM-encoded CA certificate bundle. If
                              provided, overrides the default. See 'SSL
                              Certificate Verification' in pip documentation
                              for more information.
  --client-cert <path>        Path to SSL client certificate, a single file
                              containing the private key and the certificate
                              in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine
                              whether a new version of pip is available for
                              download. Implied with --no-index.
  --no-color                  Suppress colored output.
  --no-python-version-warning
                              Silence deprecation warnings for upcoming
                              unsupported Pythons.
  --use-feature <feature>     Enable new functionality, that may be backward
                              incompatible.
  --use-deprecated <feature>  Enable deprecated functionality, that will be
                              removed in the future.
[xiaodeng@xd-pc ~]$ 

【接单日志 01】txtx解析工具

温馨提示:程序接单目前已经不再开放,但您仍然可以在issue中为新项目提供想法

详细信息

  • 单号:PYLIB-ORD-20211101
  • 委托人(QQ):3627035438
  • 项目:TXTX解析工具
  • 类型:Python库-ORD
  • 收费:1.0/1.0 CNY(付款方式:QQ)

代码:

./txtx.py

# Powered By XD(www.thisisxd.tk)
import os

def delzhushi(l,start = 0):
    s = l[start].find("#")
    li = l
    if s != -1:
        li[start] = li[start][0:s]
    if start == l.__len__()-1:
        return li
    else:
        return delzhushi(li,start+1)

def run(txt):
    t = txt
    le = 0
    for tx in t:
        where_w = tx.find("[Run_Windows]")
        where_u = tx.find("[Run_Unix](")
        if os.name == "nt":
            if where_w != -1:
                t.pop(le)
                #print(tx[where_w+14:tx.find(")",where_w)])
                os.popen(tx[where_w+14:tx.find(")",where_w)])
        else:
            if where_u != -1:
                t.pep(le)
                os.popen(tx[where_u+14:tx.find(")",where_u)])
        le += 1
    return t

def get_home(txtx):
    tx = txtx
    l = 0
    for t in tx:
        w = t.find("<[")
        if w != -1:
            home = t[w+2:t.find("]",w)]
            for i in range(l):
                tx.pop(0)
            if  home == "":
                raise TypeError("跟声明不能为空")
            else:
                return tx,home

def load(t):
    txtx = {}
    # 逐行分割
    t1 = t.split("\n")
    # 删除注释
    t1 = delzhushi(t1)
    # 跑命令
    t1 = run(t1)
    # 获取跟声明
    temp = get_home(t1)
    t1 = temp[0]
    home = temp[1]
    # 解析
    f = 1
    s = 0
    tw = [False]
    tg = False
    txtx[home] = {}
    y = 0
    for t in t1:
        s += 1
        temp = {}
        k_start = t.find("[")
        if k_start != -1 and tg == False and t.find("<[") == -1:
            k_end = t.find("]",k_start)
            if k_end != -1:
                v_start = t.find("(",k_end)
                if v_start != -1:
                    v_end = t.find(")",v_start)
                    if v_end == -1:
                        raise KeyError(f"行0{s}:这个值没有结尾")
                else:
                     raise KeyError(f"行0{s}:一个没有意义的键")
            else:
                raise KeyError(f"行0{s}:这个键没有结尾")
            # 能执行到这里这行基本就是有效的了
            print(1,t.find("<["),tg,home)
            # 分析键
            key = t[k_start+1:k_end]
            value = t[v_start+1:v_end]
            # 储存
            txtx[home][key] = value
        else:
            tmp = t.find("<[")
            if tmp != -1 and t[tmp+2:t.find("]",tmp)] != home:
                tg = True
                tw[0] = True
                if y != 1:
                    tw  += [[s,t[tmp+2:t.find("]",tmp)]]]
                y += 1
            elif t.find(">") != -1:
                tg = False
                if y == 1:
                    try:
                        tw[tw.__len__()-1] += [s]
                    except:
                        pass
                    y -= 1
                else:
                    y -= 1
                print(t[tmp:t.find("]",tmp)],tw)
            print("y",y)
    if tw[0] == True:
        for tn in tw:
            print("tn",tn,t1)
            if tn != True:
                cs = ""
                for i in t1[tn[0]-1:tn[2]]:
                    cs += str(i)
                    cs += "\n"
                print("cs",cs)
                print("递归后输出:")
                # txtx[home][t[2]] = load(cs)
                tmp114514  =  load(cs)
                print(tmp114514)
                txtx[home][tmp114514[1]] = tmp114514[0][tn[1]]#[[tmp114514[1]]]   #[tmp114514[1]]
    else:
        print("ELSE")
                
        
    # 返回
    return [txtx,home]

def loads(txtx):
    return load(txtx)[0]

def open(path,encoding = "utf-8"):
    with open(path,encoding = encoding) as f:
        return loads(f.read())

用法

import txtx

函数参数函数描述返回说明
txtx.open(path,ecoding="utf-8")[path] txtx文件路径 (String)
[encoding] 文件编码(默认=utf-8)(string)
打开txtx文件返回解析结果(dictionary)
txtx.loads(txtx)[txtx] txtx内容 (String)解析txtx字符串返回解析结果(dictionary)
txtx解析器主要函数说明

世界,您好!

警告:本文可能已经过时

欢迎使用WordPress。这是您的第一篇文章。编辑或删除它,然后开始写作吧!