Compare commits

...

24 Commits

Author SHA1 Message Date
Neocky
1e7b30a1be Changed output when checking and removed debug output
Changes:
-removed update available columm and integrated it with colors of the plugin name
- removed leftover debug output
2021-06-20 13:54:15 +02:00
Neocky
a4b1b7acf9 Added changelog to check help 2021-06-20 00:54:30 +02:00
Neocky
8344ed0afc Merge pull request #27 from Neocky/dev/v1.6.0
Merge Dev/v1.6.0
2021-06-20 00:42:17 +02:00
Neocky
2a416bbbc2 Added conformation for updateing and fixed serverjar issues
Changes:
- updated paper checker to 1.17
- added conformation when updating plugins
- added error handling
- added changlog as optional param for the check command
- fixed problems with paper updated
- updated help
- removed debug output
- removed unnecesary commnents
2021-06-20 00:36:36 +02:00
Neocky
456a0e185a Merged all and individual checking/updating of plugins
Changes:
- added fail check with api connection
- added localFileName to INSTALLEDPLUGINLIST
- merged checking/updating plugins
2021-06-19 18:01:05 +02:00
Neocky
f4361ad137 Fixed bug when plugin wasn't found with description 2021-06-19 13:47:12 +02:00
Neocky
41527926b2 Fixed TypeError while checking for updates & added update notes test
Changes:
- fixed TypeError when folder in plugin folder had .jar in name
- added update notes test to check all
2021-06-12 17:03:55 +02:00
Neocky
93818b90d7 Removed . in initial config for SFTP 2021-05-30 19:00:09 +02:00
Neocky
2712bd5be6 Added .jar validation to SFTP/FTP
Changes:
- added `.jar` file validation to SFTP/FTP
- cleanup of old code
2021-05-30 18:52:35 +02:00
Neocky
3ad7753674 Added skip when file is not .jar file
Changes:
- added skipping file if not .jar file
- removed some unneceessary config lookups
- updated regex
2021-05-29 20:42:02 +02:00
Neocky
38edfc73d6 Create FUNDING.yml 2021-05-29 01:12:30 +02:00
Neocky
a4636153c0 Added Inconsisten Version & Names topic 2021-05-29 00:38:56 +02:00
Neocky
764e8bcb81 Fixed JsonDecodeError & Better pluginnames
Changes:
- fixed JsonDecodeError when filename had many special characters in it
- fixed version & name wouldn't get detectet when plugin.yml file would have whitespaces in the beginning
- better output of plugin names when checking & updating
2021-05-28 23:52:16 +02:00
Neocky
26d7965422 Added installer.bat
Changes:
- added installer.bat file which automaticcally will install the needed python packages to run pluGET
2021-05-26 20:57:25 +02:00
Neocky
78f38f36cd Added installer.bat help
Changes:
- added installer.bat help
- changed formating of windows security message
2021-05-26 20:54:12 +02:00
Neocky
afbc3e8029 Merge pull request #18 from ZandercraftGames/main
Error Handling To Address Paper Check Crashes
2021-05-19 21:08:45 +02:00
Zander
a08aab7ae4 Made paperVersionBehind display "N/A" instead of "False" for more clarity. 2021-05-15 19:05:29 -04:00
Zander
b31cca5e31 Fix findLatestBuild check returning false on a successful API response. 2021-05-15 19:02:09 -04:00
Neocky
cd4a66002c Added new discord picture 2021-05-15 01:30:22 +02:00
Neocky
0d709cfb6f Fixed typo 2021-05-15 00:47:06 +02:00
Neocky
edc300a33d Eggcracking for better name finding & added better version digging
Added:
- eggcracking to get plugin name
- better version find mechanism
2021-05-15 00:46:29 +02:00
Zander
11b4fdcbeb Add error handling to "check serverjar" command on paper servers. Fixes use assignment issues when detection doesn't work. 2021-05-09 01:33:05 -04:00
Zander
716227eafa Add PyCharm configurations to .gitignore 2021-05-09 00:23:11 -04:00
Neocky
6e980a1580 Fixed typo & added part about security warning 2021-04-12 23:26:12 +02:00
12 changed files with 408 additions and 170 deletions

3
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,3 @@
# These are supported funding model platforms
custom: https://www.buymeacoffee.com/Neocky # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

3
.gitignore vendored
View File

@@ -130,3 +130,6 @@ dmypy.json
# VSCode Settings
.vscode
# PyCharm Settings
.idea

View File

@@ -69,7 +69,7 @@ pluGET can:
- 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 installed server software for update
- update installed server software to a specific version
@@ -88,23 +88,30 @@ 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
### Python
### 1. Python
Python needs to be installed on your machine.
Get it [here](https://www.python.org/downloads/).
### Dependencies
### 2. Dependencies
Install the needed packages for this project.
#### Automatically (Windows only)
Execute the `installer.bat` file to automaticcally install the needed packages for this project.
> Sometimes the security warning `Windows protected your PC` comes when launching the `installer.bat` file.
> This is a normal behaviour from the windows defender because this is a unknown `.bat` file.
> To run the `installer.bat` anyway, click `More Info` and then `Run anyway` when the message pops up.
##### Manually
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 `\src`folder and the program will close.
### 3. Edit the Config
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 +119,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:
```
@@ -153,14 +164,14 @@ or:
```
get 'pluginName'
```
#### Check all plugins/one specific plugin for updates:
`check [all/pluginName]`
#### Check all plugins/one specific plugin for updates with optional changelog output:
`check [all/pluginName] [changelog]`
```
check all
```
or:
```
check 'pluginName'
check 'pluginName' changelog
```
<details>
@@ -228,6 +239,21 @@ get-paper 321
## Known problems
### Can't get latest version/Update available
#### Inconsistent Names and Versions
For example:
![EssentialsX](https://i.ibb.co/fDyCYQ8/essentialsx.png)
EssentialsX is a prominent example of inconsisten version naming. The installed version is `2.18.2.0` but on [Spigot](https://www.spigotmc.org/resources/essentialsx.9089/update?update=371379) the version is only described as `2.18.2`.
That's the reason pluGET can't detect it automatically.
> There are of course many more plugins which have some sort of inconsistency which makes it sadly impossible for pluGET to detect them all. EssentialsX is used only as an example.
#### Solution
Download the plugins with the `get [pluginName]` command to make them detectable for pluGET.
After downloading EssentialsX with `get EssentialsX` and using `check all`:
![EssentialsX](https://i.ibb.co/ws5wHTj/essentialsx-2.png)
EssentialsX is now detected from pluGET and can update automatically when a new version comes out.
#### Bukkit plugins
For example:
![worldguard](https://i.ibb.co/7NJ9HRG/pluget-checkallonlyone.png)
As you can see the installed version was found but not the latest version for this plugin.

34
installer.bat Normal file
View File

@@ -0,0 +1,34 @@
@ECHO OFF
cd /d %~dp0
Echo ___ ___ ___ ___ ___ ___
Echo /\ \ /\__\ /\__\ /\ \ /\ \ /\ \
Echo /::\ \ /:/ / /:/ / /::\ \ /::\ \ \:\ \
Echo /:/\:\ \ /:/ / /:/ / /:/\:\ \ /:/\:\ \ \:\ \
Echo /::\~\:\ \ /:/ / /:/ / ___ /:/ \:\ \ /::\~\:\ \ /::\ \
Echo /:/\:\ \:\__\ /:/__/ /:/__/ /\__\ /:/__/_\:\__\ /:/\:\ \:\__\ /:/\:\__\
Echo \/__\:\/:/ / \:\ \ \:\ \ /:/ / \:\ /\ \/__/ \:\~\:\ \/__/ /:/ \/__/
Echo \::/ / \:\ \ \:\ /:/ / \:\ \:\__\ \:\ \:\__\ /:/ /
Echo \/__/ \:\ \ \:\/:/ / \:\/:/ / \:\ \/__/ \/__/
Echo \:\__\ \::/ / \::/ / \:\__\
Echo \/__/ \/__/ \/__/ \/__/
Echo `
Echo `
Echo ------------------------------------
Echo [By Neocky]
Echo https://github.com/Neocky/pluGET
Echo pluGET-Installer
Echo ------------------------------------
Echo `
Echo ----------------------------------------------------------------------------------
Echo Installing Python packages and dependencies...
py -m pip install -r requirements.txt
Echo `
Echo Launching pluGET...
launcher.bat
exit

View File

@@ -75,12 +75,12 @@ def createConfig():
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']['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:

View File

@@ -1,6 +1,8 @@
import os
import sys
import ftplib
import stat
import re
from utils.consoleoutput import oColors
from handlers.handle_config import configurationValues
@@ -93,3 +95,13 @@ def ftp_downloadFile(ftp, downloadPath, fileToDownload):
ftp.retrbinary('RETR '+fileToDownload, filedata.write)
filedata.close()
ftp.quit()
def ftp_validateFileAttributes(ftp, pluginPath):
pluginFTPAttribute = ftp.lstat(pluginPath)
if stat.S_ISDIR(pluginFTPAttribute.st_mode):
return False
elif re.search(r'.jar$', pluginPath):
return True
else:
return False

View File

@@ -61,7 +61,7 @@ def handleInput(inputCommand, inputSelectedObject, inputParams):
if inputSelectedObject == 'serverjar':
checkInstalledServerjar()
else:
checkInstalledPackage(inputSelectedObject)
checkInstalledPackage(inputSelectedObject, inputParams)
break
if inputCommand == 'search':
searchPackage(inputSelectedObject)

View File

@@ -2,6 +2,8 @@ import sys
import os
import pysftp
import paramiko
import stat
import re
from utils.consoleoutput import oColors
from handlers.handle_config import configurationValues
@@ -27,14 +29,16 @@ def createSFTPConnection():
def sftp_showPlugins(sftp):
sftp.cd('plugins')
configValues = configurationValues()
sftp.cd(configValues.sftp_folderPath)
for attr in sftp.listdir_attr():
print(attr.filename, attr)
def sftp_upload_file(sftp, itemPath):
configValues = configurationValues()
try:
sftp.chdir('plugins')
sftp.chdir(configValues.sftp_folderPath)
sftp.put(itemPath)
except FileNotFoundError:
@@ -54,8 +58,9 @@ def sftp_upload_server_jar(sftp, itemPath):
def sftp_listAll(sftp):
configValues = configurationValues()
try:
sftp.chdir('plugins')
sftp.chdir(configValues.sftp_folderPath)
installedPlugins = sftp.listdir()
except FileNotFoundError:
print(oColors.brightRed + "[SFTP]: The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
@@ -86,4 +91,13 @@ def sftp_downloadFile(sftp, downloadPath, fileToDownload):
sftp.get(fileToDownload)
sftp.close()
os.chdir(currentDirectory)
def sftp_validateFileAttributes(sftp, pluginPath):
pluginSFTPAttribute = sftp.lstat(pluginPath)
if stat.S_ISDIR(pluginSFTPAttribute.st_mode):
return False
elif re.search(r'.jar$', pluginPath):
return True
else:
return False

View File

@@ -79,12 +79,18 @@ def searchPackage(ressourceName):
ressourceId = packageName[ressourceSelected]["id"]
if not configValues.localPluginFolder:
try:
getSpecificPackage(ressourceId, configValues.sftp_folderPath)
if configValues.sftp_seperateDownloadPath is True:
getSpecificPackage(ressourceId, configValues.sftp_pathToSeperateDownloadPath)
else:
getSpecificPackage(ressourceId, configValues.sftp_folderPath)
except HTTPError as err:
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
else:
try:
getSpecificPackage(ressourceId, configValues.pathToPluginFolder)
if configValues.seperateDownloadPath is True:
getSpecificPackage(ressourceId, configValues.pathToPluginFolder)
else:
getSpecificPackage(ressourceId, configValues.pathToSeperateDownloadPath)
except HTTPError as err:
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
@@ -134,9 +140,6 @@ 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 inputPackageVersion is None or inputPackageVersion == 'latest':
downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath)

View File

@@ -1,6 +1,7 @@
import os
import re
import io
import base64
from zipfile import ZipFile
from urllib.error import HTTPError
from pathlib import Path
@@ -9,8 +10,8 @@ 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, sftp_downloadFile
from handlers.handle_ftp import createFTPConnection, ftp_listAll, ftp_downloadFile
from handlers.handle_sftp import createSFTPConnection, sftp_listAll, sftp_downloadFile, sftp_validateFileAttributes
from handlers.handle_ftp import createFTPConnection, ftp_listAll, ftp_downloadFile, ftp_validateFileAttributes
from plugin.plugin_downloader import getSpecificPackage
from utils.utilities import createTempPluginFolder, deleteTempPluginFolder
@@ -21,8 +22,8 @@ def createPluginList():
return INSTALLEDPLUGINLIST
def addToPluginList(pluginId, versionId, plugin_latest_version, plugin_is_outdated):
INSTALLEDPLUGINLIST.append([pluginId, versionId, plugin_latest_version, plugin_is_outdated])
def addToPluginList(localFileName, pluginId, versionId, plugin_latest_version, plugin_is_outdated):
INSTALLEDPLUGINLIST.append([localFileName, pluginId, versionId, plugin_latest_version, plugin_is_outdated])
def getFileName(pluginName):
@@ -46,7 +47,7 @@ def getFileVersion(pluginName):
if pluginVersionString.endswith('.'):
pluginVersionString = ''
if pluginVersionString == '':
pluginVersionString = eggCrackingJar(pluginNameFull)
pluginVersionString = eggCrackingJar(pluginNameFull, 'version')
return pluginVersionString
@@ -57,6 +58,23 @@ def getLatestPluginVersion(pluginId):
return versionLatestUpdate
def getUpdateDescription(pluginId):
url = f"https://api.spiget.org/v2/resources/{pluginId}/updates?size=1&sort=-date"
latestDescriptionSearch = doAPIRequest(url)
versionLatestDescription = latestDescriptionSearch[0]["description"]
versionLatestDescription = base64.b64decode(versionLatestDescription)
versionLatestDescriptionText =versionLatestDescription.decode('utf-8')
htmlRegex = re.compile('<.*?>')
versionLatestDescriptionText = re.sub(htmlRegex, '', versionLatestDescriptionText)
linesChangelogDescription = versionLatestDescriptionText.split("\n")
nonEmptyLines = [line for line in linesChangelogDescription if line.strip() != ""]
stringnonEmptyLines = ""
for line in nonEmptyLines:
stringnonEmptyLines += line + "\n"
stringnonEmptyLines = stringnonEmptyLines[:-1]
return stringnonEmptyLines
def compareVersions(plugin_latest_version, pluginVersion):
if pluginVersion < plugin_latest_version:
plugin_is_outdated = True
@@ -65,7 +83,7 @@ def compareVersions(plugin_latest_version, pluginVersion):
return plugin_is_outdated
def eggCrackingJar(localJarFileName):
def eggCrackingJar(localJarFileName, searchMode):
configValues = configurationValues()
if not configValues.localPluginFolder:
if configValues.sftp_useSftp:
@@ -82,26 +100,40 @@ def eggCrackingJar(localJarFileName):
pluginPath = configValues.pathToPluginFolder
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'^\s*?version: ', line):
pluginVersion = re.sub(r'^\s*?version: ', '', line)
pluginVersion = pluginVersion.replace('\n', '')
pluginVersion = pluginVersion.replace("'", '')
pluginVersion = pluginVersion.replace('"', '')
elif searchMode == 'name':
if re.match(r'^\s*?name: ', line):
pluginName = re.sub(r'^\s*?name: ', '', line)
pluginName = pluginName.replace('\n', '')
pluginName = pluginName.replace("'", '')
pluginName = pluginName.replace('"', '')
except FileNotFoundError:
pluginVersion = ''
pluginName = ''
if not configValues.localPluginFolder:
deleteTempPluginFolder(tempPluginFolderPath)
return pluginVersion
if searchMode == 'version':
return pluginVersion
if searchMode == 'name':
return pluginName
def checkInstalledPackage(inputSelectedObject="all"):
def checkInstalledPackage(inputSelectedObject="all", inputOptionalParam=None):
configValues = configurationValues()
createPluginList()
pluginFolderPath = configValues.pathToPluginFolder
if not configValues.localPluginFolder:
if configValues.sftp_useSftp:
connection = createSFTPConnection()
@@ -110,26 +142,49 @@ def checkInstalledPackage(inputSelectedObject="all"):
connection = createFTPConnection()
pluginList = ftp_listAll(connection)
else:
pluginList = os.listdir(configValues.pathToPluginFolder)
pluginList = os.listdir(pluginFolderPath)
i = 0
oldPlugins = 0
print(oColors.brightBlack + f"Checking: {inputSelectedObject}" + oColors.standardWhite)
print("┌─────┬────────────────────────────────┬──────────────┬──────────────┬───────────────────┐")
print("│ No. │ Name │ Installed V. │ Latest V. │ Update available │")
print("└─────┴────────────────────────────────┴──────────────┴─────────────────────────────────┘")
if inputOptionalParam != "changelog":
print(oColors.brightBlack + f"Use 'check {inputSelectedObject} changelog' to get the latest changelog from plugins" + oColors.standardWhite)
print("┌─────┬────────────────────────────────┬────────────────────────────")
print("│ No. │ Name │ Installed V. │ Latest V. │")
print("└─────┴────────────────────────────────┴──────────────┴──────────────┘")
try:
for plugin in track(pluginList, description="Checking for updates" ,transient=True, complete_style="bright_yellow"):
if not configValues.localPluginFolder:
if configValues.sftp_seperateDownloadPath is True:
pluginFile = f"{configValues.sftp_pathToSeperateDownloadPath}/{plugin}"
else:
pluginFile = f"{configValues.sftp_folderPath}/{plugin}"
if configValues.sftp_useSftp:
pluginAttributes = sftp_validateFileAttributes(connection, pluginFile)
if pluginAttributes == False:
continue
else:
pluginAttributes = ftp_validateFileAttributes(connection, pluginFile)
if pluginAttributes == False:
continue
else:
if not os.path.isfile(Path(f"{pluginFolderPath}/{plugin}")):
continue
if not re.search(r'.jar$', plugin):
continue
try:
fileName = getFileName(plugin)
fileVersion = getFileVersion(plugin)
pluginId = getInstalledPlugin(fileName, fileVersion)
pluginId = getInstalledPlugin(fileName, fileVersion, plugin)
except TypeError:
continue
pluginIdStr = str(pluginId)
if fileVersion == '':
fileVersion = 'N/A'
try:
pluginLatestVersion = INSTALLEDPLUGINLIST[i][2]
pluginLatestVersion = INSTALLEDPLUGINLIST[i][3]
except IndexError:
pluginLatestVersion = 'N/A'
@@ -137,7 +192,7 @@ def checkInstalledPackage(inputSelectedObject="all"):
pluginLatestVersion = 'N/A'
try:
pluginIsOutdated = INSTALLEDPLUGINLIST[i][3]
pluginIsOutdated = INSTALLEDPLUGINLIST[i][4]
except IndexError:
pluginIsOutdated = 'N/A'
@@ -147,28 +202,45 @@ def checkInstalledPackage(inputSelectedObject="all"):
if pluginIsOutdated == True:
oldPlugins = oldPlugins + 1
if inputSelectedObject != "*" and inputSelectedObject != "all":
if re.search(r'.jar$', fileName):
fileName = eggCrackingJar(plugin, "name")
if inputSelectedObject != "all" and inputSelectedObject != "*":
if inputSelectedObject != pluginIdStr or not re.search(inputSelectedObject, fileName, re.IGNORECASE):
i += 1
continue
if inputSelectedObject == "all" or inputSelectedObject != "*" or inputSelectedObject != "all":
if inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE):
if pluginLatestVersion == 'N/A':
print(oColors.brightBlack + f" [{1}]".rjust(6), end='')
else:
print(f" [{1}]".rjust(6), end='')
print(" ", end='')
else:
if pluginLatestVersion == 'N/A':
print(oColors.brightBlack + f" [{i+1}]".rjust(6), end='')
else:
print(f" [{i+1}]".rjust(6), end='')
print(" ", end='')
if pluginIsOutdated == True:
print(oColors.brightGreen + f"{fileName}".ljust(33) + oColors.standardWhite, end='')
elif pluginIsOutdated == False:
print(oColors.brightRed + f"{fileName}".ljust(33) + oColors.standardWhite, end='')
else:
print(f"{fileName}".ljust(33), end='')
print(f"{fileVersion}".ljust(15), end='')
print(f"{pluginLatestVersion}".ljust(15), end='')
print(f"{pluginIsOutdated}".ljust(5) + oColors.standardWhite)
print(f"{fileVersion}".ljust(15), end='')
print(f"{pluginLatestVersion}".ljust(15))
if (inputOptionalParam == "changelog" and pluginLatestVersion != 'N/A'):
print(oColors.brightYellow + f"CHANGELOG {fileName}:" + oColors.standardWhite)
description = getUpdateDescription(pluginId)
print(description)
print()
if inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE):
break
else:
if pluginLatestVersion == 'N/A':
print(oColors.brightBlack + f" [{i+1}]".rjust(6), end='')
else:
print(f" [{i+1}]".rjust(6), end='')
print(" ", end='')
print(f"{fileName}".ljust(33), end='')
print(f"{fileVersion}".ljust(15), end='')
print(f"{pluginLatestVersion}".ljust(15), end='')
print(f"{pluginIsOutdated}".ljust(5) + oColors.standardWhite)
print(oColors.brightRed + "Wrong input! Use 'check all' to check every plugin for updates!" + oColors.standardWhite)
break
i += 1
except TypeError:
@@ -178,16 +250,35 @@ def checkInstalledPackage(inputSelectedObject="all"):
def updateInstalledPackage(inputSelectedObject='all'):
configValues = configurationValues()
createPluginList()
if not configValues.localPluginFolder:
if configValues.sftp_useSftp:
connection = createSFTPConnection()
pluginList = sftp_listAll(connection)
else:
connection = createFTPConnection()
pluginList = ftp_listAll(connection)
else:
pluginList = os.listdir(configValues.pathToPluginFolder)
try:
print(oColors.brightBlack + "Selected plugins with available Updates:" + oColors.standardWhite)
if inputSelectedObject == "all" or inputSelectedObject == "*":
for pluginIndex in range(len(INSTALLEDPLUGINLIST)):
if INSTALLEDPLUGINLIST[pluginIndex][4] == True:
fileName = getFileName(INSTALLEDPLUGINLIST[pluginIndex][0])
print(fileName, end=' ')
else:
print(inputSelectedObject, end=' ')
print()
updateConfirmation = input("Update these plugins [y/n] ? ")
if updateConfirmation != "y":
print(oColors.brightRed + "Aborting the update process."+ oColors.standardWhite)
return False
except NameError:
print(oColors.brightRed + "Check for updates before updating plugins with: 'check all'" + oColors.standardWhite)
print(oColors.brightRed + "Started checking for updates..." + oColors.standardWhite)
checkInstalledPackage()
print(oColors.brightRed + f"Please input 'update {inputSelectedObject}' again!" + oColors.standardWhite)
return False
i = 0
pluginsUpdated = 0
indexNumberUpdated = 0
@@ -196,77 +287,57 @@ def updateInstalledPackage(inputSelectedObject='all'):
print("│ No. │ Name │ Old V. │ New V. │")
print("└─────┴────────────────────────────────┴────────────┴──────────┘")
try:
for plugin in track(pluginList, description="Updating" ,transient=True, complete_style="bright_magenta"):
for pluginArray in track(INSTALLEDPLUGINLIST, description="Updating" ,transient=True, complete_style="bright_magenta", ):
plugin = INSTALLEDPLUGINLIST[i][0]
if not configValues.localPluginFolder:
if configValues.sftp_seperateDownloadPath is True:
pluginFile = f"{configValues.sftp_pathToSeperateDownloadPath}/{plugin}"
else:
pluginFile = f"{configValues.sftp_folderPath}/{plugin}"
if configValues.sftp_useSftp:
pluginAttributes = sftp_validateFileAttributes(connection, pluginFile)
if pluginAttributes == False:
i += 1
continue
else:
pluginAttributes = ftp_validateFileAttributes(connection, pluginFile)
if pluginAttributes == False:
i += 1
continue
else:
pluginFolderPath = configValues.pathToPluginFolder
if not os.path.isfile(Path(f"{pluginFolderPath}/{plugin}")):
i += 1
continue
if not re.search(r'.jar$', plugin):
i += 1
continue
try:
fileName = getFileName(plugin)
fileVersion = getFileVersion(plugin)
pluginId = getInstalledPlugin(fileName, fileVersion)
latestVersion = getLatestPluginVersion(pluginId)
except TypeError:
continue
except ValueError:
pluginId = INSTALLEDPLUGINLIST[i][1]
latestVersion = INSTALLEDPLUGINLIST[i][3]
except (TypeError, ValueError):
i += 1
continue
if re.search(r'.jar$', fileName):
fileName = eggCrackingJar(plugin, "name")
pluginIdStr = str(pluginId)
if pluginId == None or pluginId == '':
print(oColors.brightRed + "Couldn't find plugin id. Sorry :(" + oColors.standardWhite)
i += 1
continue
if inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE):
if INSTALLEDPLUGINLIST[i][3] == True:
if inputSelectedObject == 'all' or inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE):
if INSTALLEDPLUGINLIST[i][4] == True:
print(f" [{indexNumberUpdated+1}]".rjust(6), end='')
print(" ", end='')
print(f"{fileName}".ljust(33), end='')
print(f"{fileVersion}".ljust(13), end='')
print(f"{latestVersion}".ljust(13))
if not configValues.localPluginFolder:
if configValues.sftp_seperateDownloadPath is True:
pluginPath = configValues.sftp_pathToSeperateDownloadPath
else:
pluginPath = configValues.sftp_folderPath
pluginPath = Path(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 + "Error: Old plugin file coulnd't be deleted" + oColors.standardWhite)
else:
if configValues.seperateDownloadPath is True:
pluginPath = configValues.pathToSeperateDownloadPath
else:
pluginPath = configValues.pathToPluginFolder
pluginPath = Path(f"{pluginPath}/{plugin}")
indexNumberUpdated += 1
pluginsUpdated += 1
try:
getSpecificPackage(pluginId, configValues.pathToPluginFolder)
if configValues.seperateDownloadPath is False:
os.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)
break
else:
print(f"{fileName} is already on {latestVersion}")
print(oColors.brightRed + "Aborting the update process."+ oColors.standardWhite)
break
if inputSelectedObject == 'all':
if INSTALLEDPLUGINLIST[i][3] == True:
print(f" [{indexNumberUpdated+1}]".rjust(6), end='')
print(" ", end='')
print(f"{fileName}".ljust(33), end='')
print(f"{fileVersion}".ljust(13), end='')
print(f"{latestVersion}".ljust(13))
if not configValues.localPluginFolder:
if configValues.sftp_useSftp:
if configValues.sftp_seperateDownloadPath is True:
@@ -309,12 +380,12 @@ def updateInstalledPackage(inputSelectedObject='all'):
if configValues.seperateDownloadPath is True:
pluginPath = configValues.pathToSeperateDownloadPath
else:
pluginPath = configValues.pathToPluginFolder
pluginPath = pluginFolderPath
pluginPath = Path(f"{pluginPath}/{plugin}")
indexNumberUpdated += 1
pluginsUpdated += 1
try:
getSpecificPackage(pluginId, configValues.pathToPluginFolder)
getSpecificPackage(pluginId, pluginFolderPath)
if configValues.seperateDownloadPath is False:
os.remove(pluginPath)
except HTTPError as err:
@@ -322,36 +393,71 @@ def updateInstalledPackage(inputSelectedObject='all'):
pluginsUpdated -= 1
except FileNotFoundError:
print(oColors.brightRed + f"FileNotFoundError: Old plugin file coulnd't be deleted" + oColors.standardWhite)
if inputSelectedObject != 'all':
break
elif inputSelectedObject != 'all':
print(oColors.brightGreen + f"{fileName} is already on {latestVersion}" + oColors.standardWhite)
print(oColors.brightRed + "Aborting the update process."+ oColors.standardWhite)
break
else:
i += 1
continue
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)
if inputSelectedObject =='all' and pluginsUpdated == 0:
print(oColors.brightRed + "Error occured: Aborted updating plugins." + oColors.standardWhite)
except NameError:
print(oColors.brightRed + "Check for updates before updating plugins with: 'check all'" + oColors.standardWhite)
print(oColors.brightRed + "Started checking for updates..." + oColors.standardWhite)
checkInstalledPackage()
print(oColors.brightRed + f"Please input 'update {inputSelectedObject}' again!" + oColors.standardWhite)
if i != 0:
print(oColors.brightYellow + f"Plugins updated: [{pluginsUpdated}/{i}]" + oColors.standardWhite)
if inputSelectedObject =='all' and pluginsUpdated == 0 and i != 0:
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
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"
try:
packageName = doAPIRequest(url)
except ValueError:
continue
localFileVersion = localFileVersionNew
for ressource in packageName:
if plugin_match_found == True:
continue
pID = ressource["id"]
url2 = f"https://api.spiget.org/v2/resources/{pID}/versions?size=100&sort=-name"
try:
packageVersions = doAPIRequest(url2)
except ValueError:
continue
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(localPluginFullName, pID, updateId, plugin_latest_version , plugin_is_outdated)
return pluginID
else:
if plugin_match_found != True:
@@ -359,6 +465,6 @@ def getInstalledPlugin(localFileName, localFileVersion):
updateId = None
plugin_latest_version = None
plugin_is_outdated = None
addToPluginList(pID, updateId, plugin_latest_version , plugin_is_outdated)
addToPluginList(localPluginFullName, pID, updateId, plugin_latest_version , plugin_is_outdated)
return pluginID

View File

@@ -1,5 +1,3 @@
import os
import sys
import re
import urllib.request
from pathlib import Path
@@ -13,8 +11,9 @@ 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()
@@ -23,8 +22,9 @@ def getInstalledPaperMinecraftVersion(localPaperName):
return mcVersion
# = 550
def getInstalledPaperVersion(localPaperName):
if localPaperName is None:
return False
paperBuildFull = re.search(r'([\d]*.jar)', localPaperName)
try:
paperBuild = paperBuildFull.group()
@@ -35,53 +35,53 @@ def getInstalledPaperVersion(localPaperName):
def findVersionGroup(mcVersion):
versionGroups = ['1.16', '1.15']
versionGroupFound = False
versionGroups = ['1.17', '1.16', '1.15']
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
versionGroups = ['1.17', '1.16', '1.15']
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]
@@ -89,6 +89,8 @@ def findLatestBuildForVersion(mcVersion):
def versionBehind(installedPaperBuild, latestPaperBuild):
if installedPaperBuild is None or latestPaperBuild is None:
return False
installedPaperBuildint = int(installedPaperBuild)
latestPaperBuildint = int(latestPaperBuild)
versionsBehind = latestPaperBuildint - installedPaperBuildint
@@ -96,6 +98,8 @@ def versionBehind(installedPaperBuild, latestPaperBuild):
def getDownloadFileName(paperMcVersion, paperBuild):
if paperMcVersion is None 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"]
@@ -104,11 +108,45 @@ def getDownloadFileName(paperMcVersion, paperBuild):
def paperCheckForUpdate(installedServerjarFullName):
mcVersion = getInstalledPaperMinecraftVersion(installedServerjarFullName)
paperInstalledBuild = getInstalledPaperVersion(installedServerjarFullName)
versionGroup = findVersionGroup(mcVersion)
paperLatestBuild = findLatestBuild(versionGroup)
paperVersionBehind = versionBehind(paperInstalledBuild, paperLatestBuild)
# 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("└─────┴────────────────────────────────┴──────────────┴──────────────┴───────────────────┘")
@@ -134,7 +172,7 @@ def papermc_downloader(paperBuild='latest', installedServerjarName=None, mcVersi
if mcVersion == None:
if paperBuild == 'latest':
mcVersion = '1.16.5'
mcVersion = '1.17'
else:
mcVersion = findBuildVersion(paperBuild)
@@ -152,7 +190,6 @@ def papermc_downloader(paperBuild='latest', installedServerjarName=None, mcVersi
downloadFileName = getDownloadFileName(mcVersion, paperBuild)
downloadPackagePath = Path(f"{downloadPath}/{downloadFileName}")
if configValues.localPluginFolder == False:
downloadPath = createTempPluginFolder()
@@ -172,8 +209,8 @@ def papermc_downloader(paperBuild='latest', installedServerjarName=None, mcVersi
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)

View File

@@ -35,7 +35,7 @@ def getCommandHelp(optionalParams):
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(" 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")
@@ -120,7 +120,7 @@ def apiTest():
apiStatusUrl = 'https://api.spiget.org/v2/status'
try:
r = requests.get(apiStatusUrl)
except requests.exceptions.HTTPError:
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()