mirror of
https://github.com/Neocky/pluGET.git
synced 2024-04-29 16:12:30 +00:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
afbc3e8029 | ||
![]() |
a08aab7ae4 | ||
![]() |
b31cca5e31 | ||
![]() |
cd4a66002c | ||
![]() |
0d709cfb6f | ||
![]() |
edc300a33d | ||
![]() |
11b4fdcbeb | ||
![]() |
716227eafa | ||
![]() |
6e980a1580 | ||
![]() |
cb0282e676 | ||
![]() |
1dad1c62cd | ||
![]() |
91a5e84028 | ||
![]() |
60a41015e6 | ||
![]() |
706b8049c3 | ||
![]() |
927767b0aa |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -130,3 +130,6 @@ dmypy.json
|
||||
|
||||
# VSCode Settings
|
||||
.vscode
|
||||
|
||||
# PyCharm Settings
|
||||
.idea
|
||||
|
24
README.md
24
README.md
@@ -19,7 +19,7 @@
|
||||
|
||||
|
||||
# pluGET
|
||||
#### A powerfull package manager which updates [Plugins](https://www.spigotmc.org/resources/) and Server Software for minecraft servers.
|
||||
#### A powerful package manager which updates [Plugins](https://www.spigotmc.org/resources/) and Server Software for minecraft servers.
|
||||
|
||||
<img src="https://www.bildhost.com/images/2021/03/23/pluGET.gif" alt="pluGET.gif" border="0" />
|
||||
|
||||
@@ -47,11 +47,11 @@
|
||||
## About
|
||||
This is a package manager for minecraft [Spigot](https://www.spigotmc.org/) servers and its forks (e.g. [PaperMC](https://papermc.io/)).
|
||||
This is a standalone program written in python.
|
||||
The program works with a locally installed server or with a remote host through SFTP, when configured in the config.
|
||||
The program works with a locally installed server or with a remote host through SFTP/FTP, when configured in the config.
|
||||
It uses the [Spiget](https://spiget.org/) API to download and compare plugin versions and can download the latest version of plugins from the [Spigot](https://www.spigotmc.org/) site.
|
||||
It can also compare and download the latest update of specifif server software (e.g. [PaperMC](https://papermc.io/)).
|
||||
It can also compare and download the latest update of specific server software (e.g. [PaperMC](https://papermc.io/)).
|
||||
|
||||
Plugin management was the hard part of mangaging a minecraft server. The time it took to check the [Spigot ressource](https://www.spigotmc.org/resources/) page for updates for the installed plugins and updating all plugins manually which have available updates was too long and daunting.
|
||||
Plugin management was the hard part of managing a minecraft server. The time it took to check the [Spigot ressource](https://www.spigotmc.org/resources/) page for updates for the installed plugins and updating all plugins manually which have available updates was too long and daunting.
|
||||
So I built pluGET to automate and ease the plugin handling of a minecraft server and to turn the most time consuming part of managing a minecraft server to an easy one.
|
||||
|
||||
This program is suited for minecraft server owners who want to save time and stay on top of their plugin versions.
|
||||
@@ -63,15 +63,15 @@ If you still have questions [here](https://github.com/Neocky/pluGET#need-help) i
|
||||
|
||||
So what can it do exactly?
|
||||
pluGET can:
|
||||
- work locally or through sftp
|
||||
- work locally or through SFTP/FTP
|
||||
- manage plugins:
|
||||
- download the latest version of a plugin
|
||||
- update every installed/one specific plugin
|
||||
- check for an update of every installed/one specific plugin
|
||||
- remove a plugin from the plugin folder
|
||||
- manager server software:
|
||||
- manage server software:
|
||||
- download a specific server software version
|
||||
- check instlalled server software for update
|
||||
- check installed server software for update
|
||||
- update installed server software to a specific version
|
||||
- supported server software: [PaperMc](https://papermc.io/)
|
||||
|
||||
@@ -88,7 +88,7 @@ If you feel like showing your love and/or appreciation for this project then how
|
||||
|
||||
|
||||
## Need help?
|
||||
[<img src="https://i.imgur.com/D5vyVzC.png" alt="Discord" width="272"/>](https://discord.gg/475Uf4NBPF)
|
||||
[<img src="https://i.ibb.co/CMKbT0L/rsz-1rsz-discord.png" alt="Discord" width="272"/>](https://discord.gg/475Uf4NBPF)
|
||||
|
||||
|
||||
## Installation
|
||||
@@ -97,14 +97,14 @@ Python needs to be installed on your machine.
|
||||
Get it [here](https://www.python.org/downloads/).
|
||||
### Dependencies
|
||||
Install the needed packages for this project.
|
||||
Execute this command in the ```\plugGET``` folder:
|
||||
Execute this command in the `\plugGET` folder:
|
||||
```python
|
||||
py -m pip install -r requirements.txt
|
||||
```
|
||||
|
||||
|
||||
### Edit the Config
|
||||
When run the first time, the `config.ini` file will be created in the root package folder and the program will close.
|
||||
When run the first time, the `config.ini` file will be created in the `\src` folder and the program will close.
|
||||
Edit the config to your needs and relaunch pluGET.
|
||||
**Now you are good to go!**
|
||||
|
||||
@@ -112,6 +112,10 @@ Edit the config to your needs and relaunch pluGET.
|
||||
### Windows:
|
||||
Execute the `launcher.bat` in the `\pluGET` folder.
|
||||
This will launch pluGET correctly.
|
||||
Sometimes the security warning `Windows protected your PC` comes when launching the `launcher.bat` file.
|
||||
This is a normal behaviour from the windows defender because this is a unknown `.bat` file.
|
||||
To run the `launcher.bat` anyway, click `More Info` and then `Run anyway` when the message pops up.
|
||||
|
||||
### Linux:
|
||||
Use `cd` to change into the `/pluGET` directory and change the permission of the `launcher.sh` to make it executeable:
|
||||
```
|
||||
|
@@ -11,16 +11,17 @@ class configurationValues:
|
||||
config = configparser.ConfigParser()
|
||||
config.sections()
|
||||
config.read("config.ini")
|
||||
localPluginFolder = config['General']['LocalPluginFolder']
|
||||
self.pathToPluginFolder = Path(config['General']['PathToPluginFolder'])
|
||||
seperateDownloadPath = config['General']['SeperateDownloadPath']
|
||||
self.pathToSeperateDownloadPath = Path(config['General']['PathToSeperateDownloadPath'])
|
||||
localPluginFolder = config['General']['UseLocalPluginFolder']
|
||||
self.pathToPluginFolder = Path(config['Local - This Machine']['PathToPluginFolder'])
|
||||
seperateDownloadPath = config['Local - This Machine']['SeperateDownloadPath']
|
||||
self.pathToSeperateDownloadPath = Path(config['Local - This Machine']['PathToSeperateDownloadPath'])
|
||||
|
||||
self.sftp_server = config['SFTP - Remote Server']['Server']
|
||||
self.sftp_user = config['SFTP - Remote Server']['Username']
|
||||
self.sftp_password = config['SFTP - Remote Server']['Password']
|
||||
sftp_port = config['SFTP - Remote Server']['Port']
|
||||
sftp_port = config['SFTP - Remote Server']['SFTPPort']
|
||||
self.sftp_folderPath = config['SFTP - Remote Server']['PluginFolderOnServer']
|
||||
sftp_useSftp = config['SFTP - Remote Server']['USE_SFTP']
|
||||
sftp_seperateDownloadPath = config['SFTP - Remote Server']['SeperateDownloadPath']
|
||||
self.sftp_pathToSeperateDownloadPath = config['SFTP - Remote Server']['PathToSeperateDownloadPath']
|
||||
|
||||
@@ -40,6 +41,11 @@ class configurationValues:
|
||||
else:
|
||||
self.sftp_seperateDownloadPath = False
|
||||
|
||||
if sftp_useSftp == 'True':
|
||||
self.sftp_useSftp = True
|
||||
else:
|
||||
self.sftp_useSftp = False
|
||||
|
||||
|
||||
def checkConfig():
|
||||
configAvailable = os.path.isfile("config.ini")
|
||||
@@ -53,23 +59,28 @@ def checkConfig():
|
||||
def createConfig():
|
||||
config = configparser.ConfigParser(allow_no_value=True)
|
||||
config['General'] = {}
|
||||
config['General'][';'] = 'If a local plugin folder exists (True/False): (If False SFTP will be used)'
|
||||
config['General']['LocalPluginFolder'] = 'True'
|
||||
config['General']['PathToPluginFolder'] = 'C:/Users/USER/Desktop/plugins'
|
||||
config['General'][';_'] = 'If you want a different folder to store the updated plugins change to (True/False) and the path below'
|
||||
config['General']['SeperateDownloadPath'] = 'False'
|
||||
config['General']['PathToSeperateDownloadPath'] = 'C:/Users/USER/Desktop/plugins'
|
||||
config['General'][';'] = 'If a local plugin folder exists (True/False) (If False SFTP/FTP will be used):'
|
||||
config['General']['UseLocalPluginFolder'] = 'True'
|
||||
|
||||
config['Local - This Machine'] = {}
|
||||
config['Local - This Machine']['PathToPluginFolder'] = 'C:/Users/USER/Desktop/plugins'
|
||||
config['Local - This Machine'][';'] = 'For a different folder to store the updated plugins change to (True/False) and the path below'
|
||||
config['Local - This Machine']['SeperateDownloadPath'] = 'False'
|
||||
config['Local - This Machine']['PathToSeperateDownloadPath'] = 'C:/Users/USER/Desktop/plugins'
|
||||
|
||||
config['SFTP - Remote Server'] = {}
|
||||
config['SFTP - Remote Server']['Server'] = '0.0.0.0'
|
||||
config['SFTP - Remote Server']['Username'] = 'user'
|
||||
config['SFTP - Remote Server']['Password'] = 'password'
|
||||
config['SFTP - Remote Server'][';'] = 'Normally you won*t need to change anything below this line'
|
||||
config['SFTP - Remote Server']['Port'] = '22'
|
||||
config['SFTP - Remote Server']['PluginFolderOnServer'] = '.\\plugins'
|
||||
config['SFTP - Remote Server'][';_'] = 'If you want a different folder to store the updated plugins change to (True/False) and the path below'
|
||||
config['SFTP - Remote Server'][';'] = 'If a different Port for SFTP needs to be used (Works only for SFTP)'
|
||||
config['SFTP - Remote Server']['SFTPPort'] = '22'
|
||||
config['SFTP - Remote Server'][';_'] = 'Change the path below if the plugin folder path is different on the SFTP/FTP server (Change only if you know what you are doing)'
|
||||
config['SFTP - Remote Server']['PluginFolderOnServer'] = './plugins'
|
||||
config['SFTP - Remote Server'][';__'] = 'If you want to use FTP instead of SFTP change to (False) else use (True)'
|
||||
config['SFTP - Remote Server']['USE_SFTP'] = 'True'
|
||||
config['SFTP - Remote Server'][';___'] = 'For a different folder to store the updated plugins (Only with the update command!) change to (True/False) and the path below'
|
||||
config['SFTP - Remote Server']['SeperateDownloadPath'] = 'False'
|
||||
config['SFTP - Remote Server']['PathToSeperateDownloadPath'] = '.\\plugins'
|
||||
config['SFTP - Remote Server']['PathToSeperateDownloadPath'] = './plugins'
|
||||
|
||||
|
||||
with open('config.ini', 'w') as configfile:
|
||||
|
95
src/handlers/handle_ftp.py
Normal file
95
src/handlers/handle_ftp.py
Normal file
@@ -0,0 +1,95 @@
|
||||
import os
|
||||
import sys
|
||||
import ftplib
|
||||
|
||||
from utils.consoleoutput import oColors
|
||||
from handlers.handle_config import configurationValues
|
||||
|
||||
|
||||
def createFTPConnection():
|
||||
configValues = configurationValues()
|
||||
ftp = ftplib.FTP(configValues.sftp_server, user=configValues.sftp_user, \
|
||||
passwd=configValues.sftp_password)
|
||||
try:
|
||||
return ftp
|
||||
except UnboundLocalError:
|
||||
print(oColors.brightRed + "[FTP]: Check your config.ini!" + oColors.standardWhite)
|
||||
print(oColors.brightRed + "Exiting program..." + oColors.standardWhite)
|
||||
sys.exit()
|
||||
|
||||
|
||||
def ftp_showPlugins(ftp):
|
||||
configValues = configurationValues()
|
||||
ftp.cwd(configValues.sftp_folderPath)
|
||||
for attr in ftp.dir():
|
||||
print(attr.filename, attr)
|
||||
|
||||
|
||||
def ftp_upload_file(ftp, itemPath):
|
||||
configValues = configurationValues()
|
||||
try:
|
||||
ftp.cwd(configValues.sftp_folderPath)
|
||||
itemPath = os.path.relpath(itemPath, 'TempSFTPFolder/')
|
||||
itemPath = str(itemPath)
|
||||
currentDirectory = os.getcwd()
|
||||
os.chdir('TempSFTPFolder')
|
||||
with open (itemPath, 'rb') as plugin_file:
|
||||
ftp.storbinary('STOR '+ str(itemPath), plugin_file)
|
||||
except FileNotFoundError:
|
||||
print(oColors.brightRed + "[FTP]: The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||
print(oColors.brightRed + "[FTP]: Aborting uploading." + oColors.standardWhite)
|
||||
os.chdir(currentDirectory)
|
||||
ftp.close()
|
||||
|
||||
|
||||
def ftp_upload_server_jar(ftp, itemPath):
|
||||
try:
|
||||
print(f"itempath: {itemPath}")
|
||||
ftp.cwd('.')
|
||||
itemPath = os.path.relpath(itemPath, 'TempSFTPFolder/')
|
||||
itemPath = str(itemPath)
|
||||
currentDirectory = os.getcwd()
|
||||
os.chdir('TempSFTPFolder')
|
||||
with open (itemPath, 'rb') as server_jar:
|
||||
ftp.storbinary('STOR '+ str(itemPath), server_jar)
|
||||
except FileNotFoundError:
|
||||
print(oColors.brightRed + "[FTP]: The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||
print(oColors.brightRed + "[FTP]: Aborting uploading." + oColors.standardWhite)
|
||||
os.chdir(currentDirectory)
|
||||
ftp.close()
|
||||
|
||||
|
||||
def ftp_listAll(ftp):
|
||||
configValues = configurationValues()
|
||||
try:
|
||||
ftp.cwd(configValues.sftp_folderPath)
|
||||
installedPlugins = ftp.nlst()
|
||||
except FileNotFoundError:
|
||||
print(oColors.brightRed + "[FTP]: The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||
|
||||
try:
|
||||
return installedPlugins
|
||||
except UnboundLocalError:
|
||||
print(oColors.brightRed + "[FTP]: No plugins were found." + oColors.standardWhite)
|
||||
|
||||
|
||||
def ftp_listFilesInServerRoot(ftp):
|
||||
try:
|
||||
ftp.cwd('.')
|
||||
filesInServerRoot = ftp.nlst()
|
||||
except FileNotFoundError:
|
||||
print(oColors.brightRed + "[FTP]: The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||
|
||||
try:
|
||||
return filesInServerRoot
|
||||
except UnboundLocalError:
|
||||
print(oColors.brightRed + "[FTP]: No Serverjar was found." + oColors.standardWhite)
|
||||
|
||||
|
||||
def ftp_downloadFile(ftp, downloadPath, fileToDownload):
|
||||
configValues = configurationValues()
|
||||
ftp.cwd(configValues.sftp_folderPath)
|
||||
filedata = open(downloadPath,'wb')
|
||||
ftp.retrbinary('RETR '+fileToDownload, filedata.write)
|
||||
filedata.close()
|
||||
ftp.quit()
|
@@ -82,18 +82,24 @@ def handleInput(inputCommand, inputSelectedObject, inputParams):
|
||||
break
|
||||
else:
|
||||
print(oColors.brightRed + "Error: Command not found. Please try again. :(" + oColors.standardWhite)
|
||||
print(oColors.brightRed + "Use: '" + oColors.standardWhite +"help command" + oColors.brightRed +"' to get all available commands" + oColors.standardWhite)
|
||||
getInput()
|
||||
getInput()
|
||||
|
||||
|
||||
def getInput():
|
||||
inputCommand = None
|
||||
while True:
|
||||
try:
|
||||
inputCommand, inputSelectedObject, *inputParams = input("pluGET >> ").split()
|
||||
break
|
||||
except ValueError:
|
||||
print(oColors.brightRed + "Wrong input! Use: > 'command' 'selectedObject' [optionalParams]" + oColors.standardWhite)
|
||||
print(oColors.brightRed + "Use: '" + oColors.standardWhite +"help command" + oColors.brightRed +"' to get all available commands" + oColors.standardWhite)
|
||||
|
||||
if inputCommand == None:
|
||||
continue
|
||||
else:
|
||||
print(oColors.brightRed + "Wrong input! Use: > 'command' 'selectedObject' [optionalParams]" + oColors.standardWhite)
|
||||
print(oColors.brightRed + "Use: '" + oColors.standardWhite +"help command" + oColors.brightRed +"' to get all available commands" + oColors.standardWhite)
|
||||
except KeyboardInterrupt:
|
||||
sys.exit()
|
||||
inputParams = inputParams[0] if inputParams else None
|
||||
handleInput(inputCommand, inputSelectedObject, inputParams)
|
||||
|
@@ -1,17 +1,19 @@
|
||||
import sys
|
||||
import os
|
||||
import pysftp
|
||||
import paramiko
|
||||
|
||||
from utils.consoleoutput import oColors
|
||||
from handlers.handle_config import checkConfig
|
||||
from handlers.handle_config import configurationValues
|
||||
|
||||
|
||||
def createSFTPConnection():
|
||||
configValues = configurationValues()
|
||||
cnopts = pysftp.CnOpts()
|
||||
cnopts.hostkeys = None # TODO fix this
|
||||
try:
|
||||
sftp = pysftp.Connection(checkConfig().sftp_server, username=checkConfig().sftp_user, \
|
||||
password=checkConfig().sftp_password, port=checkConfig().sftp_port, cnopts=cnopts)
|
||||
sftp = pysftp.Connection(configValues.sftp_server, username=configValues.sftp_user, \
|
||||
password=configValues.sftp_password, port=configValues.sftp_port, cnopts=cnopts)
|
||||
except paramiko.ssh_exception.AuthenticationException:
|
||||
print(oColors.brightRed + "[SFTP]: Wrong Username/Password" + oColors.standardWhite)
|
||||
except paramiko.ssh_exception.SSHException:
|
||||
@@ -30,18 +32,14 @@ def sftp_showPlugins(sftp):
|
||||
print(attr.filename, attr)
|
||||
|
||||
|
||||
def sftp_cdPluginDir(sftp):
|
||||
sftp.cd('plugins')
|
||||
|
||||
|
||||
def sftp_upload_file(sftp, itemPath):
|
||||
try:
|
||||
sftp.chdir('plugins')
|
||||
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)
|
||||
print(oColors.brightRed + "[SFTP]: The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||
print(oColors.brightRed + "[SFTP]: Aborting uploading." + oColors.standardWhite)
|
||||
sftp.close()
|
||||
|
||||
|
||||
@@ -49,10 +47,9 @@ 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)
|
||||
print(oColors.brightRed + "[SFTP]: The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||
print(oColors.brightRed + "[SFTP]: Aborting uploading." + oColors.standardWhite)
|
||||
sftp.close()
|
||||
|
||||
|
||||
@@ -60,25 +57,33 @@ def sftp_listAll(sftp):
|
||||
try:
|
||||
sftp.chdir('plugins')
|
||||
installedPlugins = sftp.listdir()
|
||||
|
||||
except FileNotFoundError:
|
||||
print(oColors.brightRed + "The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||
print(oColors.brightRed + "[SFTP]: The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||
|
||||
try:
|
||||
return installedPlugins
|
||||
except UnboundLocalError:
|
||||
print(oColors.brightRed + "No plugins were found." + oColors.standardWhite)
|
||||
print(oColors.brightRed + "[SFTP]: 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)
|
||||
print(oColors.brightRed + "[SFTP]: 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)
|
||||
print(oColors.brightRed + "[SFTP]: No Serverjar was found." + oColors.standardWhite)
|
||||
|
||||
|
||||
def sftp_downloadFile(sftp, downloadPath, fileToDownload):
|
||||
configValues = configurationValues()
|
||||
sftp.cwd(configValues.sftp_folderPath)
|
||||
currentDirectory = os.getcwd()
|
||||
os.chdir('TempSFTPFolder')
|
||||
sftp.get(fileToDownload)
|
||||
sftp.close()
|
||||
os.chdir(currentDirectory)
|
||||
|
@@ -7,7 +7,8 @@ from utils.consoleoutput import oColors
|
||||
from utils.web_request import doAPIRequest
|
||||
from utils.utilities import createTempPluginFolder, deleteTempPluginFolder, calculateFileSizeKb, calculateFileSizeMb
|
||||
from handlers.handle_config import configurationValues
|
||||
from handlers.handle_sftp import sftp_upload_file, sftp_cdPluginDir, createSFTPConnection
|
||||
from handlers.handle_sftp import sftp_upload_file, createSFTPConnection
|
||||
from handlers.handle_ftp import ftp_upload_file, createFTPConnection
|
||||
|
||||
|
||||
def handleRegexPackageName(packageNameFull):
|
||||
@@ -98,6 +99,10 @@ def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'):
|
||||
url = f"https://api.spiget.org/v2/resources/{ressourceId}/download"
|
||||
#url = f"https://api.spiget.org/v2/resources/{ressourceId}/versions/latest/download" #throws 403 forbidden error...cloudflare :(
|
||||
|
||||
urrlib_opener = urllib.request.build_opener()
|
||||
urrlib_opener.addheaders = [('User-agent', 'pluGET/1.0')]
|
||||
urllib.request.install_opener(urrlib_opener)
|
||||
|
||||
remotefile = urllib.request.urlopen(url)
|
||||
filesize = remotefile.info()['Content-Length']
|
||||
urllib.request.urlretrieve(url, downloadPath)
|
||||
@@ -110,8 +115,12 @@ def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'):
|
||||
filesizeData = calculateFileSizeKb(filesize)
|
||||
print("Downloaded " + (str(filesizeData)).rjust(9) + f" KB here {downloadPath}")
|
||||
if not configValues.localPluginFolder:
|
||||
sftpSession = createSFTPConnection()
|
||||
sftp_upload_file(sftpSession, downloadPath)
|
||||
if configValues.sftp_useSftp:
|
||||
sftpSession = createSFTPConnection()
|
||||
sftp_upload_file(sftpSession, downloadPath)
|
||||
else:
|
||||
ftpSession = createFTPConnection()
|
||||
ftp_upload_file(ftpSession, downloadPath)
|
||||
|
||||
|
||||
def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'):
|
||||
@@ -125,17 +134,14 @@ def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'):
|
||||
versionId = getVersionID(ressourceId, inputPackageVersion)
|
||||
packageVersion = getVersionName(ressourceId, versionId)
|
||||
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
|
||||
#if not configValues.localPluginFolder:
|
||||
#downloadPackagePath = f"{downloadPath}/{packageDownloadName}"
|
||||
#else:
|
||||
downloadPackagePath = Path(f"{downloadPath}/{packageDownloadName}")
|
||||
if configValues.localPluginFolder:
|
||||
if inputPackageVersion is None or inputPackageVersion == 'latest':
|
||||
downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath)
|
||||
else:
|
||||
downloadSpecificVersion(ressourceId, downloadPackagePath, versionId)
|
||||
if inputPackageVersion is None or inputPackageVersion == 'latest':
|
||||
downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath)
|
||||
else:
|
||||
downloadSpecificVersion(ressourceId, downloadPackagePath, versionId)
|
||||
|
||||
if not configValues.localPluginFolder:
|
||||
if inputPackageVersion is None or inputPackageVersion == 'latest':
|
||||
downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath)
|
||||
deleteTempPluginFolder(downloadPath)
|
||||
else:
|
||||
downloadSpecificVersion(ressourceId, downloadPackagePath, versionId)
|
||||
deleteTempPluginFolder(downloadPath)
|
||||
deleteTempPluginFolder(downloadPath)
|
||||
|
@@ -5,6 +5,7 @@ from pathlib import Path
|
||||
from utils.consoleoutput import oColors
|
||||
from handlers.handle_config import configurationValues
|
||||
from handlers.handle_sftp import createSFTPConnection, sftp_listAll
|
||||
from handlers.handle_ftp import createFTPConnection, ftp_listAll
|
||||
from plugin.plugin_updatechecker import getFileName, getFileVersion, getInstalledPlugin, createPluginList
|
||||
|
||||
|
||||
@@ -12,8 +13,12 @@ def removePlugin(pluginToRemove):
|
||||
configValues = configurationValues()
|
||||
createPluginList()
|
||||
if not configValues.localPluginFolder:
|
||||
sftp = createSFTPConnection()
|
||||
pluginList = sftp_listAll(sftp)
|
||||
if not configValues.sftp_useSftp:
|
||||
ftp = createFTPConnection()
|
||||
pluginList = ftp_listAll(ftp)
|
||||
else:
|
||||
sftp = createSFTPConnection()
|
||||
pluginList = sftp_listAll(sftp)
|
||||
else:
|
||||
pluginList = os.listdir(configValues.pathToPluginFolder)
|
||||
i = 0
|
||||
@@ -32,8 +37,12 @@ def removePlugin(pluginToRemove):
|
||||
if not configValues.localPluginFolder:
|
||||
pluginPath = configValues.sftp_folderPath
|
||||
pluginPath = f"{pluginPath}/{plugin}"
|
||||
sftp = createSFTPConnection()
|
||||
sftp.remove(pluginPath)
|
||||
if not configValues.sftp_useSftp:
|
||||
ftp = createFTPConnection()
|
||||
ftp.delete(pluginPath)
|
||||
else:
|
||||
sftp = createSFTPConnection()
|
||||
sftp.remove(pluginPath)
|
||||
print(f"Removed: {fileName}")
|
||||
i += 1
|
||||
break
|
||||
|
@@ -9,8 +9,10 @@ from rich.progress import track
|
||||
from utils.consoleoutput import oColors
|
||||
from utils.web_request import doAPIRequest
|
||||
from handlers.handle_config import configurationValues
|
||||
from handlers.handle_sftp import createSFTPConnection, sftp_listAll
|
||||
from handlers.handle_sftp import createSFTPConnection, sftp_listAll, sftp_downloadFile
|
||||
from handlers.handle_ftp import createFTPConnection, ftp_listAll, ftp_downloadFile
|
||||
from plugin.plugin_downloader import getSpecificPackage
|
||||
from utils.utilities import createTempPluginFolder, deleteTempPluginFolder
|
||||
|
||||
|
||||
def createPluginList():
|
||||
@@ -44,7 +46,7 @@ def getFileVersion(pluginName):
|
||||
if pluginVersionString.endswith('.'):
|
||||
pluginVersionString = ''
|
||||
if pluginVersionString == '':
|
||||
pluginVersionString = eggCrackingJar(pluginNameFull)
|
||||
pluginVersionString = eggCrackingJar(pluginNameFull, 'version')
|
||||
return pluginVersionString
|
||||
|
||||
|
||||
@@ -63,35 +65,63 @@ def compareVersions(plugin_latest_version, pluginVersion):
|
||||
return plugin_is_outdated
|
||||
|
||||
|
||||
def eggCrackingJar(localJarFileName):
|
||||
def eggCrackingJar(localJarFileName, searchMode):
|
||||
configValues = configurationValues()
|
||||
if not configValues.localPluginFolder:
|
||||
pluginPath = configValues.sftp_folderPath
|
||||
if configValues.sftp_useSftp:
|
||||
tempPluginFolderPath = createTempPluginFolder()
|
||||
sftp = createSFTPConnection()
|
||||
pathToPluginJar = Path(f"{tempPluginFolderPath}/{localJarFileName}")
|
||||
sftp_downloadFile(sftp, pathToPluginJar, localJarFileName)
|
||||
else:
|
||||
tempPluginFolderPath = createTempPluginFolder()
|
||||
ftp = createFTPConnection()
|
||||
pathToPluginJar = Path(f"{tempPluginFolderPath}/{localJarFileName}")
|
||||
ftp_downloadFile(ftp, pathToPluginJar, localJarFileName)
|
||||
else:
|
||||
pluginPath = configValues.pathToPluginFolder
|
||||
pathToPluginJar = Path(f"{pluginPath}/{localJarFileName}")
|
||||
pathToPluginJar = Path(f"{pluginPath}/{localJarFileName}")
|
||||
pluginVersion = ''
|
||||
pluginName = ''
|
||||
with ZipFile(pathToPluginJar, 'r') as pluginJar:
|
||||
try:
|
||||
with io.TextIOWrapper(pluginJar.open('plugin.yml', 'r'), encoding="utf-8") as pluginYml:
|
||||
pluginYmlContentLine = pluginYml.readlines()
|
||||
for line in pluginYmlContentLine:
|
||||
if "version: " in line:
|
||||
pluginVersion = line.replace('version: ', '')
|
||||
pluginVersion = pluginVersion.replace('\n', '')
|
||||
break
|
||||
if searchMode == 'version':
|
||||
if re.match(r'^version: ', line):
|
||||
pluginVersion = line.replace('version: ', '')
|
||||
pluginVersion = pluginVersion.replace('\n', '')
|
||||
pluginVersion = pluginVersion.replace("'", '')
|
||||
pluginVersion = pluginVersion.replace('"', '')
|
||||
elif searchMode == 'name':
|
||||
if re.match(r'^name: ', line):
|
||||
pluginName = line.replace('name: ', '')
|
||||
pluginName = pluginName.replace('\n', '')
|
||||
pluginName = pluginName.replace("'", '')
|
||||
pluginName = pluginName.replace('"', '')
|
||||
|
||||
except FileNotFoundError:
|
||||
pluginVersion = ''
|
||||
return pluginVersion
|
||||
pluginName = ''
|
||||
if not configValues.localPluginFolder:
|
||||
deleteTempPluginFolder(tempPluginFolderPath)
|
||||
if searchMode == 'version':
|
||||
return pluginVersion
|
||||
if searchMode == 'name':
|
||||
return pluginName
|
||||
|
||||
|
||||
def checkInstalledPackage(inputSelectedObject="all"):
|
||||
configValues = configurationValues()
|
||||
createPluginList()
|
||||
if not configValues.localPluginFolder:
|
||||
sftp = createSFTPConnection()
|
||||
pluginList = sftp_listAll(sftp)
|
||||
if configValues.sftp_useSftp:
|
||||
connection = createSFTPConnection()
|
||||
pluginList = sftp_listAll(connection)
|
||||
else:
|
||||
connection = createFTPConnection()
|
||||
pluginList = ftp_listAll(connection)
|
||||
else:
|
||||
pluginList = os.listdir(configValues.pathToPluginFolder)
|
||||
i = 0
|
||||
@@ -105,9 +135,8 @@ def checkInstalledPackage(inputSelectedObject="all"):
|
||||
try:
|
||||
fileName = getFileName(plugin)
|
||||
fileVersion = getFileVersion(plugin)
|
||||
pluginId = getInstalledPlugin(fileName, fileVersion)
|
||||
pluginId = getInstalledPlugin(fileName, fileVersion, plugin)
|
||||
except TypeError:
|
||||
i += 1
|
||||
continue
|
||||
pluginIdStr = str(pluginId)
|
||||
if fileVersion == '':
|
||||
@@ -164,8 +193,12 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
||||
configValues = configurationValues()
|
||||
createPluginList()
|
||||
if not configValues.localPluginFolder:
|
||||
sftp = createSFTPConnection()
|
||||
pluginList = sftp_listAll(sftp)
|
||||
if configValues.sftp_useSftp:
|
||||
connection = createSFTPConnection()
|
||||
pluginList = sftp_listAll(connection)
|
||||
else:
|
||||
connection = createFTPConnection()
|
||||
pluginList = ftp_listAll(connection)
|
||||
else:
|
||||
pluginList = os.listdir(configValues.pathToPluginFolder)
|
||||
i = 0
|
||||
@@ -180,13 +213,11 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
||||
try:
|
||||
fileName = getFileName(plugin)
|
||||
fileVersion = getFileVersion(plugin)
|
||||
pluginId = getInstalledPlugin(fileName, fileVersion)
|
||||
pluginId = getInstalledPlugin(fileName, fileVersion, plugin)
|
||||
latestVersion = getLatestPluginVersion(pluginId)
|
||||
except TypeError:
|
||||
i += 1
|
||||
continue
|
||||
except ValueError:
|
||||
i += 1
|
||||
continue
|
||||
pluginIdStr = str(pluginId)
|
||||
if pluginId == None or pluginId == '':
|
||||
@@ -198,7 +229,6 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
||||
print(" ", end='')
|
||||
print(f"{fileName}".ljust(33), end='')
|
||||
print(f"{fileVersion}".ljust(13), end='')
|
||||
#print(" ", end='')
|
||||
print(f"{latestVersion}".ljust(13))
|
||||
|
||||
if not configValues.localPluginFolder:
|
||||
@@ -248,27 +278,45 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
||||
print(" ", end='')
|
||||
print(f"{fileName}".ljust(33), end='')
|
||||
print(f"{fileVersion}".ljust(13), end='')
|
||||
#print(" ", end='')
|
||||
print(f"{latestVersion}".ljust(13))
|
||||
|
||||
if not configValues.localPluginFolder:
|
||||
if configValues.sftp_seperateDownloadPath is True:
|
||||
pluginPath = configValues.sftp_pathToSeperateDownloadPath
|
||||
if configValues.sftp_useSftp:
|
||||
if configValues.sftp_seperateDownloadPath is True:
|
||||
pluginPath = configValues.sftp_pathToSeperateDownloadPath
|
||||
else:
|
||||
pluginPath = configValues.sftp_folderPath
|
||||
pluginPath = f"{pluginPath}/{plugin}"
|
||||
sftp = createSFTPConnection()
|
||||
indexNumberUpdated += 1
|
||||
pluginsUpdated += 1
|
||||
try:
|
||||
getSpecificPackage(pluginId, configValues.sftp_folderPath)
|
||||
if configValues.sftp_seperateDownloadPath is False:
|
||||
sftp.remove(pluginPath)
|
||||
except HTTPError as err:
|
||||
print(oColors.brightRed + f"HTTPError: {err.code} - {err.reason}" + oColors.standardWhite)
|
||||
pluginsUpdated -= 1
|
||||
except FileNotFoundError:
|
||||
print(oColors.brightRed + f"FileNotFoundError: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
||||
else:
|
||||
pluginPath = configValues.sftp_folderPath
|
||||
pluginPath = f"{pluginPath}/{plugin}"
|
||||
sftp = createSFTPConnection()
|
||||
indexNumberUpdated += 1
|
||||
pluginsUpdated += 1
|
||||
try:
|
||||
getSpecificPackage(pluginId, configValues.sftp_folderPath)
|
||||
if configValues.sftp_seperateDownloadPath is False:
|
||||
sftp.remove(pluginPath)
|
||||
except HTTPError as err:
|
||||
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
|
||||
pluginsUpdated -= 1
|
||||
except FileNotFoundError:
|
||||
print(oColors.brightRed + f"Error: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
||||
if configValues.sftp_seperateDownloadPath is True:
|
||||
pluginPath = configValues.sftp_pathToSeperateDownloadPath
|
||||
else:
|
||||
pluginPath = configValues.sftp_folderPath
|
||||
pluginPath = f"{pluginPath}/{plugin}"
|
||||
ftp = createFTPConnection()
|
||||
indexNumberUpdated += 1
|
||||
pluginsUpdated += 1
|
||||
try:
|
||||
getSpecificPackage(pluginId, configValues.sftp_folderPath)
|
||||
if configValues.sftp_seperateDownloadPath is False:
|
||||
ftp.delete(pluginPath)
|
||||
except HTTPError as err:
|
||||
print(oColors.brightRed + f"HTTPError: {err.code} - {err.reason}" + oColors.standardWhite)
|
||||
pluginsUpdated -= 1
|
||||
except FileNotFoundError:
|
||||
print(oColors.brightRed + f"FileNotFoundError: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
||||
|
||||
else:
|
||||
if configValues.seperateDownloadPath is True:
|
||||
@@ -283,12 +331,12 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
||||
if configValues.seperateDownloadPath is False:
|
||||
os.remove(pluginPath)
|
||||
except HTTPError as err:
|
||||
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
|
||||
print(oColors.brightRed + f"HTTPError: {err.code} - {err.reason}" + oColors.standardWhite)
|
||||
pluginsUpdated -= 1
|
||||
except FileNotFoundError:
|
||||
print(oColors.brightRed + f"Error: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
||||
print(oColors.brightRed + f"FileNotFoundError: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
||||
|
||||
i = i + 1
|
||||
i += 1
|
||||
except TypeError:
|
||||
print(oColors.brightRed + "Error occured: Aborted updating for plugins." + oColors.standardWhite)
|
||||
print(oColors.brightYellow + f"Plugins updated: [{pluginsUpdated}/{i}]" + oColors.standardWhite)
|
||||
@@ -296,27 +344,40 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
||||
print(oColors.brightGreen + "All found plugins are on the latest version!" + oColors.standardWhite)
|
||||
|
||||
|
||||
def getInstalledPlugin(localFileName, localFileVersion):
|
||||
def getInstalledPlugin(localFileName, localFileVersion, localPluginFullName):
|
||||
url = "https://api.spiget.org/v2/search/resources/" + localFileName + "?field=name&sort=-downloads"
|
||||
packageName = doAPIRequest(url)
|
||||
plugin_match_found = False
|
||||
pluginID = None
|
||||
for ressource in packageName:
|
||||
localFileVersionNew = localFileVersion
|
||||
i = 0
|
||||
for i in range(0, 3):
|
||||
if plugin_match_found == True:
|
||||
break
|
||||
pID = ressource["id"]
|
||||
url2 = f"https://api.spiget.org/v2/resources/{pID}/versions?size=100&sort=-name"
|
||||
packageVersions = doAPIRequest(url2)
|
||||
for updates in packageVersions:
|
||||
updateVersion = updates["name"]
|
||||
if localFileVersion in updateVersion:
|
||||
plugin_match_found = True
|
||||
pluginID = pID
|
||||
updateId = updates["id"]
|
||||
plugin_latest_version = getLatestPluginVersion(pID)
|
||||
plugin_is_outdated = compareVersions(plugin_latest_version, updateVersion)
|
||||
addToPluginList(pID, updateId, plugin_latest_version , plugin_is_outdated)
|
||||
return pluginID
|
||||
break
|
||||
if i == 1:
|
||||
localFileVersionNew = re.sub(r'(\-\w*)', '', localFileVersion)
|
||||
if i == 2:
|
||||
pluginNameinYML = eggCrackingJar(localPluginFullName, 'name')
|
||||
url = "https://api.spiget.org/v2/search/resources/" + pluginNameinYML + "?field=name&sort=-downloads"
|
||||
packageName = doAPIRequest(url)
|
||||
localFileVersion = localFileVersionNew
|
||||
|
||||
for ressource in packageName:
|
||||
if plugin_match_found == True:
|
||||
break
|
||||
pID = ressource["id"]
|
||||
url2 = f"https://api.spiget.org/v2/resources/{pID}/versions?size=100&sort=-name"
|
||||
packageVersions = doAPIRequest(url2)
|
||||
for updates in packageVersions:
|
||||
updateVersion = updates["name"]
|
||||
if localFileVersionNew in updateVersion:
|
||||
plugin_match_found = True
|
||||
pluginID = pID
|
||||
updateId = updates["id"]
|
||||
plugin_latest_version = getLatestPluginVersion(pID)
|
||||
plugin_is_outdated = compareVersions(plugin_latest_version, updateVersion)
|
||||
addToPluginList(pID, updateId, plugin_latest_version , plugin_is_outdated)
|
||||
return pluginID
|
||||
|
||||
else:
|
||||
if plugin_match_found != True:
|
||||
|
@@ -4,6 +4,7 @@ from urllib.error import HTTPError
|
||||
from pathlib import Path
|
||||
|
||||
from handlers.handle_sftp import createSFTPConnection, sftp_listFilesInServerRoot
|
||||
from handlers.handle_ftp import createFTPConnection, ftp_listFilesInServerRoot
|
||||
from handlers.handle_config import configurationValues
|
||||
from utils.consoleoutput import oColors
|
||||
from serverjar.serverjar_paper import paperCheckForUpdate, papermc_downloader
|
||||
@@ -12,8 +13,12 @@ from serverjar.serverjar_paper import paperCheckForUpdate, papermc_downloader
|
||||
def checkInstalledServerjar():
|
||||
configValues = configurationValues()
|
||||
if not configValues.localPluginFolder:
|
||||
sftp = createSFTPConnection()
|
||||
serverRootList = sftp_listFilesInServerRoot(sftp)
|
||||
if not configValues.sftp_useSftp:
|
||||
ftp = createFTPConnection()
|
||||
serverRootList = ftp_listFilesInServerRoot(ftp)
|
||||
else:
|
||||
sftp = createSFTPConnection()
|
||||
serverRootList = sftp_listFilesInServerRoot(sftp)
|
||||
else:
|
||||
serverRootList = os.path.dirname(configValues.pathToPluginFolder)
|
||||
serverRootList = os.listdir(serverRootList)
|
||||
|
@@ -7,13 +7,16 @@ from rich.console import Console
|
||||
|
||||
from utils.consoleoutput import oColors
|
||||
from utils.web_request import doAPIRequest
|
||||
from handlers.handle_sftp import sftp_upload_server_jar, sftp_cdPluginDir, createSFTPConnection
|
||||
from handlers.handle_sftp import createSFTPConnection, sftp_upload_server_jar
|
||||
from handlers.handle_ftp import createFTPConnection, ftp_upload_server_jar
|
||||
from handlers.handle_config import configurationValues
|
||||
from utils.utilities import createTempPluginFolder, deleteTempPluginFolder, calculateFileSizeMb
|
||||
|
||||
|
||||
# = 1.16.5
|
||||
def getInstalledPaperMinecraftVersion(localPaperName):
|
||||
if localPaperName is None:
|
||||
return False
|
||||
mcVersionFull = re.search(r'(\d*\.*\d)+', localPaperName)
|
||||
try:
|
||||
mcVersion = mcVersionFull.group()
|
||||
@@ -24,6 +27,8 @@ def getInstalledPaperMinecraftVersion(localPaperName):
|
||||
|
||||
# = 550
|
||||
def getInstalledPaperVersion(localPaperName):
|
||||
if localPaperName is None:
|
||||
return False
|
||||
paperBuildFull = re.search(r'([\d]*.jar)', localPaperName)
|
||||
try:
|
||||
paperBuild = paperBuildFull.group()
|
||||
@@ -35,52 +40,52 @@ def getInstalledPaperVersion(localPaperName):
|
||||
|
||||
def findVersionGroup(mcVersion):
|
||||
versionGroups = ['1.16', '1.15']
|
||||
versionGroupFound = False
|
||||
if mcVersion is None:
|
||||
return 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
|
||||
return paperVersionGroup
|
||||
if versionGroup == mcVersion:
|
||||
versionGroupFound = True
|
||||
paperVersionGroup = versionGroup
|
||||
break
|
||||
|
||||
return paperVersionGroup
|
||||
return paperVersionGroup
|
||||
return False # Not found
|
||||
|
||||
|
||||
def findBuildVersion(wantedPaperBuild):
|
||||
versionGroups = ['1.16', '1.15']
|
||||
paperBuildFound = False
|
||||
if wantedPaperBuild is None:
|
||||
return False
|
||||
for versionGroup in versionGroups:
|
||||
if paperBuildFound is True:
|
||||
break
|
||||
url = f"https://papermc.io/api/v2/projects/paper/version_group/{versionGroup}/builds"
|
||||
papermcdetails = doAPIRequest(url)
|
||||
paperMcBuilds = papermcdetails["builds"]
|
||||
for build in paperMcBuilds:
|
||||
paperBuild = str(build["build"])
|
||||
if paperBuild == wantedPaperBuild:
|
||||
paperBuildFound = True
|
||||
paperVersionGroup = build["version"]
|
||||
break
|
||||
return paperVersionGroup
|
||||
return paperVersionGroup
|
||||
return False # Not found
|
||||
|
||||
|
||||
def findLatestBuild(paperVersionGroup):
|
||||
if paperVersionGroup is None:
|
||||
return False
|
||||
url = f"https://papermc.io/api/v2/projects/paper/version_group/{paperVersionGroup}/builds"
|
||||
papermcbuilds = doAPIRequest(url)
|
||||
if "status" in papermcbuilds: # Checks if the API returns a status. This means that there was an error.
|
||||
return False
|
||||
latestPaperBuild = papermcbuilds["builds"][-1]["build"]
|
||||
return latestPaperBuild
|
||||
|
||||
|
||||
def findLatestBuildForVersion(mcVersion):
|
||||
if mcVersion is None:
|
||||
return False
|
||||
url = f"https://papermc.io/api/v2/projects/paper/versions/{mcVersion}"
|
||||
papermcbuilds = doAPIRequest(url)
|
||||
latestPaperBuild = papermcbuilds["builds"][-1]
|
||||
@@ -88,6 +93,8 @@ def findLatestBuildForVersion(mcVersion):
|
||||
|
||||
|
||||
def versionBehind(installedPaperBuild, latestPaperBuild):
|
||||
if installedPaperBuild or latestPaperBuild is None:
|
||||
return False
|
||||
installedPaperBuildint = int(installedPaperBuild)
|
||||
latestPaperBuildint = int(latestPaperBuild)
|
||||
versionsBehind = latestPaperBuildint - installedPaperBuildint
|
||||
@@ -95,6 +102,8 @@ def versionBehind(installedPaperBuild, latestPaperBuild):
|
||||
|
||||
|
||||
def getDownloadFileName(paperMcVersion, paperBuild):
|
||||
if paperMcVersion or paperBuild is None:
|
||||
return False
|
||||
url = f"https://papermc.io/api/v2/projects/paper/versions/{paperMcVersion}/builds/{paperBuild}"
|
||||
buildDetails = doAPIRequest(url)
|
||||
downloadName = buildDetails["downloads"]["application"]["name"]
|
||||
@@ -103,11 +112,50 @@ def getDownloadFileName(paperMcVersion, paperBuild):
|
||||
|
||||
def paperCheckForUpdate(installedServerjarFullName):
|
||||
mcVersion = getInstalledPaperMinecraftVersion(installedServerjarFullName)
|
||||
|
||||
# Report an error if getInstalledPaperMinecraftVersion encountered an issue.
|
||||
if not mcVersion:
|
||||
print(oColors.brightRed + f"ERR: An error was encountered while detecting the server's Minecraft version." +
|
||||
oColors.standardWhite)
|
||||
return False
|
||||
|
||||
paperInstalledBuild = getInstalledPaperVersion(installedServerjarFullName)
|
||||
|
||||
# Report an error if getInstalledPaperVersion encountered an issue.
|
||||
if not paperInstalledBuild:
|
||||
print(oColors.brightRed + f"ERR: An error was encountered while detecting the server's Paper version." +
|
||||
oColors.standardWhite)
|
||||
return False
|
||||
|
||||
versionGroup = findVersionGroup(mcVersion)
|
||||
|
||||
# Report an error if findVersionGroup encountered an issue.
|
||||
if not versionGroup:
|
||||
print(oColors.brightRed + f"ERR: An error was encountered while fetching the server's version group." +
|
||||
oColors.standardWhite)
|
||||
return False
|
||||
|
||||
paperLatestBuild = findLatestBuild(versionGroup)
|
||||
|
||||
# Report an error if findLatestBuild encountered an issue.
|
||||
if not paperLatestBuild:
|
||||
print(oColors.brightRed + f"ERR: An error was encountered while fetching the latest version of PaperMC." +
|
||||
oColors.standardWhite)
|
||||
return False # Not currently handled, but can be at a later date. Currently just stops the following from
|
||||
# being printed.
|
||||
|
||||
paperVersionBehind = versionBehind(paperInstalledBuild, paperLatestBuild)
|
||||
|
||||
# Report an error if getInstalledPaperVersion encountered an issue.
|
||||
if not paperVersionBehind:
|
||||
print(oColors.brightRed + f"ERR: An error was encountered while detecting how many versions behind you are. "
|
||||
f"Will display as 'N/A'." + oColors.standardWhite)
|
||||
paperVersionBehind = "N/A" # Sets paperVersionBehind to N/A while still letting the versionBehind check return
|
||||
# # False for error-handing reasons.
|
||||
|
||||
# Does not return false as versions behind doesn't break things. It is just helpful information.
|
||||
# paperVersionBehind will just display as "N/A"
|
||||
|
||||
print("┌─────┬────────────────────────────────┬──────────────┬──────────────┬───────────────────┐")
|
||||
print("│ No. │ Name │ Installed V. │ Latest V. │ Versions behind │")
|
||||
print("└─────┴────────────────────────────────┴──────────────┴──────────────┴───────────────────┘")
|
||||
@@ -165,9 +213,14 @@ def papermc_downloader(paperBuild='latest', installedServerjarName=None, mcVersi
|
||||
filesizeData = calculateFileSizeMb(filesize)
|
||||
print("Downloaded " + (str(filesizeData)).rjust(9) + f" MB here {downloadPackagePath}")
|
||||
if not configValues.localPluginFolder:
|
||||
sftpSession = createSFTPConnection()
|
||||
sftp_upload_server_jar(sftpSession, downloadPackagePath)
|
||||
if not configValues.sftp_useSftp:
|
||||
ftpSession = createFTPConnection()
|
||||
ftp_upload_server_jar(ftpSession, downloadPackagePath)
|
||||
else:
|
||||
sftpSession = createSFTPConnection()
|
||||
sftp_upload_server_jar(sftpSession, downloadPackagePath)
|
||||
|
||||
deleteTempPluginFolder(downloadPath)
|
||||
|
||||
print(oColors.brightGreen + "Downloaded successfully " + oColors.standardWhite + f"Paper {paperBuild}" + \
|
||||
oColors.brightGreen + " for " + oColors.standardWhite + f"{mcVersion}" + oColors.standardWhite)
|
||||
oColors.brightGreen + " for " + oColors.standardWhite + f"{mcVersion}" + oColors.standardWhite)
|
||||
|
@@ -8,6 +8,7 @@ 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():
|
||||
@@ -134,16 +135,20 @@ def check_requirements():
|
||||
apiTest()
|
||||
check_local_plugin_folder()
|
||||
if not configValues.localPluginFolder:
|
||||
createSFTPConnection()
|
||||
if configValues.sftp_useSftp:
|
||||
createSFTPConnection()
|
||||
else:
|
||||
createFTPConnection()
|
||||
|
||||
|
||||
def createTempPluginFolder():
|
||||
tempPluginFolder = Path("./TempSFTPUploadFolder")
|
||||
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" % checkConfig().pathToPluginFolder)
|
||||
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()
|
||||
@@ -167,4 +172,4 @@ def calculateFileSizeKb(downloadFileSize):
|
||||
fileSizeDownload = int(downloadFileSize)
|
||||
fileSizeKb = fileSizeDownload / 1024
|
||||
roundedFileSize = round(fileSizeKb, 2)
|
||||
return roundedFileSize
|
||||
return roundedFileSize
|
||||
|
@@ -3,7 +3,7 @@ import requests
|
||||
|
||||
|
||||
def doAPIRequest(url):
|
||||
headers = {'user-agent': 'pluGET'}
|
||||
headers = {'user-agent': 'pluGET/1.0'}
|
||||
response = requests.get(url, headers=headers)
|
||||
packageDetails = response.json()
|
||||
return packageDetails
|
||||
|
Reference in New Issue
Block a user