Made config path correct; Deleted unnecessary stuff; Beautified outpout; Plugin version now correct;

Changes:
- config path will always be correct
- deleted unnexessary stuff
- plugin version will display now correct
- changed some formating
- created SFTP check before launching
This commit is contained in:
Neocky 2021-03-13 22:09:32 +01:00
parent 3fed1580f8
commit ddb5f1172e
9 changed files with 45 additions and 69 deletions

View File

@ -1,2 +1,4 @@
@ECHO OFF @ECHO OFF
py "%~dp0\src\__main__.py" cd "%~dp0"
cd src
py "__main__.py"

View File

@ -1,6 +1,6 @@
from utils.consoleoutput import consoleTitle, clearConsole, printMainMenu, oColors from utils.consoleoutput import consoleTitle, clearConsole, printMainMenu, oColors
from utils.utilities import getHelp, check_requirements from utils.utilities import getHelp, check_requirements
from handlers.handle_input import createInputLists, getInput, outputTest from handlers.handle_input import createInputLists, getInput
from handlers.handle_config import checkConfig from handlers.handle_config import checkConfig
from plugin.plugin_downloader import searchPackage, getSpecificPackage from plugin.plugin_downloader import searchPackage, getSpecificPackage
from plugin.plugin_updatechecker import updateInstalledPackage, checkInstalledPackage from plugin.plugin_updatechecker import updateInstalledPackage, checkInstalledPackage
@ -15,6 +15,5 @@ def mainFunction():
createInputLists() createInputLists()
printMainMenu() printMainMenu()
getInput() getInput()
#outputTest()
mainFunction() mainFunction()

View File

@ -1,4 +1,4 @@
import os.path import os
import sys import sys
import configparser import configparser
@ -6,7 +6,10 @@ from utils.consoleoutput import oColors
def checkConfig(): def checkConfig():
configAvailable = os.path.isfile("./config.ini") currentFolder = os.getcwd()
os.chdir('..')
configAvailable = os.path.isfile("config.ini")
if not configAvailable: if not configAvailable:
createConfig() createConfig()
print(oColors.brightRed + "Config created. Edit config before executing again!" + oColors.standardWhite) print(oColors.brightRed + "Config created. Edit config before executing again!" + oColors.standardWhite)
@ -32,19 +35,20 @@ def checkConfig():
else: else:
localPluginFolder = False localPluginFolder = False
os.chdir(currentFolder)
return configValues return configValues
def createConfig(): def createConfig():
config = configparser.ConfigParser(allow_no_value=True) config = configparser.ConfigParser(allow_no_value=True)
config['General'] = {} config['General'] = {}
config['General'][';'] = 'If a local plugin folder exists (True/False): (If False use SFTP)' 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['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'
config['SFTP - Remote Server']['Username'] = 'user' config['SFTP - Remote Server']['Username'] = 'user'
config['SFTP - Remote Server']['Password'] = 'longpassword' 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'][';'] = 'Normally you won*t need to change anything below this line'
config['SFTP - Remote Server']['Port'] = '22' config['SFTP - Remote Server']['Port'] = '22'
config['SFTP - Remote Server']['PluginFolderForUpload'] = '.\\plugins' config['SFTP - Remote Server']['PluginFolderForUpload'] = '.\\plugins'

View File

@ -1,5 +1,4 @@
import sys import sys
import time
from utils.consoleoutput import oColors from utils.consoleoutput import oColors
from utils.utilities import getHelp from utils.utilities import getHelp
@ -14,6 +13,7 @@ def createInputLists():
'get', 'get',
'update', 'update',
'check', 'check',
'search',
'exit', 'exit',
'help', 'help',
'remove' 'remove'
@ -44,6 +44,9 @@ def handleInput(inputCommand, inputSelectedObject, inputParams):
if inputCommand == 'check': if inputCommand == 'check':
checkInstalledPackage(inputSelectedObject) checkInstalledPackage(inputSelectedObject)
break break
if inputCommand == 'search':
searchPackage(inputSelectedObject)
break
if inputCommand == 'exit': if inputCommand == 'exit':
sys.exit() sys.exit()
if inputCommand == 'help': if inputCommand == 'help':
@ -67,24 +70,4 @@ def getInput():
print(oColors.brightRed + "Wrong input! Use: > *command* *selectedObject* *optionalParams*" + oColors.standardWhite) print(oColors.brightRed + "Wrong input! Use: > *command* *selectedObject* *optionalParams*" + oColors.standardWhite)
inputParams = inputParams[0] if inputParams else None inputParams = inputParams[0] if inputParams else None
#print(inputCommand)
#print(inputSelectedObject)
#print(inputParams)
handleInput(inputCommand, inputSelectedObject, inputParams) handleInput(inputCommand, inputSelectedObject, inputParams)
# only for testing purposes
def outputTest():
print("Hello world")
print("Waiting still seconds: 5", end='\r')
time.sleep(1)
print("Waiting still seconds: 4", end='\r')
time.sleep(1)
print("Waiting still seconds: 3", end='\r')
time.sleep(1)
print("Waiting still seconds: 2", end='\r')
time.sleep(1)
print("Waiting still seconds: 1", end='\r')
time.sleep(1)
print("Done ✅☑✔ ")
input("Press key to end program...")

View File

@ -40,7 +40,7 @@ def sftp_upload_file(sftp, itemPath):
sftp.put(itemPath) sftp.put(itemPath)
except FileNotFoundError: except FileNotFoundError:
print(oColors.brightRed + "The *plugins* folder couldn*t be found on the remote host!" + oColors.standardWhite) 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 + "Aborting installation." + oColors.standardWhite)
sftp.close() sftp.close()
@ -51,7 +51,7 @@ def sftp_listAll(sftp):
installedPlugins = sftp.listdir() installedPlugins = sftp.listdir()
except FileNotFoundError: except FileNotFoundError:
print(oColors.brightRed + "The *plugins* folder couldn*t be found on the remote host!" + oColors.standardWhite) print(oColors.brightRed + "The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
try: try:
return installedPlugins return installedPlugins

View File

@ -31,14 +31,6 @@ def handleRegexPackageName(packageNameFull):
return packageNameOnly return packageNameOnly
# TODO ununsed function
def getlatestVersion(packageId):
url = f"https://api.spiget.org/v2/resources/{packageId}/versions/latest"
response = doAPIRequest(url)
packageVersion = response["name"]
return packageVersion
def getVersionID(packageId, packageVersion): def getVersionID(packageId, packageVersion):
if packageVersion == None or packageVersion == 'latest': if packageVersion == None or packageVersion == 'latest':
url = f"https://api.spiget.org/v2/resources/{packageId}/versions/latest" url = f"https://api.spiget.org/v2/resources/{packageId}/versions/latest"
@ -68,18 +60,22 @@ def searchPackage(ressourceName):
url = f"https://api.spiget.org/v2/search/resources/{ressourceName}?field=name" url = f"https://api.spiget.org/v2/search/resources/{ressourceName}?field=name"
packageName = doAPIRequest(url) packageName = doAPIRequest(url)
i = 1 i = 1
print("Index / Name / Description / Downloads") print(f"Searching: {ressourceName}")
print("Index | Name | Description | Downloads")
for ressource in packageName: for ressource in packageName:
pName = ressource["name"] pName = ressource["name"]
newName = handleRegexPackageName(pName)
pTag = ressource["tag"] pTag = ressource["tag"]
pDownloads = ressource["downloads"] pDownloads = ressource["downloads"]
print(f" [{i}] {pName} / {pTag}/ {pDownloads}") print(f" [{i}]".ljust(8), end='')
print(f"{newName}".ljust(30), end='')
print(f"{pTag}".ljust(120), end='')
print(f"{pDownloads}".ljust(7))
i = i + 1 i = i + 1
ressourceSelected = int(input("Select your wanted Ressource: ")) ressourceSelected = int(input("Select your wanted Ressource (Index)(0 to exit): "))
if ressourceSelected != 0:
ressourceSelected = ressourceSelected - 1 ressourceSelected = ressourceSelected - 1
#fileInfo = packageName[ressourceSelected]["file"]
#packageUrl = fileInfo["url"]
ressourceId = packageName[ressourceSelected]["id"] ressourceId = packageName[ressourceSelected]["id"]
if not checkConfig().localPluginFolder: if not checkConfig().localPluginFolder:
getSpecificPackage(ressourceId, checkConfig().sftp_folderPath) getSpecificPackage(ressourceId, checkConfig().sftp_folderPath)
@ -94,7 +90,7 @@ def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'):
print(oColors.brightRed + "Reverting to latest version." + oColors.standardWhite) print(oColors.brightRed + "Reverting to latest version." + oColors.standardWhite)
url = f"https://api.spiget.org/v2/resources/{ressourceId}/download" 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 #url = f"https://api.spiget.org/v2/resources/{ressourceId}/versions/latest/download" #throws 403 forbidden error...cloudflare :(
remotefile = urllib.request.urlopen(url) remotefile = urllib.request.urlopen(url)
filesize = remotefile.info()['Content-Length'] filesize = remotefile.info()['Content-Length']
@ -116,7 +112,6 @@ def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'):
packageNameNew = handleRegexPackageName(packageName) packageNameNew = handleRegexPackageName(packageName)
versionId = getVersionID(ressourceId, inputPackageVersion) versionId = getVersionID(ressourceId, inputPackageVersion)
packageVersion = getVersionName(ressourceId, versionId) packageVersion = getVersionName(ressourceId, versionId)
#packageVersion = getlatestVersion(ressourceId)
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar" packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
downloadPackagePath = f"{downloadPath}\\{packageDownloadName}" downloadPackagePath = f"{downloadPath}\\{packageDownloadName}"
if checkConfig().localPluginFolder: if checkConfig().localPluginFolder:
@ -145,7 +140,3 @@ def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'):
except HTTPError as err: except HTTPError as err:
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite) print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
# get latest update > https://api.spiget.org/v2/resources/28140/updates/latest
# this also > https://api.spiget.org/v2/resources/28140/versions/latest
# get latest download with correct name > https://api.spiget.org/v2/resources/28140/versions/latest/download cloudflare protected
# query for a plugin https://api.spiget.org/v2/search/resources/luckperms?field=name

View File

@ -18,7 +18,7 @@ def addToPluginList(pluginId, versionId, plugin_latest_version, plugin_is_outdat
INSTALLEDPLUGINLIST.append([pluginId, versionId, plugin_latest_version, plugin_is_outdated]) INSTALLEDPLUGINLIST.append([pluginId, versionId, plugin_latest_version, plugin_is_outdated])
def getFileName(pluginName): # TODO delete end of pluginName -v like BossShopPro-v def getFileName(pluginName):
pluginNameFull = pluginName pluginNameFull = pluginName
pluginVersion = re.search(r'([\d.]+[.jar]+)', pluginNameFull) pluginVersion = re.search(r'([\d.]+[.jar]+)', pluginNameFull)
try: try:
@ -27,7 +27,8 @@ def getFileName(pluginName): # TODO delete end of pluginName -v like BossShopPro
pluginVersionFull = pluginVersion pluginVersionFull = pluginVersion
pluginNameOnlyy = pluginNameFull.replace(pluginVersionFull, '') pluginNameOnlyy = pluginNameFull.replace(pluginVersionFull, '')
pluginNameOnly = re.sub(r'(\-$)', '', pluginNameOnlyy) pluginNameOnly = re.sub(r'(\-$)', '', pluginNameOnlyy)
return pluginNameOnly pluginNameOnlyy = re.sub(r'(\-v$)', '', pluginNameOnly)
return pluginNameOnlyy
def getFileVersion(pluginName): def getFileVersion(pluginName):
@ -217,7 +218,7 @@ def getInstalledPlugin(localFileName, localFileVersion):
packageVersions = doAPIRequest(url2) packageVersions = doAPIRequest(url2)
for updates in packageVersions: for updates in packageVersions:
updateVersion = updates["name"] updateVersion = updates["name"]
if localFileVersion == updateVersion: if localFileVersion in updateVersion:
plugin_match_found = True plugin_match_found = True
pluginID = pID pluginID = pID
updateId = updates["id"] updateId = updates["id"]

View File

@ -1,9 +1,9 @@
# Handles the console output
from os import system from os import system
from os import name from os import name
def consoleTitle(): def consoleTitle():
system("title " + "pluGET │ by Neocky") system("title " + "pluGET │ By Neocky")
def clearConsole(): def clearConsole():
@ -72,7 +72,7 @@ def printLogo():
oColors.standardWhite) oColors.standardWhite)
print() print()
print() print()
print(oColors.brightYellow + " [" + oColors.darkMagenta + "by Neocky" + print(oColors.brightYellow + " [" + oColors.darkMagenta + "By Neocky" +
oColors.brightYellow + "] " + oColors.standardWhite) oColors.brightYellow + "] " + oColors.standardWhite)
print() print()
@ -84,9 +84,3 @@ def printHorizontalLine():
def printMainMenu(): def printMainMenu():
printLogo() printLogo()
printHorizontalLine() printHorizontalLine()
#print(" [1] Download a specific package")
#print(" [2] Get update info of package")
#print(" [3] Search for a plugin")
#print(" [4] Download latest version of package")
#print(" [5] Check update for installed plugins")
#print()

View File

@ -6,6 +6,7 @@ import requests
from utils.consoleoutput import oColors from utils.consoleoutput import oColors
from handlers.handle_config import checkConfig from handlers.handle_config import checkConfig
from handlers.handle_sftp import createSFTPConnection
def getHelp(): def getHelp():
@ -45,12 +46,13 @@ def apiTest():
def check_requirements(): def check_requirements():
apiTest() apiTest()
check_local_plugin_folder() check_local_plugin_folder()
# sftp test if not checkConfig().localPluginFolder:
createSFTPConnection()
def createTempPluginFolder(): def createTempPluginFolder():
tempPluginFolder = ".\\plugins" tempPluginFolder = ".\\plugins"
if not os.path.isdir(tempPluginFolder): if not os.path.isdir(tempPluginFolder):
#print(oColors.brightRed + "Plugin folder coulnd*t be found. Creating one..." + oColors.standardWhite)
try: try:
os.mkdir(tempPluginFolder) os.mkdir(tempPluginFolder)
except OSError: except OSError: