aboutsummaryrefslogtreecommitdiff
path: root/yoshi/database.py
diff options
context:
space:
mode:
Diffstat (limited to 'yoshi/database.py')
-rw-r--r--yoshi/database.py60
1 files changed, 31 insertions, 29 deletions
diff --git a/yoshi/database.py b/yoshi/database.py
index e1e2e78..4591955 100644
--- a/yoshi/database.py
+++ b/yoshi/database.py
@@ -7,8 +7,8 @@ import sqlite3
import sys
import os
-VAULT_DECRYPTED = 'vault.sqlite'
-VAULT_ENCRYPTED = 'vault.sqlite.aes'
+VAULT_DECRYPTED = "vault.sqlite"
+VAULT_ENCRYPTED = "vault.sqlite.aes"
def create_table() -> None:
@@ -16,8 +16,8 @@ def create_table() -> None:
db_connection = sqlite3.connect(VAULT_DECRYPTED)
cursor = db_connection.cursor()
cursor.execute(
- ''' CREATE TABLE IF NOT EXISTS accounts (uuid text, application text,
- username text, password text, url text) '''
+ """ CREATE TABLE IF NOT EXISTS accounts (uuid text, application text,
+ username text, password text, url text) """
)
db_connection.commit()
db_connection.close()
@@ -29,17 +29,18 @@ def check_table() -> bool:
db_connection = sqlite3.connect(VAULT_DECRYPTED)
cursor = db_connection.cursor()
cursor.execute(
- ''' SELECT count(name) FROM sqlite_master WHERE type='table'
- AND name='accounts' '''
+ """ SELECT count(name) FROM sqlite_master WHERE type='table'
+ AND name='accounts' """
)
if cursor.fetchone()[0] != 1:
user_choice = input(
- 'Password vault does not exist. Would you like to create it now? (y/n): ')
- if user_choice.lower() == 'y':
+ "Password vault does not exist. Would you like to create it now? (y/n): "
+ )
+ if user_choice.lower() == "y":
create_table()
check = True
else:
- sys.exit('Program aborted upon user request.')
+ sys.exit("Program aborted upon user request.")
else:
check = True
db_connection.commit()
@@ -47,17 +48,22 @@ def check_table() -> bool:
return check
-def add_account(uuid: str, application: str, username: str, password: str,
- url: str) -> None:
+def add_account(
+ uuid: str, application: str, username: str, password: str, url: str
+) -> None:
"""Add a new account within the vault database."""
db_connection = sqlite3.connect(VAULT_DECRYPTED)
cursor = db_connection.cursor()
cursor.execute(
- ''' INSERT INTO accounts VALUES (:uuid,:application,:username,
- :password,:url) ''', {
- 'uuid': uuid, 'application': application, 'username': username,
- 'password': password, 'url': url
- }
+ """ INSERT INTO accounts VALUES (:uuid,:application,:username,
+ :password,:url) """,
+ {
+ "uuid": uuid,
+ "application": application,
+ "username": username,
+ "password": password,
+ "url": url,
+ },
)
db_connection.commit()
db_connection.close()
@@ -67,9 +73,7 @@ def delete_account(uuid: str) -> None:
"""Delete an account within the vault database by its unique ID."""
db_connection = sqlite3.connect(VAULT_DECRYPTED)
cursor = db_connection.cursor()
- cursor.execute(
- ''' DELETE FROM accounts WHERE uuid = :uuid ''', {'uuid': uuid}
- )
+ cursor.execute(""" DELETE FROM accounts WHERE uuid = :uuid """, {"uuid": uuid})
db_connection.commit()
db_connection.close()
@@ -78,9 +82,7 @@ def find_account(uuid: str) -> list:
"""Find an account within the vault database by its unique ID."""
db_connection = sqlite3.connect(VAULT_DECRYPTED)
cursor = db_connection.cursor()
- cursor.execute(
- ''' SELECT * FROM accounts WHERE uuid = :uuid ''', {'uuid': uuid}
- )
+ cursor.execute(""" SELECT * FROM accounts WHERE uuid = :uuid """, {"uuid": uuid})
account = cursor.fetchall()
db_connection.close()
return account
@@ -90,7 +92,7 @@ def find_accounts() -> list:
"""Return all accounts stored within the vault database."""
db_connection = sqlite3.connect(VAULT_DECRYPTED)
cursor = db_connection.cursor()
- cursor.execute(''' SELECT * FROM accounts ''')
+ cursor.execute(""" SELECT * FROM accounts """)
accounts = cursor.fetchall()
db_connection.close()
return accounts
@@ -99,14 +101,14 @@ def find_accounts() -> list:
def update_account(field_name: str, new_value: str, uuid: str) -> None:
"""Update an account within the vault database by its unique ID."""
queries = {
- 'application': 'UPDATE accounts SET application = :new_value WHERE uuid = :uuid',
- 'username': 'UPDATE accounts SET username = :new_value WHERE uuid = :uuid',
- 'password': 'UPDATE accounts SET password = :new_value WHERE uuid = :uuid',
- 'url': 'UPDATE accounts SET url = :new_value WHERE uuid = :uuid'
+ "application": "UPDATE accounts SET application = :new_value WHERE uuid = :uuid",
+ "username": "UPDATE accounts SET username = :new_value WHERE uuid = :uuid",
+ "password": "UPDATE accounts SET password = :new_value WHERE uuid = :uuid",
+ "url": "UPDATE accounts SET url = :new_value WHERE uuid = :uuid",
}
db_connection = sqlite3.connect(VAULT_DECRYPTED)
cursor = db_connection.cursor()
- cursor.execute(queries[field_name], {'new_value': new_value, 'uuid': uuid})
+ cursor.execute(queries[field_name], {"new_value": new_value, "uuid": uuid})
db_connection.commit()
db_connection.close()
@@ -115,7 +117,7 @@ def purge_table() -> None:
"""Purge the 'accounts' table within the vault database."""
db_connection = sqlite3.connect(VAULT_DECRYPTED)
cursor = db_connection.cursor()
- cursor.execute(''' DROP TABLE accounts ''')
+ cursor.execute(""" DROP TABLE accounts """)
db_connection.commit()
db_connection.close()