Compare commits

...

11 Commits

Author SHA1 Message Date
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
5 changed files with 169 additions and 48 deletions

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:
```

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

@@ -46,7 +46,7 @@ def getFileVersion(pluginName):
if pluginVersionString.endswith('.'):
pluginVersionString = ''
if pluginVersionString == '':
pluginVersionString = eggCrackingJar(pluginNameFull)
pluginVersionString = eggCrackingJar(pluginNameFull, 'version')
return pluginVersionString
@@ -65,7 +65,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,21 +82,34 @@ 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'^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 = ''
pluginName = ''
if not configValues.localPluginFolder:
deleteTempPluginFolder(tempPluginFolderPath)
return pluginVersion
if searchMode == 'version':
return pluginVersion
if searchMode == 'name':
return pluginName
def checkInstalledPackage(inputSelectedObject="all"):
@@ -122,7 +135,7 @@ def checkInstalledPackage(inputSelectedObject="all"):
try:
fileName = getFileName(plugin)
fileVersion = getFileVersion(plugin)
pluginId = getInstalledPlugin(fileName, fileVersion)
pluginId = getInstalledPlugin(fileName, fileVersion, plugin)
except TypeError:
continue
pluginIdStr = str(pluginId)
@@ -200,7 +213,7 @@ 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:
continue
@@ -331,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:

View File

@@ -15,6 +15,8 @@ from utils.utilities import createTempPluginFolder, deleteTempPluginFolder, calc
# = 1.16.5
def getInstalledPaperMinecraftVersion(localPaperName):
if localPaperName is None:
return False
mcVersionFull = re.search(r'(\d*\.*\d)+', localPaperName)
try:
mcVersion = mcVersionFull.group()
@@ -25,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()
@@ -36,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]
@@ -89,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
@@ -96,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"]
@@ -104,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("└─────┴────────────────────────────────┴──────────────┴──────────────┴───────────────────┘")
@@ -172,8 +219,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)