From 49d090dca76e6b365a457cd6442c7272b734b0c9 Mon Sep 17 00:00:00 2001 From: Mayuri Lahane Date: Tue, 14 Jan 2020 17:44:43 +0530 Subject: [PATCH 1/3] fixed issue for allpass --- genpass/database.py | 15 +++++++++------ genpass/password.py | 10 +++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/genpass/database.py b/genpass/database.py index 1d7f481..bedca38 100644 --- a/genpass/database.py +++ b/genpass/database.py @@ -92,9 +92,12 @@ def show_data(self, portal_name): def show_all_data(self): """Showing all data saved in database""" - self.cursor_obj.execute( - """SELECT * FROM passwords""" - ) - rows = self.cursor_obj.fetchall() - return (rows) - self.con.commit() + try: + self.cursor_obj.execute( + """SELECT * FROM passwords""" + ) + rows = self.cursor_obj.fetchall() + return (rows) + self.con.commit() + except sqlite3.OperationalError: + print("Please make at least single entry:") diff --git a/genpass/password.py b/genpass/password.py index 7f28dd0..3d443e7 100644 --- a/genpass/password.py +++ b/genpass/password.py @@ -43,9 +43,13 @@ def allpass(): table.top_border_char = "=" table.header_separator_char = "=" table.column_headers = ["ID", "PORTAL_NAME", "PASSWORD", "DATE", "EMAIL", "PORTAL_URL"] - for row in all_pass: - table.append_row([row[0], row[1], row[2], row[3], row[4], row[5]]) - print(table) + try: + for row in all_pass: + table.append_row([row[0], row[1], row[2], row[3], row[4], row[5]]) + print(table) + except TypeError: + print("Use 'pygenpass createpass' or 'pygenpass savepass'") + @click.command(help="Delete password") From 2f223656dd3d513720a89c7597d4e7d88fbf4656 Mon Sep 17 00:00:00 2001 From: Mayuri Lahane Date: Wed, 15 Jan 2020 23:48:15 +0530 Subject: [PATCH 2/3] Fixed allpass and delpass --- genpass/__init__.py | 2 ++ genpass/database.py | 65 +++++++++++++++++++++------------------------ genpass/password.py | 23 ++++++++-------- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/genpass/__init__.py b/genpass/__init__.py index efb416d..53eed1d 100644 --- a/genpass/__init__.py +++ b/genpass/__init__.py @@ -19,6 +19,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ + import click from genpass.password import createpass from genpass.password import savepass @@ -29,6 +30,7 @@ from genpass.password import allpass + @click.group() def main(): pass diff --git a/genpass/database.py b/genpass/database.py index bedca38..a58281d 100644 --- a/genpass/database.py +++ b/genpass/database.py @@ -27,42 +27,42 @@ class DatabaseConnection: """ Class of database entries for user's information.""" def __init__(self): - """Used to create database and then to connect with generated databse file""" + """Used to create database and then to connect with generated databse file + Checked for table is created? if not then created as per required values """ 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 - (id integer PRIMARY KEY,portal_name text NOT NULL UNIQUE, password varchar, - creation_date varchar, email varchar, portal_url varchar) - """ + (id integer PRIMARY KEY,portal_name text NOT NULL UNIQUE, password varchar, + creation_date varchar, email varchar, portal_url varchar) + """ ) self.con.commit() def insert_data(self, portal_name, password, creation_date, email, portal_url): """Adding values into database""" - try: - self.password = password - self.creation_date = creation_date - 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), - ) - self.con.commit() - except sqlite3.IntegrityError: - print("Portal name already exists") + self.password = password + self.creation_date = creation_date + 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, + ), + ) + self.con.commit() 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,) ) @@ -81,23 +81,20 @@ def update_data(self, portal_name, password): 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,) + """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() def show_all_data(self): """Showing all data saved in database""" - try: - self.cursor_obj.execute( - """SELECT * FROM passwords""" - ) - rows = self.cursor_obj.fetchall() - return (rows) - self.con.commit() - except sqlite3.OperationalError: - print("Please make at least single entry:") + self.cursor_obj.execute("""SELECT * FROM passwords""") + rows = self.cursor_obj.fetchall() + return rows + self.con.commit() diff --git a/genpass/password.py b/genpass/password.py index 3d443e7..e8eaefa 100644 --- a/genpass/password.py +++ b/genpass/password.py @@ -37,26 +37,28 @@ def version(): @click.command(help="Show all passwords") def allpass(): all_pass = db_obj.show_all_data() + if all_pass==[]: + print("No records found") table = BeautifulTable() table.left_border_char = "|" table.right_border_char = "|" table.top_border_char = "=" table.header_separator_char = "=" table.column_headers = ["ID", "PORTAL_NAME", "PASSWORD", "DATE", "EMAIL", "PORTAL_URL"] - try: - for row in all_pass: - table.append_row([row[0], row[1], row[2], row[3], row[4], row[5]]) - print(table) - except TypeError: - print("Use 'pygenpass createpass' or 'pygenpass savepass'") - + 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(): """used to delete existing password""" portal_name = click.prompt("Enter portal name", default="None") - db_obj.delete_data(portal_name=portal_name) + value_check = db_obj.show_data(portal_name) + if value_check==None: + print("No records found") + else: + db_obj.delete_data(portal_name=portal_name) @click.command(help="Update password") @@ -65,6 +67,7 @@ def modpass(): 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) + print("Nothing to modify") @click.command(help="Save existing passwords") @@ -75,7 +78,6 @@ def savepass(): creation_date = date.today() 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=pwd, @@ -93,7 +95,6 @@ def createpass(): creation_date = date.today() 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, @@ -107,4 +108,4 @@ def createpass(): def showpass(): portal_name = click.prompt("Enter portal name", default="None") spass = db_obj.show_data(portal_name) - print(spass) + print(spass) \ No newline at end of file From abea51e497dc199a252c6ac7ed78781e00ab25b5 Mon Sep 17 00:00:00 2001 From: Mayuri Lahane Date: Thu, 16 Jan 2020 00:30:06 +0530 Subject: [PATCH 3/3] Fixed modpass and showpass --- genpass/__init__.py | 1 - genpass/database.py | 11 ++--------- genpass/password.py | 18 ++++++++++++------ 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/genpass/__init__.py b/genpass/__init__.py index 53eed1d..c974887 100644 --- a/genpass/__init__.py +++ b/genpass/__init__.py @@ -30,7 +30,6 @@ from genpass.password import allpass - @click.group() def main(): pass diff --git a/genpass/database.py b/genpass/database.py index a58281d..03da862 100644 --- a/genpass/database.py +++ b/genpass/database.py @@ -50,13 +50,7 @@ def insert_data(self, portal_name, password, creation_date, email, portal_url): """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.portal_name, self.password, self.creation_date, self.email, self.portal_url,), ) self.con.commit() @@ -82,8 +76,7 @@ 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,), + """SELECT password FROM passwords WHERE portal_name=?""", (self.portal_name,), ) rows = self.cursor_obj.fetchall() diff --git a/genpass/password.py b/genpass/password.py index e8eaefa..d0ef6af 100644 --- a/genpass/password.py +++ b/genpass/password.py @@ -37,7 +37,7 @@ def version(): @click.command(help="Show all passwords") def allpass(): all_pass = db_obj.show_all_data() - if all_pass==[]: + if all_pass == []: print("No records found") table = BeautifulTable() table.left_border_char = "|" @@ -55,7 +55,7 @@ def delpass(): """used to delete existing password""" portal_name = click.prompt("Enter portal name", default="None") value_check = db_obj.show_data(portal_name) - if value_check==None: + if value_check is None: print("No records found") else: db_obj.delete_data(portal_name=portal_name) @@ -65,9 +65,12 @@ def delpass(): 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) - db_obj.update_data(portal_name=portal_name, password=mod) - print("Nothing to modify") + mod_check = db_obj.show_data(portal_name) + if mod_check is None: + print("No records found") + else: + 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") @@ -108,4 +111,7 @@ def createpass(): def showpass(): portal_name = click.prompt("Enter portal name", default="None") spass = db_obj.show_data(portal_name) - print(spass) \ No newline at end of file + if spass is None: + print("No records found") + else: + print(spass)