Init project

This commit is contained in:
Vinicius Silva 2024-04-04 20:30:19 -03:00
parent 9618f0fdf5
commit e08bb5baf3
10 changed files with 261 additions and 0 deletions

88
cli.py Normal file
View File

@ -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

36
conn.py Normal file
View File

@ -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

0
db/dcm.sqlite3 Normal file
View File

9
docker.py Normal file
View File

@ -0,0 +1,9 @@
class Docker():
is_installed = 0
is_running = 1
@staticmethod
def status():
pass

19
icons/banner.ico Normal file
View File

@ -0,0 +1,19 @@
........
...'''''''''''''..
.''''''''''''''''''''.. ,.
.,''''''''''''''''''''''''. '''.
.''''''''''''''''''''''''''''.. .''''..
''''''''''''''''''''''''''''''''. ''''''''.
,''''''''''''''''''''''''''''''''''. ''''''''''''.....
'''''''''''''''''''''''''''''''''''''.. .''''''''''''
'''''''''''''''. .'''''''''''''''''''''.... ..' '''.
'''''''''''''',..,'''''''''''''''''''''''''''''.
'''''''''''''''''''''''''''''''''''''''''''',:
.'''''',;:;'''''''''''''''''''''''''''''';l.
:xxkkOOOOOxdoc'''''''''''''''''''',;cok
,OOOOOOOOOO,''''''ldooooooddxxkO;
:OOOOOl'''''';OOOOOOOo
''''''c
'''''.
.'''

5
info.py Normal file
View File

@ -0,0 +1,5 @@
__version__ = '0.1'
__author__ = 'Vinicius Silva'
__release__ = '2024'
__license__ = 'MIT'

35
main.py Normal file
View File

@ -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()

44
models.py Normal file
View File

@ -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):

5
requirements.txt Normal file
View File

@ -0,0 +1,5 @@
typer
rich
rich_menu
termcolor
peewee

20
utils.py Normal file
View File

@ -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)