便携式pwd(打印工作目录)。

pwdpp的Python项目详细描述


“pwdpp”是用python编写的可移植pwd(打印工作目录)。

要求

  • python 2.7或更高版本
  • psutil如果使用正式的cpython windows二进制文件。

用法

you@yourhost: ~$ pwdpp --help

usage: pwdpp [-h] [-P] [-L] [-s {bs,fs}] [-W]

Print the full filename of the current working directory.

optional arguments:
  -h, --help            show this help message and exit
  -P, --physical
                        avoid all symlinks (default).
                        (if your system can reveal symlinks.)

  -L, --logical
                        use PWD from environment, even if it
                        contains symlinks.
                        (if your system can't detect symlinks,
                        this option has no effect.)

  -s {bs,fs}, --pathsep {bs,fs}

                        specify path separator.
                        (bs: backslash / fs: forward slash.)

  -W
                        print the Win32 value of the physical
                        directory. this is a simple emulation of
                        bash's pwd on MSYS(2). Of course, this makes
                        no sense on *nix.

您可能需要设置pythonionecoding环境变量,例如'pythonionecoding=utf-8'。

动机

  1. bash内置的msys和msys2的pwd具有特定于windows的-w选项,用于打印真正的windows路径。
  2. 但巴什的塞格温内置密码没有。
  3. -w选项当然是windows特有的,因此我们永远不能在*nix平台中使用它。
  4. cygwin、msys和msys2各自维护自己的挂载表,并且基于它们的绝对路径表达式彼此不同。
  • If you are in these boxes, normally you want to follow these manners.
  • But sometimes you need to know the path as Windows native path.
  • If so, the lack of -W on cygwin’s pwd is the matter.

使用pwdpp作为python模块

pwdpp作为一个模块非常简单,它只公开两个方法和一个变量:

>>> import os
>>> import pwdpp
>>> pwdpp.__all__
[u'caller_type', u'curdir', u'main']
>>> pwdpp.caller_type
(u'win32', u'mingw32', u'C:\\MinGW\\msys\\1.0\\bin\\sh.exe')
>>> help(pwdpp.curdir)
Help on function curdir in module pwdpp:

curdir(physical, winpath=False)
    Return the current directory according to the following rules:
    +---------------+-----------------------------+----------------------+
    | from          | python                      | default              |
    +===============+=============================+======================+
    | cmd.exe       | official CPython on windows | follow the behavior  |
    |               |                             | of windows native.   |
    +---------------+-----------------------------+----------------------+
    | msys          | official CPython on windows | follow the behavior  |
    | (bash, etc.)  +-----------------------------+ of MSYS.             |
    |               | msys CPython? if any,       |                      |
    +---------------+-----------------------------+----------------------+
    | msys2         | official CPython on windows | follow the behavior  |
    | (bash, etc.)  +-----------------------------+ of MSYS2.            |
    |               | msys2 CPython               |                      |
    +---------------+-----------------------------+----------------------+
    | cygwin        | official CPython on windows | follow the behavior  |
    | (bash, etc.)  +-----------------------------+ of cygwin.           |
    |               | cygwin CPython              |                      |
    +---------------+-----------------------------+----------------------+
    | *nix shell    | various                     | follow the behavior  |
    |               |                             | of *nix native.      |
    +---------------+-----------------------------+----------------------+
    Except but the case following windows native, physical=True
    corresponds to "pwd -P", physical=False corresponds to "pwd -L".

    If winpath=True, this function follow the behavior of windows native,
    even if cygwin. Of course this makes no sense on real *nix.

>>> pwdpp.curdir(True, True)
u'c:\\Users\\hhsprings\\work'
>>> pwdpp.curdir(True, False)
u'/c/Users\\hhsprings\\work'
>>> os.chdir("c:/MinGW/msys/1.0/bin")  # my msys root
>>> pwdpp.curdir(True, True)
u'c:\\MinGW\\msys\\1.0\\bin'
>>> pwdpp.curdir(True, False)
u'\\usr\\bin'
>>> pwdpp.curdir(True, False).replace(u"\\", u"/")
u'/usr/bin'

main只是cli的入口点。

历史记录

1.0.6(2017-8-09)

  • 源代码与1.0.3相同。(仅用于上传到pypi。)

1.0.4-1.05(2017-8-09)

  • 不见了。上传到pypi是个错误。

1.0.3(2017-8-09)

  • 修正cwd是否为msys根目录。

1.0.2(2017-8-09)

  • 修复父级为“env.exe”的问题。
  • 呼叫者类型的第二项已损坏…

1.0.1(2017-8-09)

  • 修复Unicode问题(python 3.x)

1.0.0(2017-8-09)

  • 首次发布

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

推荐PyPI第三方库


热门话题
Java如何添加排除某个数字的随机生成器?   在Eclipse中将所有包集中在一个包中(对于Java项目)   java在部署我的应用程序后无法连接到MySQL   Ntier应用程序中的java NoClassDefFoundException   java泛型类型转换?   使用buildr编译期间的java jar插件   java查找排序数组中重复值的计数   运行Spring Boot cmdline的java示例给出了“找不到run()方法”`   java为什么不调用windowClosed?   java jsch身份验证在没有私钥的情况下失败   java如何在我的jtable中获得100多行?   java在遗留Android Studio项目中创建测试文件夹   java 安卓。所容纳之物res.Resources$NotFoundException:资源ID#0x7f080087   java Eclipse自动格式化变量初始化