finished config handling and started new console output

Finished the yaml config handling and started console handling output
This commit is contained in:
Neocky
2022-06-04 00:08:10 +02:00
parent 993d438ff7
commit 4920689f0e
3 changed files with 116 additions and 12 deletions

View File

@@ -6,13 +6,14 @@ import os
import sys
import ruamel.yaml
from pathlib import Path
from rich.console import Console
class config_value():
"""
Class which holds all the available configuration values from the config file and which will be used later in
the process of updating plugins
If bool in config can't be read it will default to 'False'
"""
def __init__(self):
yaml = ruamel.yaml.YAML()
@@ -21,15 +22,21 @@ class config_value():
self.connection = data["Connection"]
self.path_to_plugin_folder = Path(data["Local"]["PathToPluginFolder"])
self.local_seperate_download_path = True if data["Local"]["SeperateDownloadPath"] == True else False
self.path_to_seperate_download_path = Path(data["Local"]["PathToSeperateDownloadPath"])
self.local_path_to_seperate_download_path = Path(data["Local"]["PathToSeperateDownloadPath"])
self.server = data["Remote"]["Server"]
self.username = data["Remote"]["Server"]
self.password = data["Remote"]["Password"]
self.sftp_port = int(data["Remote"]["SFTP_Port"])
self.ftp_port = int(data["Remote"]["FTP_Port"])
self.remote_seperate_download_path = True if data["Remote"]["SeperateDownloadPath"] == True else False
self.remote_path_to_seperate_download_path = data["Remote"]["PathToSeperateDownloadPath"]
self.remote_plugin_folder_on_server = data["Remote"]["PluginFolderOnServer"]
def check_config() -> None:
"""
Check if there is a pluget_config.yml file in the same folder as pluget.py and if not create a new config
and exit the programm.
and exit the programm
"""
if not os.path.isfile("pluget_config.yaml"):
create_config()
@@ -82,11 +89,21 @@ def create_config() -> None:
sys.exit()
def validate_config() -> bool:
def validate_config() -> None:
"""
Validates the config variables after config class is loaded
Validates the config variables after config class is loaded and exit if error is detected and print error
"""
accepted_values = [
("local", "sftp", "ftp"),
("true", "false")
("local", "sftp", "ftp")
]
# exit afterwards if there is an error in config
exit_afterwards = False
config = config_value()
# rich console for nice colors
console = Console()
if (config.connection).lower() not in accepted_values[0]:
console.print(f"Error in Config! Accepted values for key 'Connection' are {accepted_values[0]}",
style="bright_red")
exit_afterwards = True
if exit_afterwards:
sys.exit()

View File

@@ -0,0 +1,73 @@
"""
Handles the console on first startup of pluGET and prints logo and sets title
"""
import os
from rich.console import Console
def rename_console_title() -> None:
"""
Renames the console title on first startup
"""
os.system("title " + "pluGET │ By Neocky")
def clear_console() -> None:
"""
Clears the console on first startup
"""
os.system('cls' if os.name=='nt' else 'clear')
def print_logo() -> None:
console = Console()
# line 1
console.print()
# line 2
console.print(" ██████",style="bright_magenta", end='')
console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='')
console.print("██████", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='')
console.print("███████", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='')
console.print("████████", style="bright_magenta", end='')
console.print("", style="bright_yellow")
# line 3
console.print(" ██", style="bright_magenta", end='')
console.print("╔══", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='')
console.print("╔════╝ ", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='')
console.print("╔════╝╚══", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='')
console.print("╔══╝", style="bright_yellow")
# line 4
console.print(" ██████╔╝██║ ██║ ██║██║ ███╗█████╗ ██║ ")
# line 5
console.print(" ██╔═══╝ ██║ ██║ ██║██║ ██║██╔══╝ ██║ ")
# line 6
console.print(" ██║ ███████╗╚██████╔╝╚██████╔╝███████╗ ██║ ")
# line 7
console.print(" ╚═╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ", style="bright_yellow")
console.print(" ┌────────────────────────────────────┐", style="bright_black")
#print(" │ [" + oColors.brightMagenta + "By Neocky" +oColors.brightBlack +
# "] │ " + oColors.standardWhite)
#print(oColors.brightBlack + " │ " + oColors.brightMagenta + "https://github.com/Neocky/pluGET" + oColors.brightBlack +
# " │ " + oColors.standardWhite)
#print(oColors.brightBlack + " └────────────────────────────────────┘" + oColors.standardWhite)