From e3fc379cca650375ee49e09a210fe315a7ac5fa4 Mon Sep 17 00:00:00 2001 From: Yadnyawalk Tale Date: Mon, 10 Feb 2020 01:39:49 +0530 Subject: [PATCH] Copying related improvement Copy password to clipboard after -- * new password creation * without printing it on screen --- pygenpass/__init__.py | 2 ++ pygenpass/password.py | 16 ++++++++++++---- requirements.txt | 1 + setup.cfg | 1 + 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pygenpass/__init__.py b/pygenpass/__init__.py index c7a5372..c134fc0 100644 --- a/pygenpass/__init__.py +++ b/pygenpass/__init__.py @@ -22,6 +22,7 @@ import click from pygenpass.password import allpass +from pygenpass.password import copypass from pygenpass.password import createpass from pygenpass.password import delpass from pygenpass.password import modpass @@ -42,6 +43,7 @@ def main(): main.add_command(savepass) main.add_command(delpass) main.add_command(version) +main.add_command(copypass) if __name__ == "__main__": main() diff --git a/pygenpass/password.py b/pygenpass/password.py index 3ee29a8..9bc3244 100644 --- a/pygenpass/password.py +++ b/pygenpass/password.py @@ -19,12 +19,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -from datetime import date +import click # Used for command line interface +import diceware # Used for creating password +import pyperclip -import click -import diceware from beautifultable import BeautifulTable - +from datetime import date from pygenpass.database import DatabaseConnection db_obj = DatabaseConnection() @@ -96,6 +96,7 @@ def createpass(): """Used for taking input from user to create password""" portal_name = click.prompt("Enter portal name", default="None") password = diceware.get_passphrase() + pyperclip.copy(password) creation_date = date.today() email = click.prompt("Enter email id", default="None") portal_url = click.prompt("Enter portal url", default="None") @@ -116,3 +117,10 @@ def showpass(): print("No records found") else: print(spass) + + +@click.command("copy", help="Copy password") +@click.argument("portal_name") +def copypass(portal_name): + password = db_obj.show_data(portal_name) + pyperclip.copy(password) diff --git a/requirements.txt b/requirements.txt index f22be4f..20a912e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ diceware>=0.9.6 click>=7.0 beautifultable>=0.5.0 setuptools>=40.0.0 +pyperclip>=1.7.0 diff --git a/setup.cfg b/setup.cfg index 074f436..e9786e7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -30,6 +30,7 @@ install_requires = beautifultable click diceware + pyperclip [options.entry_points] console_scripts =