diff --git a/cli.py b/cli.py new file mode 100644 index 0000000..d98e688 --- /dev/null +++ b/cli.py @@ -0,0 +1,88 @@ +import rich.prompt as prompt +from rich_menu import Menu +from utils import Utils +from termcolor import colored +from conn import Connection +import info, sys, os +from models import Conext + +class Interface(): + + @staticmethod + def banner(): + + if sys.platform == 'win32': + os.system('cls') + else: + os.system('clear') + + base_dir = Utils.get_base_dir() + banner = colored(Utils.read_file(f'{base_dir}/icons/banner.ico'), 'blue') + print(banner) + print(f'Author: {info.__author__} ') + print(f'Version: {info.__version__}') + print(f'Year: {info.__release__}') + print(f'License: {info.__license__}') + + @staticmethod + def menu(): + + main_menu = Menu("Create new connection" , + "Connect" , + "List connections" , + "Remove connection" , + "System exit" , + color="blue" , + align="center" , + rule_title="Docker Context Manager", + panel_title="Options" , + selection_char="->" , + ) + + match main_menu.ask(screen=False): + case "Create new connection": + + return Connection.new() + + case "Connect": + + + hosts = Conext().get_all() + + connecions_menu = Menu("Create new connection" , + "Connect" , + "List connections" , + "Back" , + "System exit" , + color="blue" , + align="left" , + rule_title="Docker Context Manager", + panel_title="Connections" , + selection_char="->" , + ) + + connecions_menu.ask(screen=False) + + match connecions_menu.ask(screen=False): + case "Back": + Interface.menu() + case "System exit": + exit() + + return Connection.connect(host) + case "List connections": + + return Connection.list() + case "Remove connection": + + return Connection.remove() + case "System exit": + exit() +class Cli(): + + @staticmethod + def new_connection(): + + host = prompt.Prompt.ask('Type a hostname') + + return True \ No newline at end of file diff --git a/conn.py b/conn.py new file mode 100644 index 0000000..7915bf1 --- /dev/null +++ b/conn.py @@ -0,0 +1,36 @@ +from models import * +from rich.console import Console +from rich.table import Table + +class Connection(): + + @staticmethod + def new(): + pass + + @staticmethod + def connect(host: str): + pass + + @staticmethod + def list(): + + table = Table(title="Connections") + + table.add_column("Active" , justify="center", style="green", no_wrap=True) + table.add_column("Name" , justify="center", style="green", no_wrap=True) + table.add_column("Host" , justify="center", style="green", no_wrap=True) + table.add_column("Descriptions", justify="right" , style="green", no_wrap=True) + table.add_column("Created" , justify="center", style="green", no_wrap=True) + + contexts = Context().get_all() + + for context in contexts: + table.add_row("🟢", context.name, context.host, context.description, context.created_on) + + console = Console() + console.print(table) + + @staticmethod + def remove(): + pass \ No newline at end of file diff --git a/db/dcm.sqlite3 b/db/dcm.sqlite3 new file mode 100644 index 0000000..e69de29 diff --git a/docker.py b/docker.py new file mode 100644 index 0000000..238394b --- /dev/null +++ b/docker.py @@ -0,0 +1,9 @@ + +class Docker(): + + is_installed = 0 + is_running = 1 + + @staticmethod + def status(): + pass \ No newline at end of file diff --git a/icons/banner.ico b/icons/banner.ico new file mode 100644 index 0000000..51b175d --- /dev/null +++ b/icons/banner.ico @@ -0,0 +1,19 @@ + + ........ + ...'''''''''''''.. + .''''''''''''''''''''.. ,. + .,''''''''''''''''''''''''. '''. + .''''''''''''''''''''''''''''.. .''''.. + ''''''''''''''''''''''''''''''''. ''''''''. + ,''''''''''''''''''''''''''''''''''. ''''''''''''..... + '''''''''''''''''''''''''''''''''''''.. .'''''''''''' + '''''''''''''''. .'''''''''''''''''''''.... ..' '''. + '''''''''''''',..,'''''''''''''''''''''''''''''. + '''''''''''''''''''''''''''''''''''''''''''',: + .'''''',;:;'''''''''''''''''''''''''''''';l. + :xxkkOOOOOxdoc'''''''''''''''''''',;cok + ,OOOOOOOOOO,''''''ldooooooddxxkO; + :OOOOOl'''''';OOOOOOOo + ''''''c + '''''. + .''' diff --git a/info.py b/info.py new file mode 100644 index 0000000..3250103 --- /dev/null +++ b/info.py @@ -0,0 +1,5 @@ + +__version__ = '0.1' +__author__ = 'Vinicius Silva' +__release__ = '2024' +__license__ = 'MIT' \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..8153d43 --- /dev/null +++ b/main.py @@ -0,0 +1,35 @@ +import typer, sys +from cli import Cli, Interface + +app = typer.Typer() + +@app.command() +def new(): + + is_ok = Cli.new_connection() + + if is_ok: + + new() + + else: + pass + #typer. + + +@app.command() +def connect(name: str): + #if formal: + # print(f"Goodbye Ms. {name}. Have a good day.") + #else: + # print(f"Bye {name}!") + pass + +if __name__ == "__main__": + + if len(sys.argv) > 1: + + app() + else: + Interface.banner() + Interface.menu() \ No newline at end of file diff --git a/models.py b/models.py new file mode 100644 index 0000000..b78c691 --- /dev/null +++ b/models.py @@ -0,0 +1,44 @@ +from datetime import datetime + +import db, uuid +from utils import Utils +from peewee import * + +base_dir = Utils.get_base_dir() +db = SqliteDatabase(f"{base_dir}/db/dcm.sqlite3") + +# define a classe do modelo +class Conext(Model): + + id = IntegerField(primary_key=True) + name = TextField() + host = TextField() + description = TextField(default="") + created_on = DateTimeField(default=datetime.now()) + + class Meta: + database = db + + def get_all(self): + return Context.select() + + def create(self, host, description=""): + + if db.table_exists(): + + if host: + name = uuid.uuid4().__str__() + context = Context(name=name, host=host, description=description) + + if not context: + return False, None + + context.save() + return True, name + else: + db.create_tables([Context]) + self.create(host, description) + + return False, None + + #def delete(self, host): diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6ea77a0 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +typer +rich +rich_menu +termcolor +peewee \ No newline at end of file diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..476c0fc --- /dev/null +++ b/utils.py @@ -0,0 +1,20 @@ +import os + +class Utils(): + + @staticmethod + def get_base_dir(): + return os.path.dirname(__file__) + + @staticmethod + def read_file(filepath): + + try: + + file = open(file=filepath, mode="r") + return file.read() + except FileNotFoundError and FileExistsError: + + panic_msg = 'The system has been returned a unexpected error' + raise FileNotFoundError(panic_msg) or FileExistsError(panic_msg) + \ No newline at end of file