Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Enhance The Quality Of CodeBase (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeelDobariya38 authored Nov 7, 2023
2 parents 4506969 + 224c095 commit 0e1abb1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/Run-Tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ jobs:
- name: Run pytest
run: |
pytest tests
coverage run -m pytest
coverage report
2 changes: 1 addition & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pytest
pytest-cov
coverage
mypy
11 changes: 6 additions & 5 deletions src/app/commands.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
from . import datahandler
from . import metadata

def quit_appplication():
def quit_appplication() -> None:
print("Quiting the Application....")

def print_help_message():
def print_help_message() -> None:
print("Here are valid commands:")
print(" - \"quit\" or \"exit\": for quiting the app")
print(" - \"read\" or \"load\": for reading or loading the existing passwords")
print(" - \"write\" or \"save\": for writing or saveing the new passwords")
print()

def write_password():
def write_password() -> None:
website = input("Enter a website: ")
password = input("Enter a password: ")
datahandler.save_data(website, password)
print("operation successfull!!!")
print()

def read_password():
def read_password() -> None:
data_list = datahandler.load_data()
try:
for data_item in data_list:
print(f"{data_item[0]} - {data_item[1]}")
print()
except IndexError as _:
raise Exception("data is corrupted!!")

def read_info():
def read_info() -> None:
path = metadata.RESOURCEDIR_PATH + "info.txt"
with open(path) as f:
data = f.read()
Expand Down
8 changes: 5 additions & 3 deletions src/app/datahandler.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from . import metadata

DATA_FILE = metadata.DATADIR_PATH + "data.txt"
from typing import List

def save_data(website, password):
DATA_FILE: str = metadata.DATADIR_PATH + "data.txt"

def save_data(website: str, password: str) -> None:
data = metadata.DATA_SEPARATOR.join([website, password])
with open(DATA_FILE, "a") as f:
f.write(data + '\n')

def load_data():
def load_data() -> List[list[str]]:
data_list = []
with open(DATA_FILE) as f:
data = f.read()
Expand Down
10 changes: 5 additions & 5 deletions src/app/eventhandler.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from . import commands

def handle_quit_event():
def handle_quit_event() -> None:
commands.quit_appplication()

def handle_help_event():
def handle_help_event() -> None:
commands.print_help_message()

def handle_write_password_event():
def handle_write_password_event() -> None:
commands.write_password()

def handle_read_password_event():
def handle_read_password_event() -> None:
commands.read_password()

def handle_info_event():
def handle_info_event() -> None:
commands.read_info()
19 changes: 10 additions & 9 deletions src/app/metadata.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
"""CHANGES IN THIS FILE CAN LEAD TO ADVERSE EFFECTS AND CAN EVEN CRASH THE APPLICATION"""

import os
from typing import List

# App
NAME = "Smart Manager"
VERSION = "0.1.0-alpha"
WEBSITE = "https://jeeldobariya38.github.io/Smart-Manager/"
REPO = "https://github.com/JeelDobariya38/Smart-Manager"
NAME: str = "Smart Manager"
VERSION: str = "0.1.0-alpha"
WEBSITE: str = "https://jeeldobariya38.github.io/Smart-Manager/"
REPO: str = "https://github.com/JeelDobariya38/Smart-Manager"

# Paths (all path are relative to this file)
__DATADIR = ["..", "..", "..", "data"]
__RESOURCEDIR = ["..", "..", "..", "resource"]
__DATADIR: list[str] = ["..", "..", "..", "data"]
__RESOURCEDIR: list[str] = ["..", "..", "..", "resource"]

# FilePath (Do Not Change this session, instead change above "Paths" session)
DATADIR_PATH = os.path.join(__file__, os.path.sep.join(__DATADIR)) + os.path.sep
RESOURCEDIR_PATH = os.path.join(__file__, os.path.sep.join(__RESOURCEDIR)) + os.path.sep
DATADIR_PATH: str = os.path.join(__file__, os.path.sep.join(__DATADIR)) + os.path.sep
RESOURCEDIR_PATH: str = os.path.join(__file__, os.path.sep.join(__RESOURCEDIR)) + os.path.sep

# App Configuration
DATA_SEPARATOR = " -> "
DATA_SEPARATOR: str = " -> "

0 comments on commit 0e1abb1

Please sign in to comment.