Changed indention from tab to space

This commit is contained in:
Neocky 2022-06-16 21:26:43 +02:00
parent 7f2404f0cd
commit e229324117
7 changed files with 440 additions and 438 deletions

View File

@ -1,13 +1,13 @@
""" """
Install the needed python packages through this script Install the needed python packages through this script
""" """
import os import os
try: try:
print("Installing Python packages and dependencies from requirements.txt...\n") print("Installing Python packages and dependencies from requirements.txt...\n")
os.system('py -m pip install -r requirements.txt' if os.name=='nt' else 'pip install -r requirements.txt') os.system('py -m pip install -r requirements.txt' if os.name=='nt' else 'pip install -r requirements.txt')
print("\nStart pluGET by launching the 'pluGET.py' file!") print("\nStart pluGET by launching the 'pluGET.py' file!")
except: except:
print("Requirements couldn't be installed. Check if file 'requirements.txt' is in the same folder and that Python3\ print("Requirements couldn't be installed. Check if file 'requirements.txt' is in the same folder and that Python3\
and pip is installed!") and pip is installed!")

View File

@ -7,35 +7,35 @@ import argparse
# check if folder 'src' is accessible with all modules needed and if not exit # check if folder 'src' is accessible with all modules needed and if not exit
try: try:
from src.handlers.handle_config import check_config, validate_config from src.handlers.handle_config import check_config, validate_config
from src.utils.console_output import rename_console_title, clear_console, print_logo from src.utils.console_output import rename_console_title, clear_console, print_logo
from src.utils.utilities import check_requirements, api_test_spiget from src.utils.utilities import check_requirements, api_test_spiget
from src.handlers.handle_input import handle_input from src.handlers.handle_input import handle_input
except: except:
print("Folder 'src' not found in the directory or missing files detected! \ print("Folder 'src' not found in the directory or missing files detected! \
\nPlease redownload the files from here: https://www.github.com/Neocky/pluGET") \nPlease redownload the files from here: https://www.github.com/Neocky/pluGET")
sys.exit() sys.exit()
if __name__ == "__main__": if __name__ == "__main__":
check_config() check_config()
rename_console_title() rename_console_title()
api_test_spiget() api_test_spiget()
check_requirements() check_requirements()
validate_config() validate_config()
parser = argparse.ArgumentParser(description="Arguments for pluGET", parser = argparse.ArgumentParser(description="Arguments for pluGET",
formatter_class=argparse.ArgumentDefaultsHelpFormatter) formatter_class=argparse.ArgumentDefaultsHelpFormatter)
#parser.add_argument("-a", "--archive", action="store_true", help="archive mode") #parser.add_argument("-a", "--archive", action="store_true", help="archive mode")
#parser.add_argument("--exclude", help="files to exclude") #parser.add_argument("--exclude", help="files to exclude")
parser.add_argument("mode", help="Mode (install/update)", nargs='?', default=None) parser.add_argument("mode", help="Mode (install/update)", nargs='?', default=None)
parser.add_argument("object", help="Object/Plugin Name", nargs='?', default=None) parser.add_argument("object", help="Object/Plugin Name", nargs='?', default=None)
parser.add_argument("version", help="Version", nargs='?', default=None) parser.add_argument("version", help="Version", nargs='?', default=None)
args = vars(parser.parse_args()) args = vars(parser.parse_args())
if args["mode"] is not None and args["object"] is not None: if args["mode"] is not None and args["object"] is not None:
# arguments were used so call the handle_input function to get the right function call # arguments were used so call the handle_input function to get the right function call
handle_input(args["mode"], args["object"], args["version"], arguments_from_console=True) handle_input(args["mode"], args["object"], args["version"], arguments_from_console=True)
else: else:
# no arguments were used so start pluGET console # no arguments were used so start pluGET console
clear_console() clear_console()
print_logo() print_logo()
handle_input() handle_input()

View File

@ -18,86 +18,86 @@ from src.plugin.plugin_downloader import get_specific_plugin
def handle_input(input_command=None, input_selected_object=None, input_parameter=None, arguments_from_console=False) -> None: def handle_input(input_command=None, input_selected_object=None, input_parameter=None, arguments_from_console=False) -> None:
""" """
Manages the correct function calling from the given input Manages the correct function calling from the given input
""" """
while True: while True:
# when arguemnts were not passed from console ask for input # when arguemnts were not passed from console ask for input
if arguments_from_console is False: if arguments_from_console is False:
try: try:
input_command, input_selected_object, input_parameter = get_input() input_command, input_selected_object, input_parameter = get_input()
except TypeError: except TypeError:
# KeyboardInterrupt was triggered and None was returned so exit # KeyboardInterrupt was triggered and None was returned so exit
return return
match input_command: match input_command:
case "get": case "get":
match input_selected_object.isdigit(): match input_selected_object.isdigit():
case True: case True:
get_specific_plugin(input_selected_object, input_parameter) get_specific_plugin(input_selected_object, input_parameter)
case _: case _:
print("get search specific package") print("get search specific package")
#searchPackage(inputSelectedObject) #searchPackage(inputSelectedObject)
case "update": case "update":
print("update package") print("update package")
match input_selected_object: match input_selected_object:
case "serverjar": case "serverjar":
print("update serverjar") print("update serverjar")
#updateServerjar(inputParams) #updateServerjar(inputParams)
case _: case _:
print("update package") print("update package")
#updateInstalledPackage(inputSelectedObject) #updateInstalledPackage(inputSelectedObject)
case "check": case "check":
print("check package") print("check package")
match input_selected_object: match input_selected_object:
case "serverjar": case "serverjar":
print("check serverjar") print("check serverjar")
#checkInstalledServerjar() #checkInstalledServerjar()
case _: case _:
print("check plugins") print("check plugins")
#checkInstalledPackage(inputSelectedObject, inputParams) #checkInstalledPackage(inputSelectedObject, inputParams)
case "search": case "search":
print("search package") print("search package")
#searchPackage(inputSelectedObject) #searchPackage(inputSelectedObject)
case "remove": case "remove":
print("remove package") print("remove package")
#removePlugin(inputSelectedObject) #removePlugin(inputSelectedObject)
case "get-paper": case "get-paper":
# download papermc # download papermc
print("download papermc") print("download papermc")
#papermc_downloader(inputSelectedObject, inputParams) #papermc_downloader(inputSelectedObject, inputParams)
case "exit": case "exit":
return return
case _: case _:
rich_print_error("Error: Command not found. Please try again. :(") rich_print_error("Error: Command not found. Please try again. :(")
rich_print_error("Use: 'help command' to get all available commands") rich_print_error("Use: 'help command' to get all available commands")
# return to break out of while loop if pluGET was started with arguments from console # return to break out of while loop if pluGET was started with arguments from console
if arguments_from_console: if arguments_from_console:
return None return None
def get_input() -> None: def get_input() -> None:
""" """
Gets command line input and calls the handle input function Gets command line input and calls the handle input function
""" """
input_command = None input_command = None
print("'STRG + C' to exit") print("'STRG + C' to exit")
while True: while True:
try: try:
input_command, input_selected_object, *input_parameter = input("pluGET >> ").split() input_command, input_selected_object, *input_parameter = input("pluGET >> ").split()
break break
except ValueError: except ValueError:
if input_command == None: if input_command == None:
# request input again if no input was given or not enough # request input again if no input was given or not enough
continue continue
else: else:
rich_print_error("Wrong input! Use: > 'command' 'selectedObject' [optionalParams]") rich_print_error("Wrong input! Use: > 'command' 'selectedObject' [optionalParams]")
rich_print_error("Use: 'help command' to get all available commands") rich_print_error("Use: 'help command' to get all available commands")
except KeyboardInterrupt: except KeyboardInterrupt:
return return
input_parameter = input_parameter[0] if input_parameter else None input_parameter = input_parameter[0] if input_parameter else None
return input_command, input_selected_object, input_parameter return input_command, input_selected_object, input_parameter

View File

@ -16,154 +16,154 @@ from src.handlers.handle_config import config_value
def handle_regex_package_name(full_plugin_name) -> str: def handle_regex_package_name(full_plugin_name) -> str:
""" """
Return the plugin name after trimming clutter from name with regex operations Return the plugin name after trimming clutter from name with regex operations
""" """
# trims the part of the package that has for example "[1.1 Off]" in it # trims the part of the package that has for example "[1.1 Off]" in it
unwanted_plugin_name = re.search(r'(^\[+[a-zA-Z0-9\s\W*\.*\-*\+*\%*\,]*\]+)', full_plugin_name) unwanted_plugin_name = re.search(r'(^\[+[a-zA-Z0-9\s\W*\.*\-*\+*\%*\,]*\]+)', full_plugin_name)
if bool(unwanted_plugin_name): if bool(unwanted_plugin_name):
unwanted_plugin_name_string = unwanted_plugin_name.group() unwanted_plugin_name_string = unwanted_plugin_name.group()
full_plugin_name = full_plugin_name.replace(unwanted_plugin_name_string, '') full_plugin_name = full_plugin_name.replace(unwanted_plugin_name_string, '')
# gets the real plugin_name "word1 & word2" is not supported only gets word1 # gets the real plugin_name "word1 & word2" is not supported only gets word1
plugin_name = re.search(r'([a-zA-Z]\d*)+(\s?\-*\_*[a-zA-Z]\d*\+*\-*\'*)+', full_plugin_name) plugin_name = re.search(r'([a-zA-Z]\d*)+(\s?\-*\_*[a-zA-Z]\d*\+*\-*\'*)+', full_plugin_name)
try: try:
plugin_name_full_string = plugin_name.group() plugin_name_full_string = plugin_name.group()
found_plugin_name = plugin_name_full_string.replace(' ', '') found_plugin_name = plugin_name_full_string.replace(' ', '')
except AttributeError: except AttributeError:
found_plugin_name = unwanted_plugin_name_string found_plugin_name = unwanted_plugin_name_string
return found_plugin_name return found_plugin_name
def get_version_id(plugin_id, plugin_version) -> str: def get_version_id(plugin_id, plugin_version) -> str:
""" """
Returns the version id of the plugin Returns the version id of the plugin
""" """
if plugin_version == None or plugin_version == 'latest': if plugin_version == None or plugin_version == 'latest':
url = f"https://api.spiget.org/v2/resources/{plugin_id}/versions/latest" url = f"https://api.spiget.org/v2/resources/{plugin_id}/versions/latest"
response = api_do_request(url) response = api_do_request(url)
if response == None: if response == None:
return None return None
version_id = response["id"] version_id = response["id"]
return version_id return version_id
url = f"https://api.spiget.org/v2/resources/{plugin_id}/versions?size=100&sort=-name" url = f"https://api.spiget.org/v2/resources/{plugin_id}/versions?size=100&sort=-name"
version_list = api_do_request(url) version_list = api_do_request(url)
if response == None: if version_list == None:
return None return None
for plugins in version_list: for plugins in version_list:
plugin_update = plugins["name"] plugin_update = plugins["name"]
version_id = plugins["id"] version_id = plugins["id"]
if plugin_update == plugin_version: if plugin_update == plugin_version:
return version_id return version_id
return version_list[0]["id"] return version_list[0]["id"]
def get_version_name(plugin_id, plugin_version_id) -> str: def get_version_name(plugin_id, plugin_version_id) -> str:
""" """
Returns the name of a specific version Returns the name of a specific version
""" """
url = f"https://api.spiget.org/v2/resources/{plugin_id}/versions/{plugin_version_id}" url = f"https://api.spiget.org/v2/resources/{plugin_id}/versions/{plugin_version_id}"
response = api_do_request(url) response = api_do_request(url)
if response == None: if response == None:
return None return None
version_name = response["name"] version_name = response["name"]
return version_name return version_name
def get_download_path(config_values) -> str: def get_download_path(config_values) -> str:
""" """
Reads the config and gets the path of the plugin folder Reads the config and gets the path of the plugin folder
""" """
match (config_values.connection): match (config_values.connection):
case "local": case "local":
match (config_values.local_seperate_download_path): match (config_values.local_seperate_download_path):
case True: case True:
return config_values.local_path_to_seperate_download_path return config_values.local_path_to_seperate_download_path
case _: case _:
return config_values.path_to_plugin_folder return config_values.path_to_plugin_folder
case _: case _:
match (config_values.remote_seperate_download_path): match (config_values.remote_seperate_download_path):
case True: case True:
return config_values.remote_path_to_seperate_download_path return config_values.remote_path_to_seperate_download_path
case _: case _:
return config_values.remote_plugin_folder_on_server return config_values.remote_plugin_folder_on_server
def download_specific_plugin_version(plugin_id, download_path, version_id="latest") -> None: def download_specific_plugin_version(plugin_id, download_path, version_id="latest") -> None:
""" """
Download a specific plugin Download a specific plugin
""" """
#config_values = config_value() #config_values = config_value()
if version_id != "latest" and version_id != None: if version_id != "latest" and version_id != None:
#url = f"https://spigotmc.org/resources/{plugin_id}/download?version={versionID}" #url = f"https://spigotmc.org/resources/{plugin_id}/download?version={versionID}"
rich_print_error("Sorry but specific version downloads aren't supported because of cloudflare protection. :(") rich_print_error("Sorry but specific version downloads aren't supported because of cloudflare protection. :(")
rich_print_error("Reverting to latest version.") rich_print_error("Reverting to latest version.")
#url = f"https://api.spiget.org/v2/resources/{plugin_id}/versions/latest/download" #throws 403 forbidden error...cloudflare :( #url = f"https://api.spiget.org/v2/resources/{plugin_id}/versions/latest/download" #throws 403 forbidden error...cloudflare :(
url = f"https://api.spiget.org/v2/resources/{plugin_id}/download" url = f"https://api.spiget.org/v2/resources/{plugin_id}/download"
urrlib_opener = urllib.request.build_opener() urrlib_opener = urllib.request.build_opener()
urrlib_opener.addheaders = [('User-agent', 'pluGET/1.0')] urrlib_opener.addheaders = [('User-agent', 'pluGET/1.0')]
urllib.request.install_opener(urrlib_opener) urllib.request.install_opener(urrlib_opener)
remote_file = urllib.request.urlopen(url) remote_file = urllib.request.urlopen(url)
try: try:
file_size = int(remote_file.info()['Content-Length']) file_size = int(remote_file.info()['Content-Length'])
except TypeError: except TypeError:
# if api won't return file size set it to 0 to avoid throwing an error # if api won't return file size set it to 0 to avoid throwing an error
file_size = 0 file_size = 0
urllib.request.urlretrieve(url, download_path) urllib.request.urlretrieve(url, download_path)
print(" ", end='') print(" ", end='')
if file_size >= 1000000 and file_size != 0: if file_size >= 1000000 and file_size != 0:
file_size_data = convert_file_size_down(convert_file_size_down(file_size)) file_size_data = convert_file_size_down(convert_file_size_down(file_size))
print("Downloaded " + (str(file_size_data)).rjust(9) + f" MB here {download_path}") print("Downloaded " + (str(file_size_data)).rjust(9) + f" MB here {download_path}")
elif file_size != 0: elif file_size != 0:
file_size_data = convert_file_size_down(file_size) file_size_data = convert_file_size_down(file_size)
print("Downloaded " + (str(file_size_data)).rjust(9) + f" KB here {download_path}") print("Downloaded " + (str(file_size_data)).rjust(9) + f" KB here {download_path}")
else: else:
print(f"Downloaded file here {download_path}") print(f"Downloaded file here {download_path}")
# TODO add sftp and ftp support # TODO add sftp and ftp support
#if config_values.connection == "sftp": #if config_values.connection == "sftp":
# sftp_session = createSFTPConnection() # sftp_session = createSFTPConnection()
# sftp_upload_file(sftp_session, download_path) # sftp_upload_file(sftp_session, download_path)
#elif config_values.connection == "ftp": #elif config_values.connection == "ftp":
# ftp_session = createFTPConnection() # ftp_session = createFTPConnection()
# ftp_upload_file(ftp_session, download_path) # ftp_upload_file(ftp_session, download_path)
return None return None
def get_specific_plugin(plugin_id, plugin_version="latest") -> None: def get_specific_plugin(plugin_id, plugin_version="latest") -> None:
""" """
Gets the specific plugin and calls the download function Gets the specific plugin and calls the download function
""" """
config_values = config_value() config_values = config_value()
# use a temporary folder to store plugins until they are uploaded # use a temporary folder to store plugins until they are uploaded
if config_values.connection != "local": if config_values.connection != "local":
download_path = create_temp_plugin_folder() download_path = create_temp_plugin_folder()
else: else:
download_path = get_download_path(config_values) download_path = get_download_path(config_values)
url = f"https://api.spiget.org/v2/resources/{plugin_id}" url = f"https://api.spiget.org/v2/resources/{plugin_id}"
plugin_details = api_do_request(url) plugin_details = api_do_request(url)
if plugin_details == None: if plugin_details == None:
return None return None
try: try:
plugin_name = plugin_details["name"] plugin_name = plugin_details["name"]
except KeyError: except KeyError:
# exit if plugin id coudn't be found # exit if plugin id coudn't be found
rich_print_error("Error: Plugin ID couldn't be found") rich_print_error("Error: Plugin ID couldn't be found")
return None return None
plugin_name = handle_regex_package_name(plugin_name) plugin_name = handle_regex_package_name(plugin_name)
plugin_version_id = get_version_id(plugin_id, plugin_version) plugin_version_id = get_version_id(plugin_id, plugin_version)
plugin_version_name = get_version_name(plugin_id, plugin_version_id) plugin_version_name = get_version_name(plugin_id, plugin_version_id)
plugin_download_name = f"{plugin_name}-{plugin_version_name}.jar" plugin_download_name = f"{plugin_name}-{plugin_version_name}.jar"
download_plugin_path = Path(f"{download_path}/{plugin_download_name}") download_plugin_path = Path(f"{download_path}/{plugin_download_name}")
# set the plugin_version_id to None if a specific version wasn't given as parameter # set the plugin_version_id to None if a specific version wasn't given as parameter
if plugin_version == "latest" or plugin_version is None: if plugin_version == "latest" or plugin_version is None:
plugin_version_id = None plugin_version_id = None
download_specific_plugin_version(plugin_id, download_plugin_path, plugin_version_id) download_specific_plugin_version(plugin_id, download_plugin_path, plugin_version_id)
if config_values.connection != "local": if config_values.connection != "local":
remove_temp_plugin_folder() remove_temp_plugin_folder()
return None return None

View File

@ -5,6 +5,7 @@ from src.utils import utilities
class TestCases(unittest.TestCase): class TestCases(unittest.TestCase):
def test_handle_regex_package_name(self): def test_handle_regex_package_name(self):
# Cropped name -> 'SUPERBPlugin'
plugin_name = "[1.13-5.49 ❤] >|> SUPERB Plugin <<💥| Now 150% OFF IN WINTER SALE IN SUMMER???" plugin_name = "[1.13-5.49 ❤] >|> SUPERB Plugin <<💥| Now 150% OFF IN WINTER SALE IN SUMMER???"
plugin_name_cropped = "SUPERBPlugin" plugin_name_cropped = "SUPERBPlugin"
result = plugin_downloader.handle_regex_package_name(plugin_name) result = plugin_downloader.handle_regex_package_name(plugin_name)
@ -12,15 +13,15 @@ class TestCases(unittest.TestCase):
def test_get_version_id(self): def test_get_version_id(self):
# 1234 -> "AntiPickup" in Version 1.4.1 # 21840 -> "Luckperms" in Version 5.4.30
result = plugin_downloader.get_version_id("1234", "1.4.1") result = plugin_downloader.get_version_id("28140", "5.4.30")
self.assertEqual(result, 43779) self.assertEqual(result, 455966)
def test_get_version_name(self): def test_get_version_name(self):
# 43779 -> "1.4.1" from AntiPickup # 455966 -> "5.4.30" from Luckperms
result = plugin_downloader.get_version_name("1234", 43779) result = plugin_downloader.get_version_name("28140", 455966)
self.assertEqual(result, "1.4.1") self.assertEqual(result, "5.4.30")
def test_get_download_path(self): def test_get_download_path(self):
@ -50,6 +51,7 @@ class TestCases(unittest.TestCase):
def test_convert_file_size_down(self): def test_convert_file_size_down(self):
# 100000 / 1024 = 97.66
result= utilities.convert_file_size_down(100000) result= utilities.convert_file_size_down(100000)
self.assertEqual(result, 97.66) self.assertEqual(result, 97.66)

View File

@ -1,5 +1,5 @@
""" """
Handles the console on first startup of pluGET and prints logo and sets title Handles the console on first startup of pluGET and prints logo and sets title
""" """
import os import os
@ -7,132 +7,132 @@ from rich.console import Console
def rich_print_error(error_message) -> None: def rich_print_error(error_message) -> None:
""" """
Prints a formatted error message from rich Prints a formatted error message from rich
""" """
console = Console() console = Console()
console.print(error_message, style="bright_red") console.print(error_message, style="bright_red")
return None return None
def rename_console_title() -> None: def rename_console_title() -> None:
""" """
Renames the console title on first startup Renames the console title on first startup
""" """
os.system("title " + "pluGET │ By Neocky") os.system("title " + "pluGET │ By Neocky")
return None return None
def clear_console() -> None: def clear_console() -> None:
""" """
Clears the console on first startup Clears the console on first startup
""" """
os.system('cls' if os.name=='nt' else 'clear') os.system('cls' if os.name=='nt' else 'clear')
return None return None
def print_logo() -> None: def print_logo() -> None:
""" """
Prints the logo of pluGET and the link to the github repo Prints the logo of pluGET and the link to the github repo
""" """
# use rich console # use rich console
console = Console() console = Console()
# line 1 # line 1
console.print() console.print()
# line 2 # line 2
console.print(" ██████",style="bright_magenta", end='') console.print(" ██████",style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("██████", style="bright_magenta", end='') console.print("██████", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("███████", style="bright_magenta", end='') console.print("███████", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("████████", style="bright_magenta", end='') console.print("████████", style="bright_magenta", end='')
console.print("", style="bright_yellow") console.print("", style="bright_yellow")
# line 3 # line 3
console.print(" ██", style="bright_magenta", end='') console.print(" ██", style="bright_magenta", end='')
console.print("╔══", style="bright_yellow", end='') console.print("╔══", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("╔════╝ ", style="bright_yellow", end='') console.print("╔════╝ ", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("╔════╝╚══", style="bright_yellow", end='') console.print("╔════╝╚══", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("╔══╝", style="bright_yellow") console.print("╔══╝", style="bright_yellow")
# line 4 # line 4
console.print(" ██████", style="bright_magenta", end='') console.print(" ██████", style="bright_magenta", end='')
console.print("╔╝", style="bright_yellow", end='') console.print("╔╝", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("███", style="bright_magenta", end='') console.print("███", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("█████", style="bright_magenta", end='') console.print("█████", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow") console.print("", style="bright_yellow")
# line 5 # line 5
console.print(" ██", style="bright_magenta", end='') console.print(" ██", style="bright_magenta", end='')
console.print("╔═══╝ ", style="bright_yellow", end='') console.print("╔═══╝ ", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("╔══╝ ", style="bright_yellow", end='') console.print("╔══╝ ", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow") console.print("", style="bright_yellow")
# line 6 # line 6
console.print(" ██", style="bright_magenta", end='') console.print(" ██", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("███████", style="bright_magenta", end='') console.print("███████", style="bright_magenta", end='')
console.print("╗╚", style="bright_yellow", end='') console.print("╗╚", style="bright_yellow", end='')
console.print("██████", style="bright_magenta", end='') console.print("██████", style="bright_magenta", end='')
console.print("╔╝╚", style="bright_yellow", end='') console.print("╔╝╚", style="bright_yellow", end='')
console.print("██████", style="bright_magenta", end='') console.print("██████", style="bright_magenta", end='')
console.print("╔╝", style="bright_yellow", end='') console.print("╔╝", style="bright_yellow", end='')
console.print("███████", style="bright_magenta", end='') console.print("███████", style="bright_magenta", end='')
console.print("", style="bright_yellow", end='') console.print("", style="bright_yellow", end='')
console.print("██", style="bright_magenta", end='') console.print("██", style="bright_magenta", end='')
console.print("", style="bright_yellow") console.print("", style="bright_yellow")
# line 7 # line 7
console.print(" ╚═╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ", style="bright_yellow") console.print(" ╚═╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ", style="bright_yellow")
# line 8 # line 8
console.print() console.print()
# line 9 # line 9
console.print(" ┌────────────────────────────────────┐", style="bright_black") console.print(" ┌────────────────────────────────────┐", style="bright_black")
# line 10 # line 10
console.print(" │ [", style="bright_black", end='') console.print(" │ [", style="bright_black", end='')
console.print("By Neocky", style="bright_magenta", end='') console.print("By Neocky", style="bright_magenta", end='')
console.print("] │ ", style="bright_black") console.print("] │ ", style="bright_black")
# line 11 # line 11
console.print("", style="bright_black", end='') console.print("", style="bright_black", end='')
console.print("https://github.com/Neocky/pluGET", style="link https://github.com/Neocky/pluGET", end='') console.print("https://github.com/Neocky/pluGET", style="link https://github.com/Neocky/pluGET", end='')
console.print("", style="bright_black") console.print("", style="bright_black")
# line 12 # line 12
console.print(" └────────────────────────────────────┘", style="bright_black") console.print(" └────────────────────────────────────┘", style="bright_black")
console.print(" ───────────────────────────────────────────────────") console.print(" ───────────────────────────────────────────────────")
return None return None

View File

@ -13,97 +13,97 @@ from src.handlers.handle_config import config_value
def api_do_request(url) -> list: def api_do_request(url) -> list:
""" """
Handles the webrequest and returns a json list Handles the webrequest and returns a json list
""" """
webrequest_header = {'user-agent': 'pluGET/1.0'} webrequest_header = {'user-agent': 'pluGET/1.0'}
try: try:
response = requests.get(url, headers=webrequest_header) response = requests.get(url, headers=webrequest_header)
except: except:
print("Couldn't create webrequest") print("Couldn't create webrequest")
# return None to make functions quit # return None to make functions quit
return None return None
api_json_data = response.json() api_json_data = response.json()
return api_json_data return api_json_data
def api_test_spiget() -> None: def api_test_spiget() -> None:
""" """
Test if the Spiget api sends a 200 status code back Test if the Spiget api sends a 200 status code back
""" """
try: try:
r = requests.get('https://api.spiget.org/v2/status') r = requests.get('https://api.spiget.org/v2/status')
except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError): except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError):
rich_print_error("Error: Couldn't make a connection to the API. Check you connection to the internet!") rich_print_error("Error: Couldn't make a connection to the API. Check you connection to the internet!")
sys.exit() sys.exit()
if r.status_code != 200: if r.status_code != 200:
rich_print_error("Error: Problems with the API detected. Plese try it again later!") rich_print_error("Error: Problems with the API detected. Plese try it again later!")
sys.exit() sys.exit()
return return
def create_temp_plugin_folder() -> Path: def create_temp_plugin_folder() -> Path:
""" """
Creates a temporary folder to store plugins inside Creates a temporary folder to store plugins inside
Returns full path of temporary folder Returns full path of temporary folder
""" """
path_temp_plugin_folder = Path("./TempSFTPFolder") path_temp_plugin_folder = Path("./TempSFTPFolder")
if os.path.isdir(path_temp_plugin_folder): if os.path.isdir(path_temp_plugin_folder):
return path_temp_plugin_folder return path_temp_plugin_folder
try: try:
os.mkdir(path_temp_plugin_folder) os.mkdir(path_temp_plugin_folder)
except OSError: except OSError:
rich_print_error(f"Error: Creation of directory {path_temp_plugin_folder} failed") rich_print_error(f"Error: Creation of directory {path_temp_plugin_folder} failed")
rich_print_error(" Please check for missing permissions in folder tree!") rich_print_error(" Please check for missing permissions in folder tree!")
sys.exit() sys.exit()
return path_temp_plugin_folder return path_temp_plugin_folder
def remove_temp_plugin_folder() -> None: def remove_temp_plugin_folder() -> None:
""" """
Removes the temporary plugin folder and all content inside it Removes the temporary plugin folder and all content inside it
""" """
try: try:
shutil.rmtree(Path("./TempSFTPFolder")) shutil.rmtree(Path("./TempSFTPFolder"))
except OSError as e: except OSError as e:
rich_print_error(f"Error: {e.filename} - {e.strerror}") rich_print_error(f"Error: {e.filename} - {e.strerror}")
return return
def convert_file_size_down(file_size) -> float: def convert_file_size_down(file_size) -> float:
""" """
Convert the size of the number one down. E.g. MB -> KB through division with 1024 Convert the size of the number one down. E.g. MB -> KB through division with 1024
""" """
converted_file_size = (int(file_size)) / 1024 converted_file_size = (int(file_size)) / 1024
converted_file_size = round(converted_file_size, 2) converted_file_size = round(converted_file_size, 2)
return converted_file_size return converted_file_size
def check_local_plugin_folder(config_values) -> None: def check_local_plugin_folder(config_values) -> None:
""" """
Check if a local plugin folder exists and if not exit the programm Check if a local plugin folder exists and if not exit the programm
""" """
if config_values.local_seperate_download_path: if config_values.local_seperate_download_path:
plugin_folder_path = config_values.local_path_to_seperate_download_path plugin_folder_path = config_values.local_path_to_seperate_download_path
else: else:
plugin_folder_path = config_values.path_to_plugin_folder plugin_folder_path = config_values.path_to_plugin_folder
if not os.path.isdir(plugin_folder_path): if not os.path.isdir(plugin_folder_path):
rich_print_error(f"Error: Local plugin folder '{plugin_folder_path}' couldn't be found! \ rich_print_error(f"Error: Local plugin folder '{plugin_folder_path}' couldn't be found! \
\n Check the config and try again!") \n Check the config and try again!")
sys.exit() sys.exit()
return None return None
def check_requirements() -> None: def check_requirements() -> None:
""" """
Check if the plugin folders are available Check if the plugin folders are available
""" """
config_values = config_value() config_values = config_value()
match config_values.connection: match config_values.connection:
case "local": case "local":
check_local_plugin_folder(config_values) check_local_plugin_folder(config_values)
case "sftp": case "sftp":
print("Check sftp folder") print("Check sftp folder")
case "ftp": case "ftp":
print("check ftp folder") print("check ftp folder")