Added eggcracking method and first progress bar tests

Changes:
- added eggcracking method for plugins
- plugins will be unzipped when they don't have a version in their name and the version will be searched inside the `plugin.yml` file
- added progress bar tests
- changed default paths in config
This commit is contained in:
Neocky 2021-03-18 00:03:07 +01:00
parent e87729f700
commit d7fc68195b
2 changed files with 34 additions and 5 deletions

View File

@ -58,10 +58,10 @@ def createConfig():
config['General'] = {} config['General'] = {}
config['General'][';'] = 'If a local plugin folder exists (True/False): (If False SFTP will be used)' config['General'][';'] = 'If a local plugin folder exists (True/False): (If False SFTP will be used)'
config['General']['LocalPluginFolder'] = 'True' config['General']['LocalPluginFolder'] = 'True'
config['General']['PathToPluginFolder'] = 'C:\\Users\\USER\\Desktop\\plugins' 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'][';_'] = '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']['SeperateDownloadPath'] = 'False'
config['General']['PathToSeperateDownloadPath'] = 'C:\\Users\\USER\\Desktop\\plugins' config['General']['PathToSeperateDownloadPath'] = 'C:/Users/USER/Desktop/plugins'
config['SFTP - Remote Server'] = {} config['SFTP - Remote Server'] = {}
config['SFTP - Remote Server']['Server'] = '0.0.0.0' config['SFTP - Remote Server']['Server'] = '0.0.0.0'

View File

@ -1,7 +1,10 @@
import os import os
import re import re
import io
from zipfile import ZipFile
from urllib.error import HTTPError from urllib.error import HTTPError
from pathlib import Path from pathlib import Path
from rich.progress import track
from utils.consoleoutput import oColors from utils.consoleoutput import oColors
from utils.web_request import doAPIRequest from utils.web_request import doAPIRequest
@ -38,6 +41,10 @@ def getFileVersion(pluginName):
pluginVersion = re.search(r'([\d.]+[.jar]+)', pluginNameFull) pluginVersion = re.search(r'([\d.]+[.jar]+)', pluginNameFull)
pluginVersionFull = pluginVersion.group() pluginVersionFull = pluginVersion.group()
pluginVersionString = pluginVersionFull.replace('.jar', '') pluginVersionString = pluginVersionFull.replace('.jar', '')
if pluginVersionString.endswith('.'):
pluginVersionString = ''
if pluginVersionString == '':
pluginVersionString = eggCrackingJar(pluginNameFull)
return pluginVersionString return pluginVersionString
@ -56,6 +63,29 @@ def compareVersions(plugin_latest_version, pluginVersion):
return plugin_is_outdated return plugin_is_outdated
def eggCrackingJar(localJarFileName):
if not checkConfig().localPluginFolder:
pluginPath = checkConfig().sftp_folderPath
else:
pluginPath = checkConfig().pathToPluginFolder
pathToPluginJar = Path(f"{pluginPath}/{localJarFileName}")
pluginVersion = ''
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
except FileNotFoundError:
pluginVersion = ''
return pluginVersion
def checkInstalledPackage(inputSelectedObject="all"): def checkInstalledPackage(inputSelectedObject="all"):
createPluginList() createPluginList()
if not checkConfig().localPluginFolder: if not checkConfig().localPluginFolder:
@ -68,7 +98,7 @@ def checkInstalledPackage(inputSelectedObject="all"):
print(f"Checking: {inputSelectedObject}") print(f"Checking: {inputSelectedObject}")
print("Index | Name | Installed V. | Latest V. | Update available") print("Index | Name | Installed V. | Latest V. | Update available")
try: try:
for plugin in pluginList: for plugin in track(pluginList, description="Checking plugins" ,transient=True, complete_style="cyan"):
try: try:
fileName = getFileName(plugin) fileName = getFileName(plugin)
fileVersion = getFileVersion(plugin) fileVersion = getFileVersion(plugin)
@ -77,7 +107,6 @@ def checkInstalledPackage(inputSelectedObject="all"):
i += 1 i += 1
continue continue
pluginIdStr = str(pluginId) pluginIdStr = str(pluginId)
if fileVersion == '': if fileVersion == '':
fileVersion = 'N/A' fileVersion = 'N/A'
@ -99,7 +128,7 @@ def checkInstalledPackage(inputSelectedObject="all"):
if pluginIsOutdated == True: if pluginIsOutdated == True:
oldPackages = oldPackages + 1 oldPackages = oldPackages + 1
if inputSelectedObject != "*" and inputSelectedObject != "all": if inputSelectedObject != "*" and inputSelectedObject != "all":
if inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE): if inputSelectedObject == pluginIdStr or re.search(inputSelectedObject, fileName, re.IGNORECASE):
print(f" [{1}]".ljust(8), end='') print(f" [{1}]".ljust(8), end='')