__main__.py 文件源码

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

项目:passpy 作者: bfrascher 项目源码 文件源码
def generate(ctx, pass_name, pass_length, no_symbols, clip, in_place, force):
    """Generate a new password of length `pass-length` and insert into
    `pass-name`.  If `--no-symbols` or `-n` is specified, do not use
    any non-alphanumeric characters in the generated password.  If
    `--clip` or `-c` is specified, do not print the password but
    instead copy it to the clipboard.  On Linux you will need to have
    xclip/xsel and on OSX pbcopy/pbpaste installed.  Prompt before
    overwriting an existing password, unless `--force` or `-f` is
    specified.  If `--in-place` or `-i` is specified, do not
    interactively prompt, and only replace the first line of the
    password file with the new generated password, keeping the
    remainder of the file intact.

    """
    symbols = not no_symbols
    try:
        password = ctx.obj.gen_key(pass_name, pass_length, symbols,
                                   force, in_place)
    except StoreNotInitialisedError:
        click.echo(MSG_STORE_NOT_INITIALISED_ERROR)
        return 1
    except PermissionError:
        click.echo(MSG_PERMISSION_ERROR)
        return 1
    except FileNotFoundError:
        click.echo(MSG_FILE_NOT_FOUND.format(pass_name))
        return 1

    if password is None:
        return 1

    if clip:
        pyperclip.copy(password)
        click.echo('Copied {0} to the clipboard.'.format(pass_name))
    else:
        click.echo('The generated password for {0} is:'.format(pass_name))
        click.echo(password)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号