Skip to content

Commit

Permalink
Merge pull request #72 from mayurilahane/updated_commands
Browse files Browse the repository at this point in the history
Updated commands and added module for colorful printable output.
  • Loading branch information
mayurilahane authored Mar 22, 2020
2 parents 01bedac + aae5173 commit 1e53fa3
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 38 deletions.
20 changes: 10 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ Command line options
--help Show this message and exit.
Commands:
allpass Show all passwords
createpass Create new password
delpass Delete password
modpass Update password
savepass Save existing passwords
showpass Show password
version Show Version
all Show all passwords
create Create new password
delete Delete password
modify Update password
save Save existing passwords
show Show password
version Show Version
Examples
========
* This command will ask for portal name and will create random password

.. code-block:: bash
$ pygenpass createpass
$ pygenpass create
Enter portal name [None]:
Enter email id [None]:
Expand All @@ -73,7 +73,7 @@ Examples

.. code-block:: bash
$ pygenpass savepass
$ pygenpass save
Enter portal name [None]:
Enter your password [None]:
Expand All @@ -84,7 +84,7 @@ Examples

.. code-block:: bash
$ pygenpass showpass
$ pygenpass show
Enter portal name [None]:
Expand Down
24 changes: 12 additions & 12 deletions pygenpass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
"""
import click

from pygenpass.password import allpass
from pygenpass.password import createpass
from pygenpass.password import delpass
from pygenpass.password import modpass
from pygenpass.password import savepass
from pygenpass.password import showpass
from pygenpass.password import add
from pygenpass.password import all
from pygenpass.password import create
from pygenpass.password import delete
from pygenpass.password import modify
from pygenpass.password import show
from pygenpass.password import version


Expand All @@ -35,12 +35,12 @@ def main():
pass


main.add_command(allpass)
main.add_command(modpass)
main.add_command(createpass)
main.add_command(showpass)
main.add_command(savepass)
main.add_command(delpass)
main.add_command(all)
main.add_command(modify)
main.add_command(create)
main.add_command(show)
main.add_command(add)
main.add_command(delete)
main.add_command(version)

if __name__ == "__main__":
Expand Down
19 changes: 13 additions & 6 deletions pygenpass/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"""
import sqlite3 # library for database

from termcolor import colored


class DatabaseConnection:
""" Class of database entries for user's information."""
Expand All @@ -45,12 +47,17 @@ def insert_data(self, portal_name, password, creation_date, email, portal_url):
self.email = email
self.portal_name = portal_name
self.portal_url = portal_url
self.cursor_obj.execute(
"""INSERT INTO passwords
(portal_name, password, creation_date, email, portal_url)
VALUES (?, ?, ?, ?, ?)""",
(self.portal_name, self.password, self.creation_date, self.email, self.portal_url),
)
try:
self.cursor_obj.execute(
"""INSERT INTO passwords
(portal_name, password, creation_date, email, portal_url)
VALUES (?, ?, ?, ?, ?)""",
(self.portal_name, self.password, self.creation_date, self.email, self.portal_url),
)
except sqlite3.IntegrityError:
print(
colored("Already exists with the same name. Try with another Portal_name", "green")
)
self.con.commit()

def delete_data(self, portal_name):
Expand Down
21 changes: 11 additions & 10 deletions pygenpass/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import click
import diceware
from beautifultable import BeautifulTable
from termcolor import colored

from pygenpass.database import DatabaseConnection

Expand All @@ -38,21 +39,21 @@

@click.command(help="Show Version")
def version():
click.echo("PyGenpass v0.2")
click.echo(colored("PyGenpass v0.2", "green"))


@click.command(help="Show all passwords")
def allpass():
def all():
all_pass = db_obj.show_all_data()
if all_pass == []:
print("No records found")
print(colored("No records found", "green"))
for row in all_pass:
table.append_row([row[0], row[1], row[2], row[3], row[4], row[5]])
print(table)


@click.command(help="Delete password")
def delpass():
def delete():
"""used to delete existing password"""
portal_name = click.prompt("Enter portal name", default="None")
value_check = db_obj.show_data(portal_name)
Expand All @@ -63,7 +64,7 @@ def delpass():


@click.command(help="Update password")
def modpass():
def modify():
"""Update existing password"""
portal_name = click.prompt("Enter portal name", default="None")
mod_check = db_obj.show_data(portal_name)
Expand All @@ -74,8 +75,8 @@ def modpass():
db_obj.update_data(portal_name=portal_name, password=mod)


@click.command(help="Save existing passwords")
def savepass():
@click.command(help="Add existing passwords")
def add():
"""Used to take portal name and password from user"""
portal_name = click.prompt("Enter portal name", default="None")
pwd = click.prompt("Enter your password", default="None", hide_input=True)
Expand All @@ -92,7 +93,7 @@ def savepass():


@click.command(help="Create new password")
def createpass():
def create():
"""Used for taking input from user to create password"""
portal_name = click.prompt("Enter portal name", default="None")
password = diceware.get_passphrase()
Expand All @@ -109,10 +110,10 @@ def createpass():


@click.command(help="Show password")
def showpass():
def show():
portal_name = click.prompt("Enter portal name", default="None")
spass = db_obj.show_data(portal_name)
if spass is None:
print("No records found")
print(colored("No records found", "green"))
else:
print(spass)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ diceware>=0.9.6
click>=7.0
beautifultable>=0.5.0
setuptools>=40.0.0
termcolor>=1.1.0
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ install_requires =
beautifultable
click
diceware
termcolor

[options.entry_points]
console_scripts =
Expand Down

0 comments on commit 1e53fa3

Please sign in to comment.