2021-03-08 21:13:57 +00:00
|
|
|
# misc functions
|
2021-03-10 01:05:56 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import shutil
|
2021-03-12 00:39:39 +00:00
|
|
|
import requests
|
2021-03-16 00:04:13 +00:00
|
|
|
from pathlib import Path
|
2021-03-12 00:39:39 +00:00
|
|
|
|
|
|
|
from utils.consoleoutput import oColors
|
2021-03-27 11:07:19 +00:00
|
|
|
from handlers.handle_config import configurationValues
|
2021-03-13 21:09:32 +00:00
|
|
|
from handlers.handle_sftp import createSFTPConnection
|
2021-03-10 01:05:56 +00:00
|
|
|
|
2021-03-08 21:13:57 +00:00
|
|
|
|
|
|
|
def getHelp():
|
|
|
|
print(oColors.brightYellow+ "Need help?" + oColors.standardWhite)
|
2021-03-21 15:37:25 +00:00
|
|
|
print("For a list of all commands: 'help command'")
|
2021-03-21 13:30:27 +00:00
|
|
|
print("Or check the docs here:")
|
2021-03-08 21:13:57 +00:00
|
|
|
print("https://github.com/Neocky/pluGET")
|
|
|
|
print("Or go to the official discord.")
|
|
|
|
print("The link for discord can also be found on Github!")
|
2021-03-10 01:05:56 +00:00
|
|
|
|
|
|
|
|
2021-03-21 13:30:27 +00:00
|
|
|
def getCommandHelp(optionalParams):
|
|
|
|
if optionalParams == None:
|
|
|
|
optionalParams = 'all'
|
2021-03-21 15:37:25 +00:00
|
|
|
print(oColors.brightBlack + f"Help for command: {optionalParams}" +oColors.standardWhite)
|
2021-03-21 13:30:27 +00:00
|
|
|
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 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")
|
2021-03-21 15:37:25 +00:00
|
|
|
print(" get-paper PaperVersion McVersion Downloads a specific PaperMc version")
|
2021-03-21 13:30:27 +00:00
|
|
|
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)
|
2021-03-21 15:37:25 +00:00
|
|
|
print(" get-paper PaperVersion McVersion Downloads a specific PaperMc version")
|
2021-03-21 13:30:27 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
else:
|
|
|
|
print(oColors.brightRed + "Error: Help for Command not found. Please try again. :(" + oColors.standardWhite)
|
|
|
|
break
|
|
|
|
|
|
|
|
|
2021-03-10 01:05:56 +00:00
|
|
|
def check_local_plugin_folder():
|
2021-03-27 11:07:19 +00:00
|
|
|
configValues = configurationValues()
|
|
|
|
if configValues.localPluginFolder:
|
|
|
|
if configValues.seperateDownloadPath:
|
|
|
|
pluginFolderPath = configValues.pathToSeperateDownloadPath
|
2021-03-14 12:25:13 +00:00
|
|
|
else:
|
2021-03-27 11:07:19 +00:00
|
|
|
pluginFolderPath = configValues.pathToPluginFolder
|
2021-03-14 12:25:13 +00:00
|
|
|
|
|
|
|
if not os.path.isdir(pluginFolderPath):
|
2021-03-10 01:05:56 +00:00
|
|
|
print(oColors.brightRed + "Plugin folder coulnd*t be found. Creating one..." + oColors.standardWhite)
|
|
|
|
try:
|
2021-03-14 12:25:13 +00:00
|
|
|
os.mkdir(pluginFolderPath)
|
2021-03-10 01:05:56 +00:00
|
|
|
except OSError:
|
2021-03-14 12:25:13 +00:00
|
|
|
print(oColors.brightRed + "Creation of directory %s failed" % pluginFolderPath)
|
2021-03-10 01:05:56 +00:00
|
|
|
print(oColors.brightRed + "Please check the config file!" + oColors.standardWhite)
|
2021-03-13 22:12:56 +00:00
|
|
|
input("Press any key + enter to exit...")
|
2021-03-10 01:05:56 +00:00
|
|
|
sys.exit()
|
|
|
|
else:
|
2021-03-14 12:25:13 +00:00
|
|
|
print("Created directory %s" % pluginFolderPath)
|
2021-03-10 01:05:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
def apiTest():
|
|
|
|
apiStatusUrl = 'https://api.spiget.org/v2/status'
|
|
|
|
try:
|
|
|
|
r = requests.get(apiStatusUrl)
|
|
|
|
except requests.exceptions.HTTPError:
|
2021-03-12 00:39:39 +00:00
|
|
|
print(oColors.brightRed + "Couldn't make a connection to the API. Check you connection to the internet!" + oColors.standardWhite)
|
2021-03-13 22:12:56 +00:00
|
|
|
input("Press any key + enter to exit...")
|
2021-03-10 01:05:56 +00:00
|
|
|
sys.exit()
|
|
|
|
if r.status_code != 200:
|
|
|
|
print(oColors.brightRed + "Problems with the API detected. Plese try it again later!" + oColors.standardWhite)
|
2021-03-13 22:12:56 +00:00
|
|
|
input("Press any key + enter to exit...")
|
2021-03-10 01:05:56 +00:00
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
|
|
|
|
def check_requirements():
|
2021-03-27 11:07:19 +00:00
|
|
|
configValues = configurationValues()
|
2021-03-10 01:05:56 +00:00
|
|
|
apiTest()
|
|
|
|
check_local_plugin_folder()
|
2021-03-27 11:07:19 +00:00
|
|
|
if not configValues.localPluginFolder:
|
2021-03-13 21:09:32 +00:00
|
|
|
createSFTPConnection()
|
|
|
|
|
2021-03-10 01:05:56 +00:00
|
|
|
|
|
|
|
def createTempPluginFolder():
|
2021-03-16 00:04:13 +00:00
|
|
|
tempPluginFolder = Path("./TempSFTPUploadFolder")
|
2021-03-10 01:05:56 +00:00
|
|
|
if not os.path.isdir(tempPluginFolder):
|
|
|
|
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)
|
2021-03-13 22:12:56 +00:00
|
|
|
input("Press any key + enter to exit...")
|
2021-03-10 01:05:56 +00:00
|
|
|
sys.exit()
|
|
|
|
return tempPluginFolder
|
|
|
|
|
|
|
|
|
|
|
|
def deleteTempPluginFolder(tempPluginFolder):
|
|
|
|
try:
|
|
|
|
shutil.rmtree(tempPluginFolder)
|
|
|
|
except OSError as e:
|
2021-03-12 00:39:39 +00:00
|
|
|
print ("Error: %s - %s." % (e.filename, e.strerror))
|
2021-03-16 00:04:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
def calculateFileSizeMb(downloadFileSize):
|
|
|
|
fileSizeDownload = int(downloadFileSize)
|
|
|
|
fileSizeMb = fileSizeDownload / 1024 / 1024
|
|
|
|
roundedFileSize = round(fileSizeMb, 2)
|
|
|
|
return roundedFileSize
|
2021-03-26 19:24:15 +00:00
|
|
|
|
|
|
|
def calculateFileSizeKb(downloadFileSize):
|
|
|
|
fileSizeDownload = int(downloadFileSize)
|
|
|
|
fileSizeKb = fileSizeDownload / 1024
|
|
|
|
roundedFileSize = round(fileSizeKb, 2)
|
|
|
|
return roundedFileSize
|