Skip to content

Commit

Permalink
Reformatted code using black tool
Browse files Browse the repository at this point in the history
Signed-off-by: Ganesh Hubale <[email protected]>
  • Loading branch information
ganeshhubale committed Oct 9, 2024
1 parent 1d75ffd commit d05d42d
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup python
uses: actions/setup-python@v1
with:
python-version: '3.7'
python-version: '3.9'
architecture: 'x64'

- name: Pre-Commit Checks
Expand Down
78 changes: 41 additions & 37 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: trailing-whitespace
name: Trim Trailing Whitespace
language_version: python3
- id: end-of-file-fixer
name: File Ending
language_version: python3
- id: debug-statements
name: Debug Statments
language_version: python3
- id: flake8
name: Flake8
language_version: python3
verbose: true
- id: check-yaml
- repo: https://github.com/asottile/reorder_python_imports
rev: v1.8.0
hooks:
- id: reorder-python-imports
name: Reorder Python Imports
language_version: python3
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
name: Formate with Black
args: [--safe, --quiet, --line-length, "100"]
language_version: python3
require_serial: true
- repo: https://github.com/asottile/pyupgrade
rev: v1.25.2
hooks:
- id: pyupgrade
name: Python Package Checks
language_version: python3
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: trailing-whitespace
name: Trim Trailing Whitespace
language_version: python3.9 # Updated to Python 3.9
- id: end-of-file-fixer
name: File Ending
language_version: python3.9 # Updated to Python 3.9
- id: debug-statements
name: Debug Statements
language_version: python3.9 # Updated to Python 3.9
- id: flake8
name: Flake8
language_version: python3.9 # Updated to Python 3.9
verbose: true
- id: check-yaml
name: Check YAML

- repo: https://github.com/asottile/reorder_python_imports
rev: v3.7.0
hooks:
- id: reorder-python-imports
name: Reorder Python Imports
language_version: python3.9 # Updated to Python 3.9

- repo: https://github.com/psf/black
rev: 22.12.0 # Ensure this version supports Python 3.9
hooks:
- id: black
name: Format with Black
args: [--safe, --quiet, --line-length, "100"]
language_version: python3.9 # Updated to Python 3.9
require_serial: true

- repo: https://github.com/asottile/pyupgrade
rev: v3.10.0
hooks:
- id: pyupgrade
name: Python Package Checks
language_version: python3.9 # Updated to Python 3.9
28 changes: 16 additions & 12 deletions pygenpass/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

import sqlite3 # library for database
import sys

from termcolor import colored
import sys


class DatabaseConnection:
""" 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
Checked for table is created? if not then created as per required values """
Checked for table is created? if not then created as per required values"""
try:
self.con = sqlite3.connect("generated_password.db")
self.cursor_obj = self.con.cursor()
Expand All @@ -40,7 +42,7 @@ def __init__(self):
"""
)
self.con.commit()
except sqlite3.Error as e:
except sqlite3.Error as e:
# Catch any SQLite error and print the error message
print(f"Database error occurred: {e}")
sys.exit(1) # Exit the program if a database error occurs
Expand All @@ -50,7 +52,6 @@ def __init__(self):
print(f"An error occurred: {e}")
sys.exit(1) # Exit the program if an unexpected error occurs


def insert_data(self, portal_name, password, creation_date, email, portal_url):
"""Adding values into database"""
try:
Expand All @@ -63,12 +64,15 @@ def insert_data(self, portal_name, password, creation_date, email, portal_url):
self.con.commit()
except sqlite3.IntegrityError:
print(
colored(f"Error: A record with the portal name '{portal_name}' already exists.", "green")
colored(
f"Error: A record with the portal name '{portal_name}' already exists.",
"green",
)
)

except sqlite3.Error as e:
print(f"Database error occurred while inserting data: {e}")

except Exception as e:
print(f"An unexpected error occurred: {e}")

Expand Down Expand Up @@ -99,7 +103,7 @@ def update_data(self, portal_name, password):

except sqlite3.Error as e:
print(f"Database error occurred while updating data: {e}")

except Exception as e:
print(f"An unexpected error occurred: {e}")

Expand All @@ -118,7 +122,7 @@ def show_data(self, portal_name):
return None
except sqlite3.Error as e:
print(f"Database error occurred while fetching data: {e}")

except Exception as e:
print(f"An unexpected error occurred: {e}")

Expand All @@ -131,7 +135,7 @@ def show_all_data(self):

except sqlite3.Error as e:
print(f"Database error occurred while fetching all data: {e}")

except Exception as e:
print(f"An unexpected error occurred: {e}")

Expand All @@ -141,9 +145,9 @@ def close_connection(self):
if self.con:
self.con.close()
print("Database connection closed successfully.")

except sqlite3.Error as e:
print(f"Error closing the database connection: {e}")

except Exception as e:
print(f"An unexpected error occurred while closing the connection: {e}")
6 changes: 2 additions & 4 deletions pygenpass/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
from datetime import date

import click
import diceware
from beautifultable import BeautifulTable
from termcolor import colored
from datetime import date

from pygenpass.database import DatabaseConnection


db_obj = DatabaseConnection()
table = BeautifulTable()
table.left_border_char = "|"
Expand All @@ -53,7 +54,6 @@ def all():
db_obj.close_connection()



@click.command(help="Delete password")
def delete():
"""used to delete existing password"""
Expand Down Expand Up @@ -97,7 +97,6 @@ def add():
db_obj.close_connection()



@click.command(help="Create new password")
def create():
"""Used for taking input from user to create password"""
Expand All @@ -116,7 +115,6 @@ def create():
db_obj.close_connection()



@click.command(help="Show password")
def show():
portal_name = click.prompt("Enter portal name", default="None")
Expand Down
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ classifiers =
Programming Language :: Python
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Environment :: Console
Topic :: Internet
Topic :: Utilities
Expand All @@ -24,11 +25,11 @@ classifiers =
zip_safe = false
include_package_data = true
packages = find:
python_requires = >= 3.6
python_requires = >= 3.8
setup_requires = setuptools_scm
install_requires =
beautifultable
click
click >=8.1.0
diceware
termcolor

Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from setuptools import setup

setup(use_scm_version=True,)
setup(
use_scm_version=True,
)

0 comments on commit d05d42d

Please sign in to comment.