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
try:
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')
print("\nStart pluGET by launching the 'pluGET.py' file!")
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')
print("\nStart pluGET by launching the 'pluGET.py' file!")
except:
print("Requirements couldn't be installed. Check if file 'requirements.txt' is in the same folder and that Python3\
and pip is installed!")
print("Requirements couldn't be installed. Check if file 'requirements.txt' is in the same folder and that Python3\
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
try:
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.utilities import check_requirements, api_test_spiget
from src.handlers.handle_input import handle_input
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.utilities import check_requirements, api_test_spiget
from src.handlers.handle_input import handle_input
except:
print("Folder 'src' not found in the directory or missing files detected! \
\nPlease redownload the files from here: https://www.github.com/Neocky/pluGET")
sys.exit()
print("Folder 'src' not found in the directory or missing files detected! \
\nPlease redownload the files from here: https://www.github.com/Neocky/pluGET")
sys.exit()
if __name__ == "__main__":
check_config()
rename_console_title()
api_test_spiget()
check_requirements()
validate_config()
parser = argparse.ArgumentParser(description="Arguments for pluGET",
check_config()
rename_console_title()
api_test_spiget()
check_requirements()
validate_config()
parser = argparse.ArgumentParser(description="Arguments for pluGET",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
#parser.add_argument("-a", "--archive", action="store_true", help="archive mode")
#parser.add_argument("--exclude", help="files to exclude")
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("version", help="Version", nargs='?', default=None)
args = vars(parser.parse_args())
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
handle_input(args["mode"], args["object"], args["version"], arguments_from_console=True)
else:
# no arguments were used so start pluGET console
clear_console()
print_logo()
handle_input()
#parser.add_argument("-a", "--archive", action="store_true", help="archive mode")
#parser.add_argument("--exclude", help="files to exclude")
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("version", help="Version", nargs='?', default=None)
args = vars(parser.parse_args())
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
handle_input(args["mode"], args["object"], args["version"], arguments_from_console=True)
else:
# no arguments were used so start pluGET console
clear_console()
print_logo()
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:
"""
Manages the correct function calling from the given input
"""
while True:
# when arguemnts were not passed from console ask for input
if arguments_from_console is False:
try:
input_command, input_selected_object, input_parameter = get_input()
except TypeError:
# KeyboardInterrupt was triggered and None was returned so exit
return
"""
Manages the correct function calling from the given input
"""
while True:
# when arguemnts were not passed from console ask for input
if arguments_from_console is False:
try:
input_command, input_selected_object, input_parameter = get_input()
except TypeError:
# KeyboardInterrupt was triggered and None was returned so exit
return
match input_command:
case "get":
match input_selected_object.isdigit():
case True:
get_specific_plugin(input_selected_object, input_parameter)
case _:
print("get search specific package")
#searchPackage(inputSelectedObject)
match input_command:
case "get":
match input_selected_object.isdigit():
case True:
get_specific_plugin(input_selected_object, input_parameter)
case _:
print("get search specific package")
#searchPackage(inputSelectedObject)
case "update":
print("update package")
match input_selected_object:
case "serverjar":
print("update serverjar")
#updateServerjar(inputParams)
case _:
print("update package")
#updateInstalledPackage(inputSelectedObject)
case "update":
print("update package")
match input_selected_object:
case "serverjar":
print("update serverjar")
#updateServerjar(inputParams)
case _:
print("update package")
#updateInstalledPackage(inputSelectedObject)
case "check":
print("check package")
match input_selected_object:
case "serverjar":
print("check serverjar")
#checkInstalledServerjar()
case _:
print("check plugins")
#checkInstalledPackage(inputSelectedObject, inputParams)
case "check":
print("check package")
match input_selected_object:
case "serverjar":
print("check serverjar")
#checkInstalledServerjar()
case _:
print("check plugins")
#checkInstalledPackage(inputSelectedObject, inputParams)
case "search":
print("search package")
#searchPackage(inputSelectedObject)
case "remove":
print("remove package")
#removePlugin(inputSelectedObject)
case "get-paper":
# download papermc
print("download papermc")
#papermc_downloader(inputSelectedObject, inputParams)
case "exit":
return
case _:
rich_print_error("Error: Command not found. Please try again. :(")
rich_print_error("Use: 'help command' to get all available commands")
case "search":
print("search package")
#searchPackage(inputSelectedObject)
case "remove":
print("remove package")
#removePlugin(inputSelectedObject)
case "get-paper":
# download papermc
print("download papermc")
#papermc_downloader(inputSelectedObject, inputParams)
case "exit":
return
case _:
rich_print_error("Error: Command not found. Please try again. :(")
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
if arguments_from_console:
return None
# return to break out of while loop if pluGET was started with arguments from console
if arguments_from_console:
return None
def get_input() -> None:
"""
Gets command line input and calls the handle input function
"""
input_command = None
print("'STRG + C' to exit")
while True:
try:
input_command, input_selected_object, *input_parameter = input("pluGET >> ").split()
break
except ValueError:
if input_command == None:
# request input again if no input was given or not enough
continue
else:
rich_print_error("Wrong input! Use: > 'command' 'selectedObject' [optionalParams]")
rich_print_error("Use: 'help command' to get all available commands")
except KeyboardInterrupt:
return
input_parameter = input_parameter[0] if input_parameter else None
return input_command, input_selected_object, input_parameter
"""
Gets command line input and calls the handle input function
"""
input_command = None
print("'STRG + C' to exit")
while True:
try:
input_command, input_selected_object, *input_parameter = input("pluGET >> ").split()
break
except ValueError:
if input_command == None:
# request input again if no input was given or not enough
continue
else:
rich_print_error("Wrong input! Use: > 'command' 'selectedObject' [optionalParams]")
rich_print_error("Use: 'help command' to get all available commands")
except KeyboardInterrupt:
return
input_parameter = input_parameter[0] if input_parameter else None
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:
"""
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
unwanted_plugin_name = re.search(r'(^\[+[a-zA-Z0-9\s\W*\.*\-*\+*\%*\,]*\]+)', full_plugin_name)
if bool(unwanted_plugin_name):
unwanted_plugin_name_string = unwanted_plugin_name.group()
full_plugin_name = full_plugin_name.replace(unwanted_plugin_name_string, '')
"""
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
unwanted_plugin_name = re.search(r'(^\[+[a-zA-Z0-9\s\W*\.*\-*\+*\%*\,]*\]+)', full_plugin_name)
if bool(unwanted_plugin_name):
unwanted_plugin_name_string = unwanted_plugin_name.group()
full_plugin_name = full_plugin_name.replace(unwanted_plugin_name_string, '')
# 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)
try:
plugin_name_full_string = plugin_name.group()
found_plugin_name = plugin_name_full_string.replace(' ', '')
except AttributeError:
found_plugin_name = unwanted_plugin_name_string
return found_plugin_name
# 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)
try:
plugin_name_full_string = plugin_name.group()
found_plugin_name = plugin_name_full_string.replace(' ', '')
except AttributeError:
found_plugin_name = unwanted_plugin_name_string
return found_plugin_name
def get_version_id(plugin_id, plugin_version) -> str:
"""
Returns the version id of the plugin
"""
if plugin_version == None or plugin_version == 'latest':
url = f"https://api.spiget.org/v2/resources/{plugin_id}/versions/latest"
response = api_do_request(url)
if response == None:
return None
version_id = response["id"]
return version_id
"""
Returns the version id of the plugin
"""
if plugin_version == None or plugin_version == 'latest':
url = f"https://api.spiget.org/v2/resources/{plugin_id}/versions/latest"
response = api_do_request(url)
if response == None:
return None
version_id = response["id"]
return version_id
url = f"https://api.spiget.org/v2/resources/{plugin_id}/versions?size=100&sort=-name"
version_list = api_do_request(url)
if response == None:
return None
for plugins in version_list:
plugin_update = plugins["name"]
version_id = plugins["id"]
if plugin_update == plugin_version:
return version_id
return version_list[0]["id"]
url = f"https://api.spiget.org/v2/resources/{plugin_id}/versions?size=100&sort=-name"
version_list = api_do_request(url)
if version_list == None:
return None
for plugins in version_list:
plugin_update = plugins["name"]
version_id = plugins["id"]
if plugin_update == plugin_version:
return version_id
return version_list[0]["id"]
def get_version_name(plugin_id, plugin_version_id) -> str:
"""
Returns the name of a specific version
"""
url = f"https://api.spiget.org/v2/resources/{plugin_id}/versions/{plugin_version_id}"
response = api_do_request(url)
if response == None:
return None
version_name = response["name"]
return version_name
"""
Returns the name of a specific version
"""
url = f"https://api.spiget.org/v2/resources/{plugin_id}/versions/{plugin_version_id}"
response = api_do_request(url)
if response == None:
return None
version_name = response["name"]
return version_name
def get_download_path(config_values) -> str:
"""
Reads the config and gets the path of the plugin folder
"""
match (config_values.connection):
case "local":
match (config_values.local_seperate_download_path):
case True:
return config_values.local_path_to_seperate_download_path
case _:
return config_values.path_to_plugin_folder
case _:
match (config_values.remote_seperate_download_path):
case True:
return config_values.remote_path_to_seperate_download_path
case _:
return config_values.remote_plugin_folder_on_server
"""
Reads the config and gets the path of the plugin folder
"""
match (config_values.connection):
case "local":
match (config_values.local_seperate_download_path):
case True:
return config_values.local_path_to_seperate_download_path
case _:
return config_values.path_to_plugin_folder
case _:
match (config_values.remote_seperate_download_path):
case True:
return config_values.remote_path_to_seperate_download_path
case _:
return config_values.remote_plugin_folder_on_server
def download_specific_plugin_version(plugin_id, download_path, version_id="latest") -> None:
"""
Download a specific plugin
"""
#config_values = config_value()
if version_id != "latest" and version_id != None:
#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("Reverting to latest version.")
"""
Download a specific plugin
"""
#config_values = config_value()
if version_id != "latest" and version_id != None:
#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("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}/download"
#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"
urrlib_opener = urllib.request.build_opener()
urrlib_opener.addheaders = [('User-agent', 'pluGET/1.0')]
urllib.request.install_opener(urrlib_opener)
urrlib_opener = urllib.request.build_opener()
urrlib_opener.addheaders = [('User-agent', 'pluGET/1.0')]
urllib.request.install_opener(urrlib_opener)
remote_file = urllib.request.urlopen(url)
try:
file_size = int(remote_file.info()['Content-Length'])
except TypeError:
# if api won't return file size set it to 0 to avoid throwing an error
file_size = 0
urllib.request.urlretrieve(url, download_path)
print(" ", end='')
if file_size >= 1000000 and file_size != 0:
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}")
elif file_size != 0:
file_size_data = convert_file_size_down(file_size)
print("Downloaded " + (str(file_size_data)).rjust(9) + f" KB here {download_path}")
else:
print(f"Downloaded file here {download_path}")
# TODO add sftp and ftp support
#if config_values.connection == "sftp":
# sftp_session = createSFTPConnection()
# sftp_upload_file(sftp_session, download_path)
#elif config_values.connection == "ftp":
# ftp_session = createFTPConnection()
# ftp_upload_file(ftp_session, download_path)
return None
remote_file = urllib.request.urlopen(url)
try:
file_size = int(remote_file.info()['Content-Length'])
except TypeError:
# if api won't return file size set it to 0 to avoid throwing an error
file_size = 0
urllib.request.urlretrieve(url, download_path)
print(" ", end='')
if file_size >= 1000000 and file_size != 0:
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}")
elif file_size != 0:
file_size_data = convert_file_size_down(file_size)
print("Downloaded " + (str(file_size_data)).rjust(9) + f" KB here {download_path}")
else:
print(f"Downloaded file here {download_path}")
# TODO add sftp and ftp support
#if config_values.connection == "sftp":
# sftp_session = createSFTPConnection()
# sftp_upload_file(sftp_session, download_path)
#elif config_values.connection == "ftp":
# ftp_session = createFTPConnection()
# ftp_upload_file(ftp_session, download_path)
return None
def get_specific_plugin(plugin_id, plugin_version="latest") -> None:
"""
Gets the specific plugin and calls the download function
"""
config_values = config_value()
# use a temporary folder to store plugins until they are uploaded
if config_values.connection != "local":
download_path = create_temp_plugin_folder()
else:
download_path = get_download_path(config_values)
"""
Gets the specific plugin and calls the download function
"""
config_values = config_value()
# use a temporary folder to store plugins until they are uploaded
if config_values.connection != "local":
download_path = create_temp_plugin_folder()
else:
download_path = get_download_path(config_values)
url = f"https://api.spiget.org/v2/resources/{plugin_id}"
plugin_details = api_do_request(url)
if plugin_details == None:
return None
try:
plugin_name = plugin_details["name"]
except KeyError:
# exit if plugin id coudn't be found
rich_print_error("Error: Plugin ID couldn't be found")
return None
plugin_name = handle_regex_package_name(plugin_name)
plugin_version_id = get_version_id(plugin_id, plugin_version)
plugin_version_name = get_version_name(plugin_id, plugin_version_id)
plugin_download_name = f"{plugin_name}-{plugin_version_name}.jar"
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
if plugin_version == "latest" or plugin_version is None:
plugin_version_id = None
download_specific_plugin_version(plugin_id, download_plugin_path, plugin_version_id)
url = f"https://api.spiget.org/v2/resources/{plugin_id}"
plugin_details = api_do_request(url)
if plugin_details == None:
return None
try:
plugin_name = plugin_details["name"]
except KeyError:
# exit if plugin id coudn't be found
rich_print_error("Error: Plugin ID couldn't be found")
return None
plugin_name = handle_regex_package_name(plugin_name)
plugin_version_id = get_version_id(plugin_id, plugin_version)
plugin_version_name = get_version_name(plugin_id, plugin_version_id)
plugin_download_name = f"{plugin_name}-{plugin_version_name}.jar"
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
if plugin_version == "latest" or plugin_version is None:
plugin_version_id = None
download_specific_plugin_version(plugin_id, download_plugin_path, plugin_version_id)
if config_values.connection != "local":
remove_temp_plugin_folder()
return None
if config_values.connection != "local":
remove_temp_plugin_folder()
return None

View File

@ -5,6 +5,7 @@ from src.utils import utilities
class TestCases(unittest.TestCase):
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_cropped = "SUPERBPlugin"
result = plugin_downloader.handle_regex_package_name(plugin_name)
@ -12,15 +13,15 @@ class TestCases(unittest.TestCase):
def test_get_version_id(self):
# 1234 -> "AntiPickup" in Version 1.4.1
result = plugin_downloader.get_version_id("1234", "1.4.1")
self.assertEqual(result, 43779)
# 21840 -> "Luckperms" in Version 5.4.30
result = plugin_downloader.get_version_id("28140", "5.4.30")
self.assertEqual(result, 455966)
def test_get_version_name(self):
# 43779 -> "1.4.1" from AntiPickup
result = plugin_downloader.get_version_name("1234", 43779)
self.assertEqual(result, "1.4.1")
# 455966 -> "5.4.30" from Luckperms
result = plugin_downloader.get_version_name("28140", 455966)
self.assertEqual(result, "5.4.30")
def test_get_download_path(self):
@ -50,6 +51,7 @@ class TestCases(unittest.TestCase):
def test_convert_file_size_down(self):
# 100000 / 1024 = 97.66
result= utilities.convert_file_size_down(100000)
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
@ -7,132 +7,132 @@ from rich.console import Console
def rich_print_error(error_message) -> None:
"""
Prints a formatted error message from rich
"""
console = Console()
console.print(error_message, style="bright_red")
return None
"""
Prints a formatted error message from rich
"""
console = Console()
console.print(error_message, style="bright_red")
return None
def rename_console_title() -> None:
"""
Renames the console title on first startup
"""
os.system("title " + "pluGET │ By Neocky")
return None
"""
Renames the console title on first startup
"""
os.system("title " + "pluGET │ By Neocky")
return None
def clear_console() -> None:
"""
Clears the console on first startup
"""
os.system('cls' if os.name=='nt' else 'clear')
return None
"""
Clears the console on first startup
"""
os.system('cls' if os.name=='nt' else 'clear')
return None
def print_logo() -> None:
"""
Prints the logo of pluGET and the link to the github repo
"""
# use rich console
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(" ██████", 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 5
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 6
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 7
console.print(" ╚═╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ", style="bright_yellow")
# line 8
console.print()
# line 9
console.print(" ┌────────────────────────────────────┐", style="bright_black")
# line 10
console.print(" │ [", style="bright_black", end='')
console.print("By Neocky", style="bright_magenta", end='')
console.print("] │ ", style="bright_black")
"""
Prints the logo of pluGET and the link to the github repo
"""
# use rich console
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(" ██████", 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 5
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 6
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 7
console.print(" ╚═╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ", style="bright_yellow")
# line 8
console.print()
# line 9
console.print(" ┌────────────────────────────────────┐", style="bright_black")
# line 10
console.print(" │ [", style="bright_black", end='')
console.print("By Neocky", style="bright_magenta", end='')
console.print("] │ ", style="bright_black")
# line 11
console.print("", style="bright_black", end='')
console.print("https://github.com/Neocky/pluGET", style="link https://github.com/Neocky/pluGET", end='')
console.print("", style="bright_black")
# line 12
console.print(" └────────────────────────────────────┘", style="bright_black")
console.print(" ───────────────────────────────────────────────────")
return None
console.print("", style="bright_black", end='')
console.print("https://github.com/Neocky/pluGET", style="link https://github.com/Neocky/pluGET", end='')
console.print("", style="bright_black")
# line 12
console.print(" └────────────────────────────────────┘", style="bright_black")
console.print(" ───────────────────────────────────────────────────")
return None

View File

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