mirror of
https://github.com/Neocky/pluGET.git
synced 2024-04-29 16:12:30 +00:00
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:
parent
3fed1580f8
commit
ddb5f1172e
@ -1,2 +1,4 @@
|
||||
@ECHO OFF
|
||||
py "%~dp0\src\__main__.py"
|
||||
cd "%~dp0"
|
||||
cd src
|
||||
py "__main__.py"
|
@ -1,6 +1,6 @@
|
||||
from utils.consoleoutput import consoleTitle, clearConsole, printMainMenu, oColors
|
||||
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 plugin.plugin_downloader import searchPackage, getSpecificPackage
|
||||
from plugin.plugin_updatechecker import updateInstalledPackage, checkInstalledPackage
|
||||
@ -15,6 +15,5 @@ def mainFunction():
|
||||
createInputLists()
|
||||
printMainMenu()
|
||||
getInput()
|
||||
#outputTest()
|
||||
|
||||
mainFunction()
|
||||
|
@ -1,4 +1,4 @@
|
||||
import os.path
|
||||
import os
|
||||
import sys
|
||||
import configparser
|
||||
|
||||
@ -6,7 +6,10 @@ from utils.consoleoutput import oColors
|
||||
|
||||
|
||||
def checkConfig():
|
||||
configAvailable = os.path.isfile("./config.ini")
|
||||
currentFolder = os.getcwd()
|
||||
os.chdir('..')
|
||||
configAvailable = os.path.isfile("config.ini")
|
||||
|
||||
if not configAvailable:
|
||||
createConfig()
|
||||
print(oColors.brightRed + "Config created. Edit config before executing again!" + oColors.standardWhite)
|
||||
@ -32,19 +35,20 @@ def checkConfig():
|
||||
else:
|
||||
localPluginFolder = False
|
||||
|
||||
os.chdir(currentFolder)
|
||||
return configValues
|
||||
|
||||
|
||||
def createConfig():
|
||||
config = configparser.ConfigParser(allow_no_value=True)
|
||||
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']['PathToPluginFolder'] = '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'] = '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']['Port'] = '22'
|
||||
config['SFTP - Remote Server']['PluginFolderForUpload'] = '.\\plugins'
|
||||
|
@ -1,5 +1,4 @@
|
||||
import sys
|
||||
import time
|
||||
|
||||
from utils.consoleoutput import oColors
|
||||
from utils.utilities import getHelp
|
||||
@ -14,6 +13,7 @@ def createInputLists():
|
||||
'get',
|
||||
'update',
|
||||
'check',
|
||||
'search',
|
||||
'exit',
|
||||
'help',
|
||||
'remove'
|
||||
@ -44,6 +44,9 @@ def handleInput(inputCommand, inputSelectedObject, inputParams):
|
||||
if inputCommand == 'check':
|
||||
checkInstalledPackage(inputSelectedObject)
|
||||
break
|
||||
if inputCommand == 'search':
|
||||
searchPackage(inputSelectedObject)
|
||||
break
|
||||
if inputCommand == 'exit':
|
||||
sys.exit()
|
||||
if inputCommand == 'help':
|
||||
@ -67,24 +70,4 @@ def getInput():
|
||||
print(oColors.brightRed + "Wrong input! Use: > *command* *selectedObject* *optionalParams*" + oColors.standardWhite)
|
||||
|
||||
inputParams = inputParams[0] if inputParams else None
|
||||
#print(inputCommand)
|
||||
#print(inputSelectedObject)
|
||||
#print(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...")
|
||||
|
@ -40,7 +40,7 @@ def sftp_upload_file(sftp, itemPath):
|
||||
sftp.put(itemPath)
|
||||
|
||||
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)
|
||||
sftp.close()
|
||||
|
||||
@ -51,7 +51,7 @@ def sftp_listAll(sftp):
|
||||
installedPlugins = sftp.listdir()
|
||||
|
||||
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:
|
||||
return installedPlugins
|
||||
|
@ -31,14 +31,6 @@ def handleRegexPackageName(packageNameFull):
|
||||
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):
|
||||
if packageVersion == None or packageVersion == '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"
|
||||
packageName = doAPIRequest(url)
|
||||
i = 1
|
||||
print("Index / Name / Description / Downloads")
|
||||
print(f"Searching: {ressourceName}")
|
||||
print("Index | Name | Description | Downloads")
|
||||
for ressource in packageName:
|
||||
pName = ressource["name"]
|
||||
newName = handleRegexPackageName(pName)
|
||||
pTag = ressource["tag"]
|
||||
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
|
||||
|
||||
ressourceSelected = int(input("Select your wanted Ressource: "))
|
||||
ressourceSelected = int(input("Select your wanted Ressource (Index)(0 to exit): "))
|
||||
if ressourceSelected != 0:
|
||||
ressourceSelected = ressourceSelected - 1
|
||||
#fileInfo = packageName[ressourceSelected]["file"]
|
||||
#packageUrl = fileInfo["url"]
|
||||
ressourceId = packageName[ressourceSelected]["id"]
|
||||
if not checkConfig().localPluginFolder:
|
||||
getSpecificPackage(ressourceId, checkConfig().sftp_folderPath)
|
||||
@ -94,7 +90,7 @@ def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'):
|
||||
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}/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)
|
||||
filesize = remotefile.info()['Content-Length']
|
||||
@ -116,7 +112,6 @@ def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'):
|
||||
packageNameNew = handleRegexPackageName(packageName)
|
||||
versionId = getVersionID(ressourceId, inputPackageVersion)
|
||||
packageVersion = getVersionName(ressourceId, versionId)
|
||||
#packageVersion = getlatestVersion(ressourceId)
|
||||
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
|
||||
downloadPackagePath = f"{downloadPath}\\{packageDownloadName}"
|
||||
if checkConfig().localPluginFolder:
|
||||
@ -145,7 +140,3 @@ def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'):
|
||||
except HTTPError as err:
|
||||
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
|
||||
|
@ -18,7 +18,7 @@ def addToPluginList(pluginId, versionId, plugin_latest_version, plugin_is_outdat
|
||||
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
|
||||
pluginVersion = re.search(r'([\d.]+[.jar]+)', pluginNameFull)
|
||||
try:
|
||||
@ -27,7 +27,8 @@ def getFileName(pluginName): # TODO delete end of pluginName -v like BossShopPro
|
||||
pluginVersionFull = pluginVersion
|
||||
pluginNameOnlyy = pluginNameFull.replace(pluginVersionFull, '')
|
||||
pluginNameOnly = re.sub(r'(\-$)', '', pluginNameOnlyy)
|
||||
return pluginNameOnly
|
||||
pluginNameOnlyy = re.sub(r'(\-v$)', '', pluginNameOnly)
|
||||
return pluginNameOnlyy
|
||||
|
||||
|
||||
def getFileVersion(pluginName):
|
||||
@ -217,7 +218,7 @@ def getInstalledPlugin(localFileName, localFileVersion):
|
||||
packageVersions = doAPIRequest(url2)
|
||||
for updates in packageVersions:
|
||||
updateVersion = updates["name"]
|
||||
if localFileVersion == updateVersion:
|
||||
if localFileVersion in updateVersion:
|
||||
plugin_match_found = True
|
||||
pluginID = pID
|
||||
updateId = updates["id"]
|
||||
|
@ -1,9 +1,9 @@
|
||||
# Handles the console output
|
||||
from os import system
|
||||
from os import name
|
||||
|
||||
|
||||
def consoleTitle():
|
||||
system("title " + "pluGET │ by Neocky")
|
||||
system("title " + "pluGET │ By Neocky")
|
||||
|
||||
|
||||
def clearConsole():
|
||||
@ -72,7 +72,7 @@ def printLogo():
|
||||
oColors.standardWhite)
|
||||
print()
|
||||
print()
|
||||
print(oColors.brightYellow + " [" + oColors.darkMagenta + "by Neocky" +
|
||||
print(oColors.brightYellow + " [" + oColors.darkMagenta + "By Neocky" +
|
||||
oColors.brightYellow + "] " + oColors.standardWhite)
|
||||
print()
|
||||
|
||||
@ -84,9 +84,3 @@ def printHorizontalLine():
|
||||
def printMainMenu():
|
||||
printLogo()
|
||||
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()
|
||||
|
@ -6,6 +6,7 @@ import requests
|
||||
|
||||
from utils.consoleoutput import oColors
|
||||
from handlers.handle_config import checkConfig
|
||||
from handlers.handle_sftp import createSFTPConnection
|
||||
|
||||
|
||||
def getHelp():
|
||||
@ -45,12 +46,13 @@ def apiTest():
|
||||
def check_requirements():
|
||||
apiTest()
|
||||
check_local_plugin_folder()
|
||||
# sftp test
|
||||
if not checkConfig().localPluginFolder:
|
||||
createSFTPConnection()
|
||||
|
||||
|
||||
def createTempPluginFolder():
|
||||
tempPluginFolder = ".\\plugins"
|
||||
if not os.path.isdir(tempPluginFolder):
|
||||
#print(oColors.brightRed + "Plugin folder coulnd*t be found. Creating one..." + oColors.standardWhite)
|
||||
try:
|
||||
os.mkdir(tempPluginFolder)
|
||||
except OSError:
|
||||
|
Loading…
Reference in New Issue
Block a user