__main__.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:passpy 作者: bfrascher 项目源码 文件源码
def show(ctx, pass_name, clip, passthrough=False):
    """Decrypt and print a password named `pass-name`.  If `--clip` or
    `-c` is specified, do not print the password but instead copy the
    first line to the clipboard using pyperclip.  On Linux you will
    need to have xclip/xsel and on OSX pbcopy/pbpaste installed.

    """
    try:
        data = ctx.obj.get_key(pass_name)
    # If pass_name is actually a folder in the password store pass
    # lists the folder instead.
    except FileNotFoundError:
        if not passthrough:
            return ctx.invoke(ls, subfolder=pass_name, passthrough=True)
        else:
            click.echo(MSG_FILE_NOT_FOUND.format(pass_name))
            return 1
    except StoreNotInitialisedError:
        click.echo(MSG_STORE_NOT_INITIALISED_ERROR)
        return 1
    except PermissionError:
        click.echo(MSG_PERMISSION_ERROR)
        return 1

    if clip:
        pyperclip.copy(data.split('\n')[0])
        click.echo('Copied {0} to the clipboard.'.format(pass_name))
    else:
        # The key data always ends with a newline.  So no need to add
        # another one.
        click.echo(data, nl=False)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号