This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature Pull Request: Create a Basic Prototype Of Application (#38)
- Loading branch information
Showing
29 changed files
with
215 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class LocalDriver: | ||
pass |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.