Split everything in sub packages; Created main function; Added many exception handlers for SFTP

Added:
- Split everything into sub packages
- created a main file: __main__.py
- added many exception handlings with SFTP

Edited:
- launcher.bat calls now the __main__.py file
This commit is contained in:
Neocky
2021-03-12 01:39:39 +01:00
parent 36c96f7d23
commit ac561d92ce
17 changed files with 239 additions and 176 deletions

0
src/utils/__init__.py Normal file
View File

View File

@@ -0,0 +1,91 @@
# Handles the console output
from os import system
from os import name
def consoleTitle():
system("title " + "pluGET │ by Neocky")
def clearConsole():
system('cls' if name=='nt' else 'clear')
# https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
class oColors:
standardWhite = "\033[0m"
brightYellow = "\033[93m"
brightMagenta = "\033[95m"
brightRed = "\033[91m"
darkMagenta = "\033[35m"
def printLogo():
print()
print(oColors.brightYellow + r" ___ ___ ___ ___ ___ ___ ")
print(oColors.brightMagenta + r" /\ " + oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/"'\\' +
oColors.brightYellow + r"__\ " + oColors.brightMagenta + r"/"'\\' + oColors.brightYellow + r"__\ " +
oColors.brightMagenta + r"/\ "+ oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/\ "+
oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/\ "+ oColors.brightYellow + r""'\\ ')
print(oColors.brightMagenta + r" /::\ "+ oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/:/ " +
oColors.brightYellow + r"/ " + oColors.brightMagenta + r"/:/ "+ oColors.brightYellow + r"/ " +
oColors.brightMagenta + r"/::\ "+ oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/::\ "+
oColors.brightYellow + r"\ " + oColors.brightMagenta + r"\:\ "+ oColors.brightYellow + r""'\\ ')
print(oColors.brightMagenta + r" /:/\:\ "+ oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/:/ "+
oColors.brightYellow + r"/ " + oColors.brightMagenta + r"/:/ "+ oColors.brightYellow + r"/ " +
oColors.brightMagenta + r"/:/\:\ "+ oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/:/\:\ "+
oColors.brightYellow + r"\ " + oColors.brightMagenta + r"\:\ "+ oColors.brightYellow + r""'\\ ')
print(oColors.brightMagenta + r" /::"'\\' + oColors.brightYellow + r"~" + oColors.brightMagenta + r"\:\ "+
oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/:/ "+ oColors.brightYellow + r"/ " +
oColors.brightMagenta + r"/:/ "+ oColors.brightYellow + r"/ ___ " + oColors.brightMagenta + r"/:/ \:\ "+
oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/::"'\\'+ oColors.brightYellow + r"~" +
oColors.brightMagenta + r"\:\ "+ oColors.brightYellow + r"\ " + oColors.brightMagenta + r"/::\ "+
oColors.brightYellow + r""'\\')
print(oColors.brightMagenta + r" /:/\:\ \:"'\\'+ oColors.brightYellow + r"__\ " + oColors.brightMagenta + r"/:/"+
oColors.brightYellow + r"__/ " + oColors.brightMagenta + r"/:/"+ oColors.brightYellow + r"__/ " +
oColors.brightMagenta + r"/"'\\'+ oColors.brightYellow + r"__\ " + oColors.brightMagenta + r"/:/"+
oColors.brightYellow + r"__/_" + oColors.brightMagenta + r"\:"'\\'+ oColors.brightYellow + r"__\ " +
oColors.brightMagenta + r"/:/\:\ \:"'\\' + oColors.brightYellow + r"__\ " +
oColors.brightMagenta + r"/:/\:"'\\'+ oColors.brightYellow + r"__\ ")
print(oColors.brightMagenta + r" " + oColors.brightMagenta + r"\/"+ oColors.brightYellow + r"__" +
oColors.brightMagenta + r"\:\/:/"+ oColors.brightYellow + r" / " + oColors.brightMagenta + r"\:"'\\'+
oColors.brightYellow + r" \ " + oColors.brightMagenta + r"\:"'\\' + oColors.brightYellow + r" \ " +
oColors.brightMagenta + r"/:/ "+ oColors.brightYellow + r"/ " + oColors.brightMagenta + r"\:\ /\ \/" +
oColors.brightYellow + r"__/ " + oColors.brightMagenta + r"\:"'\\' + oColors.brightYellow + r"~" +
oColors.brightMagenta + r"\:\ \/" + oColors.brightYellow + r"__/ " + oColors.brightMagenta + r"/:/ \/"+
oColors.brightYellow + r"__/")
print(oColors.brightMagenta + r" \::/ "+ oColors.brightYellow + r"/ " + oColors.brightMagenta + r"\:\ "+
oColors.brightYellow + r"\ " + oColors.brightMagenta + r"\:\ /:/ "+ oColors.brightYellow + r"/ " +
oColors.brightMagenta + r"\:\ \:"'\\'+ oColors.brightYellow + r"__\ " + oColors.brightMagenta + r"\:\ \:"'\\'+
oColors.brightYellow + r"__\ " + oColors.brightMagenta + r"/:/ "+ oColors.brightYellow + r"/ ")
print(oColors.brightMagenta + r" \/"+ oColors.brightYellow + r"__/ " +
oColors.brightMagenta + r"\:\ " + oColors.brightYellow + r"\ " + oColors.brightMagenta + r"\:\/:/ "+
oColors.brightYellow + r"/ " + oColors.brightMagenta + r"\:\/:/ "+ oColors.brightYellow + r"/ " +
oColors.brightMagenta + r"\:\ \/"+ oColors.brightYellow + r"__/ " + oColors.brightMagenta + r"\/"+
oColors.brightYellow + r"__/ ")
print(oColors.brightMagenta + r" \:"'\\' + oColors.brightYellow + r"__\ " +
oColors.brightMagenta + r"\::/ " + oColors.brightYellow + r"/ " + oColors.brightMagenta + r"\::/ " +
oColors.brightYellow + r"/ " + oColors.brightMagenta + r"\:"'\\' + oColors.brightYellow + r"__\ ")
print(oColors.brightMagenta + r" \/" + oColors.brightYellow + r"__/ " +
oColors.brightMagenta + r"\/" + oColors.brightYellow + r"__/ " + oColors.brightMagenta + r"\/" +
oColors.brightYellow + r"__/ " + oColors.brightMagenta + r"\/" + oColors.brightYellow + r"__/ " +
oColors.standardWhite)
print()
print()
print(oColors.brightYellow + " [" + oColors.darkMagenta + "by Neocky" +
oColors.brightYellow + "] " + oColors.standardWhite)
print()
def printHorizontalLine():
print(" ─────────────────────────────────────────────────────────────────────────────────")
def printMainMenu():
printLogo()
printHorizontalLine()
#print(" [1] Download a specific package")
#print(" [2] Get update info of package")
#print(" [3] Search for a plugin")
#print(" [4] Download latest version of package")
#print(" [5] Check update for installed plugins")
#print()

67
src/utils/utilities.py Normal file
View File

@@ -0,0 +1,67 @@
# misc functions
import os
import sys
import shutil
import requests
from utils.consoleoutput import oColors
from handlers.handle_config import checkConfig
def getHelp():
print(oColors.brightYellow+ "Need help?" + oColors.standardWhite)
print("Check the docs here:")
print("https://github.com/Neocky/pluGET")
print("Or go to the official discord.")
print("The link for discord can also be found on Github!")
def check_local_plugin_folder():
if checkConfig().localPluginFolder:
if not os.path.isdir(checkConfig().pathToPluginFolder):
print(oColors.brightRed + "Plugin folder coulnd*t be found. Creating one..." + oColors.standardWhite)
try:
os.mkdir(checkConfig().pathToPluginFolder)
except OSError:
print(oColors.brightRed + "Creation of directory %s failed" % checkConfig().pathToPluginFolder)
print(oColors.brightRed + "Please check the config file!" + oColors.standardWhite)
sys.exit()
else:
print("Created directory %s" % checkConfig().pathToPluginFolder)
def apiTest():
apiStatusUrl = 'https://api.spiget.org/v2/status'
try:
r = requests.get(apiStatusUrl)
except requests.exceptions.HTTPError:
print(oColors.brightRed + "Couldn't make a connection to the API. Check you connection to the internet!" + oColors.standardWhite)
sys.exit()
if r.status_code != 200:
print(oColors.brightRed + "Problems with the API detected. Plese try it again later!" + oColors.standardWhite)
sys.exit()
def check_requirements():
apiTest()
check_local_plugin_folder()
# sftp test
def createTempPluginFolder():
tempPluginFolder = ".\\plugins"
if not os.path.isdir(tempPluginFolder):
#print(oColors.brightRed + "Plugin folder coulnd*t be found. Creating one..." + oColors.standardWhite)
try:
os.mkdir(tempPluginFolder)
except OSError:
print(oColors.brightRed + "Creation of directory %s failed" % checkConfig().pathToPluginFolder)
print(oColors.brightRed + "Please check the config file!" + oColors.standardWhite)
sys.exit()
return tempPluginFolder
def deleteTempPluginFolder(tempPluginFolder):
try:
shutil.rmtree(tempPluginFolder)
except OSError as e:
print ("Error: %s - %s." % (e.filename, e.strerror))

9
src/utils/web_request.py Normal file
View File

@@ -0,0 +1,9 @@
# Handles the web requests
import requests
def doAPIRequest(url):
headers = {'user-agent': 'pluGET'}
response = requests.get(url, headers=headers)
packageDetails = response.json()
return packageDetails