mirror of
https://github.com/Neocky/pluGET.git
synced 2024-04-29 16:12:30 +00:00
Added papermc support & fixing some issues
Changes: - adding papermc support - paper can be checked for an update - can be updated to latest or specific version - download specific paper version for different minecraft versions
This commit is contained in:
parent
20261d110e
commit
5e296e858f
@ -6,6 +6,9 @@ from handlers.handle_config import checkConfig
|
|||||||
from plugin.plugin_downloader import searchPackage, getSpecificPackage
|
from plugin.plugin_downloader import searchPackage, getSpecificPackage
|
||||||
from plugin.plugin_updatechecker import updateInstalledPackage, checkInstalledPackage
|
from plugin.plugin_updatechecker import updateInstalledPackage, checkInstalledPackage
|
||||||
from plugin.plugin_remover import removePlugin
|
from plugin.plugin_remover import removePlugin
|
||||||
|
from serverjar.serverjar_checker import checkInstalledServerjar, updateServerjar
|
||||||
|
from serverjar.serverjar_paper import papermc_downloader
|
||||||
|
|
||||||
|
|
||||||
def createInputLists():
|
def createInputLists():
|
||||||
global COMMANDLIST
|
global COMMANDLIST
|
||||||
@ -16,7 +19,8 @@ def createInputLists():
|
|||||||
'search',
|
'search',
|
||||||
'exit',
|
'exit',
|
||||||
'help',
|
'help',
|
||||||
'remove'
|
'remove',
|
||||||
|
'get-paper'
|
||||||
]
|
]
|
||||||
global INPUTSELECTEDOBJECT
|
global INPUTSELECTEDOBJECT
|
||||||
INPUTSELECTEDOBJECT = [
|
INPUTSELECTEDOBJECT = [
|
||||||
@ -47,10 +51,16 @@ def handleInput(inputCommand, inputSelectedObject, inputParams):
|
|||||||
searchPackage(inputSelectedObject)
|
searchPackage(inputSelectedObject)
|
||||||
break
|
break
|
||||||
if inputCommand == 'update':
|
if inputCommand == 'update':
|
||||||
updateInstalledPackage(inputSelectedObject)
|
if inputSelectedObject == 'serverjar':
|
||||||
|
updateServerjar(inputParams)
|
||||||
|
else:
|
||||||
|
updateInstalledPackage(inputSelectedObject)
|
||||||
break
|
break
|
||||||
if inputCommand == 'check':
|
if inputCommand == 'check':
|
||||||
checkInstalledPackage(inputSelectedObject)
|
if inputSelectedObject == 'serverjar':
|
||||||
|
checkInstalledServerjar()
|
||||||
|
else:
|
||||||
|
checkInstalledPackage(inputSelectedObject)
|
||||||
break
|
break
|
||||||
if inputCommand == 'search':
|
if inputCommand == 'search':
|
||||||
searchPackage(inputSelectedObject)
|
searchPackage(inputSelectedObject)
|
||||||
@ -63,6 +73,9 @@ def handleInput(inputCommand, inputSelectedObject, inputParams):
|
|||||||
if inputCommand == 'remove':
|
if inputCommand == 'remove':
|
||||||
removePlugin(inputSelectedObject)
|
removePlugin(inputSelectedObject)
|
||||||
break
|
break
|
||||||
|
if inputCommand == 'get-paper':
|
||||||
|
papermc_downloader(inputSelectedObject, inputParams)
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
print(oColors.brightRed + "Command not found. Please try again." + oColors.standardWhite)
|
print(oColors.brightRed + "Command not found. Please try again." + oColors.standardWhite)
|
||||||
getInput()
|
getInput()
|
||||||
|
@ -45,6 +45,17 @@ def sftp_upload_file(sftp, itemPath):
|
|||||||
sftp.close()
|
sftp.close()
|
||||||
|
|
||||||
|
|
||||||
|
def sftp_upload_server_jar(sftp, itemPath):
|
||||||
|
try:
|
||||||
|
sftp.chdir('.')
|
||||||
|
sftp.put(itemPath)
|
||||||
|
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(oColors.brightRed + "The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||||
|
print(oColors.brightRed + "Aborting installation." + oColors.standardWhite)
|
||||||
|
sftp.close()
|
||||||
|
|
||||||
|
|
||||||
def sftp_listAll(sftp):
|
def sftp_listAll(sftp):
|
||||||
try:
|
try:
|
||||||
sftp.chdir('plugins')
|
sftp.chdir('plugins')
|
||||||
@ -57,3 +68,17 @@ def sftp_listAll(sftp):
|
|||||||
return installedPlugins
|
return installedPlugins
|
||||||
except UnboundLocalError:
|
except UnboundLocalError:
|
||||||
print(oColors.brightRed + "No plugins were found." + oColors.standardWhite)
|
print(oColors.brightRed + "No plugins were found." + oColors.standardWhite)
|
||||||
|
|
||||||
|
|
||||||
|
def sftp_listFilesInServerRoot(sftp):
|
||||||
|
try:
|
||||||
|
#sftp.chdir('plugins')
|
||||||
|
filesInServerRoot = sftp.listdir()
|
||||||
|
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(oColors.brightRed + "The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||||
|
|
||||||
|
try:
|
||||||
|
return filesInServerRoot
|
||||||
|
except UnboundLocalError:
|
||||||
|
print(oColors.brightRed + "No Serverjar was found." + oColors.standardWhite)
|
85
src/serverjar/serverjar_checker.py
Normal file
85
src/serverjar/serverjar_checker.py
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from urllib.error import HTTPError
|
||||||
|
|
||||||
|
from handlers.handle_sftp import createSFTPConnection, sftp_listFilesInServerRoot
|
||||||
|
from handlers.handle_config import checkConfig
|
||||||
|
from utils.consoleoutput import oColors
|
||||||
|
from serverjar.serverjar_paper import paperCheckForUpdate, papermc_downloader
|
||||||
|
|
||||||
|
|
||||||
|
def checkInstalledServerjar():
|
||||||
|
if not checkConfig().localPluginFolder:
|
||||||
|
sftp = createSFTPConnection()
|
||||||
|
serverRootList = sftp_listFilesInServerRoot(sftp)
|
||||||
|
else:
|
||||||
|
serverRootList = os.path.dirname(checkConfig().pathToPluginFolder)
|
||||||
|
os.chdir('..')
|
||||||
|
serverRootList = os.listdir(serverRootList)
|
||||||
|
installedServerjarFullName = None
|
||||||
|
try:
|
||||||
|
for files in serverRootList:
|
||||||
|
try:
|
||||||
|
if '.jar' in files:
|
||||||
|
installedServerjarFullName = files
|
||||||
|
break
|
||||||
|
except TypeError:
|
||||||
|
continue
|
||||||
|
except TypeError:
|
||||||
|
print(oColors.brightRed + "Serverjar couldn't be found." + oColors.standardWhite)
|
||||||
|
print(oColors.brightRed + "Aborting the process." + oColors.standardWhite)
|
||||||
|
|
||||||
|
if installedServerjarFullName == None:
|
||||||
|
print(oColors.brightRed + "Serverjar couldn't be found." + oColors.standardWhite)
|
||||||
|
print(oColors.brightRed + "Aborting the process." + oColors.standardWhite)
|
||||||
|
input("Press any key + enter to exit...")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
if 'paper' in installedServerjarFullName:
|
||||||
|
paperCheckForUpdate(installedServerjarFullName)
|
||||||
|
|
||||||
|
else:
|
||||||
|
print(oColors.brightRed + f"{installedServerjarFullName} isn't supported.")
|
||||||
|
print(oColors.brightRed + "Aborting the process." + oColors.standardWhite)
|
||||||
|
|
||||||
|
|
||||||
|
def updateServerjar(serverJarBuild='latest'):
|
||||||
|
if serverJarBuild == None:
|
||||||
|
serverJarBuild = 'latest'
|
||||||
|
if not checkConfig().localPluginFolder:
|
||||||
|
sftp = createSFTPConnection()
|
||||||
|
serverRootList = sftp_listFilesInServerRoot(sftp)
|
||||||
|
else:
|
||||||
|
serverRoot = os.path.dirname(checkConfig().pathToPluginFolder)
|
||||||
|
os.chdir('..')
|
||||||
|
serverRootList = os.listdir(serverRoot)
|
||||||
|
installedServerjarFullName = None
|
||||||
|
try:
|
||||||
|
for files in serverRootList:
|
||||||
|
try:
|
||||||
|
if '.jar' in files:
|
||||||
|
installedServerjarFullName = files
|
||||||
|
break
|
||||||
|
except TypeError:
|
||||||
|
continue
|
||||||
|
except TypeError:
|
||||||
|
print(oColors.brightRed + "Serverjar couldn't be found." + oColors.standardWhite)
|
||||||
|
print(oColors.brightRed + "Aborting the process." + oColors.standardWhite)
|
||||||
|
|
||||||
|
if installedServerjarFullName == None:
|
||||||
|
print(oColors.brightRed + "Serverjar couldn't be found." + oColors.standardWhite)
|
||||||
|
print(oColors.brightRed + "Aborting the process." + oColors.standardWhite)
|
||||||
|
input("Press any key + enter to exit...")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
if 'paper' in installedServerjarFullName:
|
||||||
|
print(serverJarBuild)
|
||||||
|
try:
|
||||||
|
papermc_downloader(serverJarBuild, installedServerjarFullName)
|
||||||
|
except HTTPError as err:
|
||||||
|
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
|
||||||
|
|
||||||
|
else:
|
||||||
|
print(oColors.brightRed + f"{installedServerjarFullName} isn't supported.")
|
||||||
|
print(oColors.brightRed + "Aborting the process." + oColors.standardWhite)
|
||||||
|
|
@ -1,32 +1,142 @@
|
|||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import re
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
from utils.consoleoutput import oColors
|
from utils.consoleoutput import oColors
|
||||||
from utils.web_request import doAPIRequest
|
from utils.web_request import doAPIRequest
|
||||||
from handlers.handle_sftp import sftp_upload_file, sftp_cdPluginDir, createSFTPConnection
|
from handlers.handle_sftp import sftp_upload_server_jar, sftp_cdPluginDir, createSFTPConnection
|
||||||
|
from handlers.handle_config import checkConfig
|
||||||
|
from utils.utilities import createTempPluginFolder, deleteTempPluginFolder
|
||||||
|
from plugin.plugin_downloader import calculateFileSize
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# = 1.16.5
|
||||||
def getInstalledPaperMinecraftVersion(localPaperName):
|
def getInstalledPaperMinecraftVersion(localPaperName):
|
||||||
print("test")
|
mcVersionFull = re.search(r'(\d*\.*\d)+', localPaperName)
|
||||||
|
try:
|
||||||
|
mcVersion = mcVersionFull.group()
|
||||||
|
except AttributeError:
|
||||||
|
mcVersion = mcVersionFull
|
||||||
|
return mcVersion
|
||||||
|
|
||||||
|
|
||||||
|
# = 550
|
||||||
def getInstalledPaperVersion(localPaperName):
|
def getInstalledPaperVersion(localPaperName):
|
||||||
print("test")
|
paperBuildFull = re.search(r'([\d]*.jar)', localPaperName)
|
||||||
|
try:
|
||||||
|
paperBuild = paperBuildFull.group()
|
||||||
|
except AttributeError:
|
||||||
|
paperBuild = paperBuildFull
|
||||||
|
paperBuild = paperBuild.replace('.jar', '')
|
||||||
|
return paperBuild
|
||||||
|
|
||||||
|
|
||||||
|
def findVersionGroup(mcVersion):
|
||||||
|
versionGroups = ['1.16', '1.15']
|
||||||
|
versionGroupFound = False
|
||||||
|
for versionGroup in versionGroups:
|
||||||
|
if versionGroupFound == True:
|
||||||
|
break
|
||||||
|
url = f"https://papermc.io/api/v2/projects/paper/version_group/{versionGroup}/builds"
|
||||||
|
papermcdetails = doAPIRequest(url)
|
||||||
|
papermcVersionForMc = papermcdetails["versions"]
|
||||||
|
for versions in papermcVersionForMc:
|
||||||
|
if versions == mcVersion:
|
||||||
|
versionGroupFound = True
|
||||||
|
paperVersionGroup = versionGroup
|
||||||
|
break
|
||||||
|
if versionGroup == mcVersion:
|
||||||
|
versionGroupFound = True
|
||||||
|
paperVersionGroup = versionGroup
|
||||||
|
print(versionGroup)
|
||||||
|
break
|
||||||
|
|
||||||
|
return paperVersionGroup
|
||||||
|
|
||||||
|
|
||||||
|
def findLatestBuild(paperVersionGroup):
|
||||||
|
url = f"https://papermc.io/api/v2/projects/paper/version_group/{paperVersionGroup}/builds"
|
||||||
|
papermcbuilds = doAPIRequest(url)
|
||||||
|
latestPaperBuild = papermcbuilds["builds"][-1]["build"]
|
||||||
|
return latestPaperBuild
|
||||||
|
|
||||||
|
|
||||||
|
def versionBehind(installedPaperBuild, latestPaperBuild):
|
||||||
|
installedPaperBuildint = int(installedPaperBuild)
|
||||||
|
latestPaperBuildint = int(latestPaperBuild)
|
||||||
|
versionsBehind = latestPaperBuildint - installedPaperBuildint
|
||||||
|
return versionsBehind
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def getDownloadFileName(paperMcVersion, paperBuild):
|
||||||
|
url = f"https://papermc.io/api/v2/projects/paper/versions/{paperMcVersion}/builds/{paperBuild}"
|
||||||
|
buildDetails = doAPIRequest(url)
|
||||||
|
downloadName = buildDetails["downloads"]["application"]["name"]
|
||||||
|
return downloadName
|
||||||
|
|
||||||
|
|
||||||
|
def paperCheckForUpdate(installedServerjarFullName):
|
||||||
|
mcVersion = getInstalledPaperMinecraftVersion(installedServerjarFullName)
|
||||||
|
paperInstalledBuild = getInstalledPaperVersion(installedServerjarFullName)
|
||||||
|
versionGroup = findVersionGroup(mcVersion)
|
||||||
|
paperLatestBuild = findLatestBuild(versionGroup)
|
||||||
|
paperVersionBehind = versionBehind(paperInstalledBuild, paperLatestBuild)
|
||||||
|
|
||||||
|
print(f"Paper for {mcVersion}")
|
||||||
|
print("Index | Name | Old V. | New V. | Versions behind ")
|
||||||
|
print(f" [1]".ljust(8), end='')
|
||||||
|
print(f"paper".ljust(24), end='')
|
||||||
|
print(f"{paperInstalledBuild}".ljust(8), end='')
|
||||||
|
print(" ", end='')
|
||||||
|
print(f"{paperLatestBuild}".ljust(8), end='')
|
||||||
|
print(" ", end='')
|
||||||
|
print(f"{paperVersionBehind}".ljust(8))
|
||||||
|
|
||||||
|
|
||||||
# https://papermc.io/api/docs/swagger-ui/index.html?configUrl=/api/openapi/swagger-config#/
|
# https://papermc.io/api/docs/swagger-ui/index.html?configUrl=/api/openapi/swagger-config#/
|
||||||
def papermc_downloader(paperBuild, paperVersionGroup='1.16'):
|
def papermc_downloader(paperBuild='latest', installedServerjarName=None, mcVersion=None):
|
||||||
url = f"https://papermc.io/api/v2/projects/paper/{serverVersion}/{inputPackageVersion}" # v1 is deprecated
|
if checkConfig().localPluginFolder == False:
|
||||||
#https://papermc.io/api/v2/projects/paper/version_group/1.16/builds get all builds for all 1.16 versions
|
downloadPath = createTempPluginFolder()
|
||||||
#https://papermc.io/api/v2/projects/paper/versions/1.16.5/builds/450 gets file name
|
else:
|
||||||
# input serverversion = 1.16.5 inputpackageversion = 450
|
downloadPath = checkConfig().pathToPluginFolder
|
||||||
# regex 1.16 % build url
|
downloadPath = downloadPath.replace(r'\plugins', '')
|
||||||
# search for 450 in version group 1.16
|
|
||||||
# if found get file name from builds/450
|
|
||||||
# build url & download package
|
|
||||||
# https://papermc.io/api/v2/projects/paper/versions/1.16.5/builds/450/downloads/paper-1.16.5-450.jar
|
|
||||||
|
|
||||||
|
if mcVersion == None:
|
||||||
|
mcVersion = '1.16.5'
|
||||||
|
|
||||||
papermcdetails = doAPIRequest(url)
|
if installedServerjarName != None:
|
||||||
errorExists = papermcdetails["error"]
|
mcVersion = getInstalledPaperMinecraftVersion(installedServerjarName)
|
||||||
if errorExists in papermcdetails:
|
|
||||||
print(f"PaperMc version: {inputPackageVersion} couldn't be found")
|
if paperBuild == 'latest':
|
||||||
print("Aborting the download of PaperMc.")
|
versionGroup = findVersionGroup(mcVersion)
|
||||||
input("Press any key + enter to exit...")
|
paperBuild = findLatestBuild(versionGroup)
|
||||||
sys.exit()
|
try:
|
||||||
|
downloadFileName = getDownloadFileName(mcVersion, paperBuild)
|
||||||
|
except KeyError:
|
||||||
|
print(oColors.brightRed + f"This version wasn't found for {mcVersion}" + oColors.standardWhite)
|
||||||
|
print(oColors.brightRed + f"Reverting to latest version for {mcVersion}" + oColors.standardWhite)
|
||||||
|
versionGroup = findVersionGroup(mcVersion)
|
||||||
|
paperBuild = findLatestBuild(versionGroup)
|
||||||
|
downloadFileName = getDownloadFileName(mcVersion, paperBuild)
|
||||||
|
|
||||||
|
downloadPackagePath = f"{downloadPath}\\{downloadFileName}"
|
||||||
|
|
||||||
|
if checkConfig().localPluginFolder == False:
|
||||||
|
downloadPath = createTempPluginFolder()
|
||||||
|
|
||||||
|
url = f"https://papermc.io/api/v2/projects/paper/versions/{mcVersion}/builds/{paperBuild}/downloads/{downloadFileName}"
|
||||||
|
remotefile = urllib.request.urlopen(url)
|
||||||
|
filesize = remotefile.info()['Content-Length']
|
||||||
|
print(f"Starting paper-{paperBuild} download for {mcVersion}...")
|
||||||
|
urllib.request.urlretrieve(url, downloadPackagePath)
|
||||||
|
filesizeData = calculateFileSize(filesize)
|
||||||
|
|
||||||
|
print(f"Downloadsize: {filesizeData} KB")
|
||||||
|
print(f"File downloaded here: {downloadPackagePath}")
|
||||||
|
if not checkConfig().localPluginFolder:
|
||||||
|
sftpSession = createSFTPConnection()
|
||||||
|
sftp_upload_server_jar(sftpSession, downloadPackagePath)
|
||||||
|
deleteTempPluginFolder(downloadPath)
|
||||||
|
@ -59,7 +59,7 @@ def check_requirements():
|
|||||||
|
|
||||||
|
|
||||||
def createTempPluginFolder():
|
def createTempPluginFolder():
|
||||||
tempPluginFolder = ".\\plugins"
|
tempPluginFolder = ".\\TempSFTPUploadFolder"
|
||||||
if not os.path.isdir(tempPluginFolder):
|
if not os.path.isdir(tempPluginFolder):
|
||||||
try:
|
try:
|
||||||
os.mkdir(tempPluginFolder)
|
os.mkdir(tempPluginFolder)
|
||||||
|
Loading…
Reference in New Issue
Block a user