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

Commit

Permalink
Feature Pull Request: Create a Basic Prototype Of Application (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeelDobariya38 authored Jan 10, 2024
2 parents ef11c3f + b1ff8be commit 313535b
Show file tree
Hide file tree
Showing 29 changed files with 215 additions and 240 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[flake8]
max-line-length = 79
ignore = F841
per-file-ignores =
__init__.py: F401
command.py: E305
exclude = .git, __pycache__, venv
show-source = true
4 changes: 2 additions & 2 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ jobs:
- name: Run MyPy
run: |
poetry run mypy src
poetry run mypy SmartManager
- name: Run Flake8
run: |
poetry run flake8 src
poetry run flake8 SmartManager
- name: Run Pytest
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/Run-Tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ jobs:
- name: Run MyPy
run: |
poetry run mypy src
poetry run mypy SmartManager
- name: Run Flake8
run: |
poetry run flake8 src
poetry run flake8 SmartManager
- name: Run Pytest
run: |
Expand Down
Empty file added SmartManager/Api/__init__.py
Empty file.
Empty file added SmartManager/Api/api.py
Empty file.
Empty file added SmartManager/App/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions SmartManager/App/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from SmartManager.App.controller import Controller

CONTROLLER: Controller = Controller()


def init(dbdriver) -> None:
CONTROLLER.set_db_driver(dbdriver)


def main() -> None:
CONTROLLER.run()
CONTROLLER.welcome()
while CONTROLLER.isrunning():
command = CONTROLLER.get_command()
CONTROLLER.execute_command(command)
101 changes: 101 additions & 0 deletions SmartManager/App/command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
from abc import ABC, abstractmethod
from typing import List


class CommandInterface(ABC):
repr: str = ""
hint: str = "Command class for Controlling other commands.."

@abstractmethod
def convert_to_command(self, textrepr: str):
pass

@abstractmethod
def match(self, textrepr: str) -> bool:
pass

@abstractmethod
def execute(self, controller) -> None:
pass


class Command(CommandInterface):
repr: str = ""
hint: str = "Command class for Controlling other commands.."
commands: List[CommandInterface] = []

def convert_to_command(self, textrepr: str) -> CommandInterface:
textrepr = textrepr.lower()
for command in self.commands:
if command.match(textrepr):
return command
raise ValueError("Not a valid text representaion of Command!!")

@staticmethod
def add(command) -> None:
Command.commands.append(command) # type: ignore[misc]

def match(self, textrepr: str) -> bool:
return False

def execute(self, controller) -> None:
pass


class InvalidCommand(Command):
def match(self, textrepr: str) -> bool:
return True

def execute(self, controller):
controller.userinterface.show_output("Invaild Command!!")


class WelcomeCommand(Command):
def match(self, textrepr: str) -> bool:
return True

def execute(self, controller):
controller.userinterface.show_output("Welcome To Smart Manager")
controller.userinterface.show_output()


class EmptyCommand(Command):
def match(self, textrepr: str) -> bool:
return textrepr == ""

def execute(self, controller):
pass

Command.add(EmptyCommand())


class HelpCommand(Command):
repr: str = "help"
hint: str = "For Showing Help Prompt"

def match(self, textrepr: str) -> bool:
return textrepr == "help"

def execute(self, controller):
msg = "Here is list of valid Commands:\n\n"
msg += "Commands:\n"
for command in self.commands:
if command.repr != "":
msg += f" - {command.repr}: {command.hint}\n"
controller.userinterface.show_output(msg)

Command.add(HelpCommand())


class QuitCommand(Command):
repr: str = "quit"
hint: str = "For Quitting The Application"

def match(self, textrepr: str) -> bool:
return textrepr in ["quit", "exit"]

def execute(self, controller):
controller.userinterface.show_output("Quitting the application...")
controller.quit()

Command.add(QuitCommand())
40 changes: 40 additions & 0 deletions SmartManager/App/controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from SmartManager.App.interface import UserInterface, CLI
from SmartManager.App.command import (
CommandInterface, Command, InvalidCommand, WelcomeCommand
)
from SmartManager.App.datahandler import Datahandler


class Controller:
running = False
datahandler: Datahandler = Datahandler()
userinterface: UserInterface = CLI()
command: CommandInterface = Command()

def __init__(self):
pass

def set_db_driver(self, databasedriver):
self.datahandler.databasedriver = databasedriver

def isrunning(self) -> bool:
return self.running

def run(self) -> None:
self.running = True

def quit(self) -> None:
self.running = False

def welcome(self):
WelcomeCommand().execute(self)

def get_command(self) -> CommandInterface:
textrepr = self.userinterface.get_input(">> ")
try:
return self.command.convert_to_command(textrepr)
except ValueError as _:
return InvalidCommand()

def execute_command(self, command: CommandInterface):
command.execute(self)
11 changes: 11 additions & 0 deletions SmartManager/App/datahandler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Datahandler:
databasedriver = None

def __init__(self):
pass

def save_data(self):
pass

def load_data(self):
pass
20 changes: 20 additions & 0 deletions SmartManager/App/interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import Protocol


class UserInterface(Protocol):
def get_input(self, msg: str = "") -> str:
...

def show_output(self, msg: str = "") -> None:
...


class CLI:
def __init__(self):
pass

def get_input(self, msg: str = "") -> str:
return input(msg)

def show_output(self, msg: str = "") -> None:
print(msg)
Empty file.
Empty file added SmartManager/Database/driver.py
Empty file.
2 changes: 2 additions & 0 deletions SmartManager/Database/localdriver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class LocalDriver:
pass
Empty file added SmartManager/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions SmartManager/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from SmartManager.App import app # noqa: F401, F403
from SmartManager.Database.localdriver import LocalDriver # noqa: F401, F403


def app_run():
app.init(LocalDriver())
app.main()


if __name__ == "__main__":
app_run()
33 changes: 0 additions & 33 deletions devdocs/Deployment_Guidelines.md

This file was deleted.

10 changes: 0 additions & 10 deletions devdocs/Project_Structure.md

This file was deleted.

59 changes: 0 additions & 59 deletions devdocs/Version_Guidelines.md

This file was deleted.

8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.poetry]
name = "Smart-Manager"
name = "SmartManager"
version = "2.0.0-Beta"
description = "Smart Manager is a Python command-line application designed to securely store and manage passwords and authentication-related data."
authors = ["Jeel Dobariya <dobariyaj34@gmail.com>"]
Expand Down
5 changes: 0 additions & 5 deletions src/controller/__init__.py

This file was deleted.

Loading

0 comments on commit 313535b

Please sign in to comment.