mirror of
https://github.com/Neocky/pluGET.git
synced 2024-04-29 16:12:30 +00:00
Started the new config handling
Implemented new and not complete config handling and implemented command parameter support
This commit is contained in:
0
old_src/utils/__init__.py
Normal file
0
old_src/utils/__init__.py
Normal file
89
old_src/utils/consoleoutput.py
Normal file
89
old_src/utils/consoleoutput.py
Normal file
@@ -0,0 +1,89 @@
|
||||
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"
|
||||
brightBlack = "\033[90m"
|
||||
brightRed = "\033[91m"
|
||||
brightGreen = "\033[92m"
|
||||
brightYellow = "\033[93m"
|
||||
brightMagenta = "\033[95m"
|
||||
|
||||
|
||||
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.brightBlack + " ┌────────────────────────────────────┐" + oColors.standardWhite)
|
||||
print(oColors.brightBlack + " │ [" + 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)
|
||||
|
||||
|
||||
def printHorizontalLine():
|
||||
print(" ─────────────────────────────────────────────────────────────────────────────────")
|
||||
|
||||
|
||||
def printMainMenu():
|
||||
printLogo()
|
||||
printHorizontalLine()
|
175
old_src/utils/utilities.py
Normal file
175
old_src/utils/utilities.py
Normal file
@@ -0,0 +1,175 @@
|
||||
# misc functions
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import requests
|
||||
from pathlib import Path
|
||||
|
||||
from utils.consoleoutput import oColors
|
||||
from handlers.handle_config import configurationValues
|
||||
from handlers.handle_sftp import createSFTPConnection
|
||||
from handlers.handle_ftp import createFTPConnection
|
||||
|
||||
|
||||
def getHelp():
|
||||
print(oColors.brightYellow+ "Need help?" + oColors.standardWhite)
|
||||
print("For a list of all commands: 'help command'")
|
||||
print("Or 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 getCommandHelp(optionalParams):
|
||||
if optionalParams == None:
|
||||
optionalParams = 'all'
|
||||
print(oColors.brightBlack + f"Help for command: {optionalParams}" +oColors.standardWhite)
|
||||
print("┌────────────────┬─────────────────┬─────────────────┬────────────────────────────────────────────────────────┐")
|
||||
print("│ Command │ Selected Object │ Optional Params │ Function │")
|
||||
print("└────────────────┴─────────────────┴─────────────────┴────────────────────────────────────────────────────────┘")
|
||||
while True:
|
||||
if optionalParams == 'all':
|
||||
print(oColors.brightBlack + " GENERAL:" + oColors.standardWhite)
|
||||
print(" exit ./anything Exit pluGET")
|
||||
print(" help ./anything Get general help")
|
||||
print(" help command all/command Get specific help to the commands of pluGET")
|
||||
print(oColors.brightBlack + " PLUGIN MANAGEMENT:" + oColors.standardWhite)
|
||||
print(" get Name/ID Version Downloads the latest version of a plugin")
|
||||
print(" check Name/ID/all changelog Check for an update of an installed plugin")
|
||||
print(" update Name/ID/all Update installed plugins to the latest version")
|
||||
print(" search Name Search for a plugin and download the latest version")
|
||||
print(" remove Name/ID Delete an installed plugin")
|
||||
print(oColors.brightBlack + " SERVER SOFTWARE MANAGEMENT:" + oColors.standardWhite)
|
||||
print(" check serverjar Check installed server software for an update")
|
||||
print(" update serverjar Version/Latest Update installed server software to a specific version")
|
||||
print(" get-paper PaperVersion McVersion Downloads a specific PaperMc version")
|
||||
break
|
||||
|
||||
if optionalParams == 'exit':
|
||||
print(oColors.brightBlack + " GENERAL:" + oColors.standardWhite)
|
||||
print(" exit ./anything Exit pluGET")
|
||||
break
|
||||
|
||||
if optionalParams == 'help':
|
||||
print(oColors.brightBlack + " GENERAL:" + oColors.standardWhite)
|
||||
print(" help ./anything Get general help")
|
||||
print(" help command all/command Get specific help to the commands of pluGET")
|
||||
break
|
||||
|
||||
if optionalParams == 'get':
|
||||
print(oColors.brightBlack + " PLUGIN MANAGEMENT:" + oColors.standardWhite)
|
||||
print(print(" get Name/ID Version Downloads the latest version of a plugin"))
|
||||
break
|
||||
|
||||
if optionalParams == 'check':
|
||||
print(oColors.brightBlack + " PLUGIN MANAGEMENT:" + oColors.standardWhite)
|
||||
print(" check Name/ID/all Check for an update of an installed plugin")
|
||||
print(oColors.brightBlack + " SERVER SOFTWARE MANAGEMENT:" + oColors.standardWhite)
|
||||
print(" check serverjar Check installed server software for an update")
|
||||
break
|
||||
|
||||
if optionalParams == 'update':
|
||||
print(oColors.brightBlack + " PLUGIN MANAGEMENT:" + oColors.standardWhite)
|
||||
print(" update Name/ID/all Update installed plugins to the latest version")
|
||||
print(oColors.brightBlack + " SERVER SOFTWARE MANAGEMENT:" + oColors.standardWhite)
|
||||
print(" update serverjar Version/Latest Update installed server software to a specific version")
|
||||
break
|
||||
|
||||
if optionalParams == 'search':
|
||||
print(oColors.brightBlack + " PLUGIN MANAGEMENT:" + oColors.standardWhite)
|
||||
print(" search Name Search for a plugin and download the latest version")
|
||||
break
|
||||
|
||||
if optionalParams == 'remove':
|
||||
print(oColors.brightBlack + " PLUGIN MANAGEMENT:" + oColors.standardWhite)
|
||||
print(" remove Name/ID Delete an installed plugin")
|
||||
break
|
||||
|
||||
if optionalParams == 'get-paper':
|
||||
print(oColors.brightBlack + " SERVER SOFTWARE MANAGEMENT:" + oColors.standardWhite)
|
||||
print(" get-paper PaperVersion McVersion Downloads a specific PaperMc version")
|
||||
break
|
||||
|
||||
else:
|
||||
print(oColors.brightRed + "Error: Help for Command not found. Please try again. :(" + oColors.standardWhite)
|
||||
break
|
||||
|
||||
|
||||
def check_local_plugin_folder():
|
||||
configValues = configurationValues()
|
||||
if configValues.localPluginFolder:
|
||||
if configValues.seperateDownloadPath:
|
||||
pluginFolderPath = configValues.pathToSeperateDownloadPath
|
||||
else:
|
||||
pluginFolderPath = configValues.pathToPluginFolder
|
||||
|
||||
if not os.path.isdir(pluginFolderPath):
|
||||
print(oColors.brightRed + "Plugin folder coulnd*t be found. Creating one..." + oColors.standardWhite)
|
||||
try:
|
||||
os.mkdir(pluginFolderPath)
|
||||
except OSError:
|
||||
print(oColors.brightRed + "Creation of directory %s failed" % pluginFolderPath)
|
||||
print(oColors.brightRed + "Please check the config file!" + oColors.standardWhite)
|
||||
input("Press any key + enter to exit...")
|
||||
sys.exit()
|
||||
else:
|
||||
print("Created directory %s" % pluginFolderPath)
|
||||
|
||||
|
||||
def apiTest():
|
||||
apiStatusUrl = 'https://api.spiget.org/v2/status'
|
||||
try:
|
||||
r = requests.get(apiStatusUrl)
|
||||
except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError):
|
||||
print(oColors.brightRed + "Couldn't make a connection to the API. Check you connection to the internet!" + oColors.standardWhite)
|
||||
input("Press any key + enter to exit...")
|
||||
sys.exit()
|
||||
if r.status_code != 200:
|
||||
print(oColors.brightRed + "Problems with the API detected. Plese try it again later!" + oColors.standardWhite)
|
||||
input("Press any key + enter to exit...")
|
||||
sys.exit()
|
||||
|
||||
|
||||
def check_requirements():
|
||||
configValues = configurationValues()
|
||||
apiTest()
|
||||
check_local_plugin_folder()
|
||||
if not configValues.localPluginFolder:
|
||||
if configValues.sftp_useSftp:
|
||||
createSFTPConnection()
|
||||
else:
|
||||
createFTPConnection()
|
||||
|
||||
|
||||
def createTempPluginFolder():
|
||||
configValues = configurationValues()
|
||||
tempPluginFolder = Path("./TempSFTPFolder")
|
||||
if not os.path.isdir(tempPluginFolder):
|
||||
try:
|
||||
os.mkdir(tempPluginFolder)
|
||||
except OSError:
|
||||
print(oColors.brightRed + "Creation of directory %s failed" % configValues.pathToPluginFolder)
|
||||
print(oColors.brightRed + "Please check the config file!" + oColors.standardWhite)
|
||||
input("Press any key + enter to exit...")
|
||||
sys.exit()
|
||||
return tempPluginFolder
|
||||
|
||||
|
||||
def deleteTempPluginFolder(tempPluginFolder):
|
||||
try:
|
||||
shutil.rmtree(tempPluginFolder)
|
||||
except OSError as e:
|
||||
print ("Error: %s - %s." % (e.filename, e.strerror))
|
||||
|
||||
|
||||
def calculateFileSizeMb(downloadFileSize):
|
||||
fileSizeDownload = int(downloadFileSize)
|
||||
fileSizeMb = fileSizeDownload / 1024 / 1024
|
||||
roundedFileSize = round(fileSizeMb, 2)
|
||||
return roundedFileSize
|
||||
|
||||
def calculateFileSizeKb(downloadFileSize):
|
||||
fileSizeDownload = int(downloadFileSize)
|
||||
fileSizeKb = fileSizeDownload / 1024
|
||||
roundedFileSize = round(fileSizeKb, 2)
|
||||
return roundedFileSize
|
9
old_src/utils/web_request.py
Normal file
9
old_src/utils/web_request.py
Normal file
@@ -0,0 +1,9 @@
|
||||
# Handles the web requests
|
||||
import requests
|
||||
|
||||
|
||||
def doAPIRequest(url):
|
||||
headers = {'user-agent': 'pluGET/1.0'}
|
||||
response = requests.get(url, headers=headers)
|
||||
packageDetails = response.json()
|
||||
return packageDetails
|
Reference in New Issue
Block a user