Skip to content

Commit

Permalink
Formatted files using pep8 standerds
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurilahane committed Jan 13, 2020
1 parent c95c773 commit eedb4d9
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 63 deletions.
103 changes: 54 additions & 49 deletions genpass/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,63 +24,68 @@


class DatabaseConnection(object):
""" Class of database entries for user's information."""
""" Class of database entries for user's information."""

def __init__(self):
"""Used to create database and then to connect with generated databse file"""
self.con = sqlite3.connect('generated_password.db')
self.cursor_obj = self.con.cursor()
def __init__(self):
"""Used to create database and then to connect with generated databse file"""
self.con = sqlite3.connect("generated_password.db")
self.cursor_obj = self.con.cursor()

def create_table(self):
"""Checked for table is created? if not then created as per required values """
self.cursor_obj.execute(
"""CREATE TABLE IF NOT EXISTS passwords
def create_table(self):
"""Checked for table is created? if not then created as per required values """
self.cursor_obj.execute(
"""CREATE TABLE IF NOT EXISTS passwords
(id integer PRIMARY KEY,portal_name text NOT NULL UNIQUE, password varchar,
creation_date varchar, email varchar, portal_url varchar)
""")
self.con.commit()
"""
)
self.con.commit()

def insert_data(self, portal_name, password, creation_date, email, portal_url):
"""Adding values into database"""
try:
self.portal_name = portal_name
self.password = password
self.creation_date = creation_date
self.email = email
self.portal_url = portal_url
self.cursor_obj.execute\
("""INSERT INTO passwords
def insert_data(self, portal_name, password, creation_date, email, portal_url):
"""Adding values into database"""
try:
self.portal_name = portal_name
self.password = password
self.creation_date = creation_date
self.email = email
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),
)
self.con.commit()
except sqlite3.IntegrityError:
print("Portal name already exists")
VALUES (?, ?, ?, ?, ?)""",
(self.portal_name, self.password, self.creation_date, self.email, self.portal_url),
)
self.con.commit()
except sqlite3.IntegrityError:
print("Portal name already exists")

def delete_data(self, portal_name):
"""Deleting values from database"""
self.portal_name = portal_name
def delete_data(self, portal_name):
"""Deleting values from database"""
self.portal_name = portal_name

self.cursor_obj.execute("""DELETE from passwords where portal_name = ?""",
(self.portal_name,))
self.con.commit()
self.cursor_obj.execute(
"""DELETE from passwords where portal_name = ?""", (self.portal_name,)
)
self.con.commit()

def update_data(self, portal_name, password):
"""Updating values in database"""
self.portal_name = portal_name
self.password = password
self.cursor_obj.execute("""UPDATE passwords SET password =? WHERE portal_name =?""",
(self.password, self.portal_name))
self.con.commit()
def update_data(self, portal_name, password):
"""Updating values in database"""
self.portal_name = portal_name
self.password = password
self.cursor_obj.execute(
"""UPDATE passwords SET password =? WHERE portal_name =?""",
(self.password, self.portal_name),
)
self.con.commit()

def show_data(self, portal_name):
"""All inserted data will showed"""
self.portal_name = portal_name
def show_data(self, portal_name):
"""All inserted data will showed"""
self.portal_name = portal_name

self.cursor_obj.execute("""SELECT password FROM passwords WHERE portal_name=?""",
(self.portal_name,))
rows = self.cursor_obj.fetchall()
for row in rows:
return row[0]
self.con.commit()
self.cursor_obj.execute(
"""SELECT password FROM passwords WHERE portal_name=?""", (self.portal_name,)
)
rows = self.cursor_obj.fetchall()
for row in rows:
return row[0]
self.con.commit()
28 changes: 16 additions & 12 deletions genpass/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,43 +35,47 @@ def version():
@click.command(help="Delete password")
def delpass():
"""used to delete existing password"""
portal_name = click.prompt('Enter portal name', default="None")
portal_name = click.prompt("Enter portal name", default="None")
db_obj.delete_data(portal_name=portal_name)


@click.command(help="Update password")
def modpass():
"""Update existing password"""
portal_name = click.prompt('Enter portal name', default="None")
mod = click.prompt('Enter new password', default="None", hide_input=True)
portal_name = click.prompt("Enter portal name", default="None")
mod = click.prompt("Enter new password", default="None", hide_input=True)
db_obj.update_data(portal_name=portal_name, password=mod)


@click.command(help="Save existing passwords")
def savepass():
"""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)
portal_name = click.prompt("Enter portal name", default="None")
pwd = click.prompt("Enter your password", default="None", hide_input=True)
db_obj.create_table()
db_obj.insert_data(portal_name=portal_name, password=pwd)


@click.command(help="Create new password")
def createpass():
"""Used for taking input from user to create password"""
portal_name = click.prompt('Enter portal name', default="None")
portal_name = click.prompt("Enter portal name", default="None")
password = diceware.get_passphrase()
creation_date = date.today()
email = click.prompt('Enter email id', default="None")
portal_url = click.prompt('Enter portal url', default="None")
email = click.prompt("Enter email id", default="None")
portal_url = click.prompt("Enter portal url", default="None")
db_obj.create_table()
db_obj.insert_data(portal_name=portal_name, password=password,
creation_date=creation_date, email=email,
portal_url=portal_url)
db_obj.insert_data(
portal_name=portal_name,
password=password,
creation_date=creation_date,
email=email,
portal_url=portal_url,
)


@click.command(help="Show password")
def showpass():
portal_name = click.prompt('Enter portal name', default="None")
portal_name = click.prompt("Enter portal name", default="None")
spass = db_obj.show_data(portal_name)
print(spass)
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
name="pygenpass",
packages=find_packages(),
entry_points={"console_scripts": ["pygenpass = genpass.__init__:main"]},
version="v0.1",
version="0.1",
author="Mayuri Lahane",
author_email="[email protected]",
description="Genpass - Command Line Password Manager Tool",
Expand All @@ -24,4 +24,5 @@
namespace_packages=[],
include_package_data=True,
zip_safe=False,
install_requires=install_requires,)
install_requires=install_requires,
)

0 comments on commit eedb4d9

Please sign in to comment.