mirror of
https://github.com/Neocky/pluGET.git
synced 2024-04-29 16:12:30 +00:00
commit
60a41015e6
@ -11,16 +11,17 @@ class configurationValues:
|
|||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.sections()
|
config.sections()
|
||||||
config.read("config.ini")
|
config.read("config.ini")
|
||||||
localPluginFolder = config['General']['LocalPluginFolder']
|
localPluginFolder = config['General']['UseLocalPluginFolder']
|
||||||
self.pathToPluginFolder = Path(config['General']['PathToPluginFolder'])
|
self.pathToPluginFolder = Path(config['Local - This Machine']['PathToPluginFolder'])
|
||||||
seperateDownloadPath = config['General']['SeperateDownloadPath']
|
seperateDownloadPath = config['Local - This Machine']['SeperateDownloadPath']
|
||||||
self.pathToSeperateDownloadPath = Path(config['General']['PathToSeperateDownloadPath'])
|
self.pathToSeperateDownloadPath = Path(config['Local - This Machine']['PathToSeperateDownloadPath'])
|
||||||
|
|
||||||
self.sftp_server = config['SFTP - Remote Server']['Server']
|
self.sftp_server = config['SFTP - Remote Server']['Server']
|
||||||
self.sftp_user = config['SFTP - Remote Server']['Username']
|
self.sftp_user = config['SFTP - Remote Server']['Username']
|
||||||
self.sftp_password = config['SFTP - Remote Server']['Password']
|
self.sftp_password = config['SFTP - Remote Server']['Password']
|
||||||
sftp_port = config['SFTP - Remote Server']['Port']
|
sftp_port = config['SFTP - Remote Server']['SFTPPort']
|
||||||
self.sftp_folderPath = config['SFTP - Remote Server']['PluginFolderOnServer']
|
self.sftp_folderPath = config['SFTP - Remote Server']['PluginFolderOnServer']
|
||||||
|
sftp_useSftp = config['SFTP - Remote Server']['USE_SFTP']
|
||||||
sftp_seperateDownloadPath = config['SFTP - Remote Server']['SeperateDownloadPath']
|
sftp_seperateDownloadPath = config['SFTP - Remote Server']['SeperateDownloadPath']
|
||||||
self.sftp_pathToSeperateDownloadPath = config['SFTP - Remote Server']['PathToSeperateDownloadPath']
|
self.sftp_pathToSeperateDownloadPath = config['SFTP - Remote Server']['PathToSeperateDownloadPath']
|
||||||
|
|
||||||
@ -40,6 +41,11 @@ class configurationValues:
|
|||||||
else:
|
else:
|
||||||
self.sftp_seperateDownloadPath = False
|
self.sftp_seperateDownloadPath = False
|
||||||
|
|
||||||
|
if sftp_useSftp == 'True':
|
||||||
|
self.sftp_useSftp = True
|
||||||
|
else:
|
||||||
|
self.sftp_useSftp = False
|
||||||
|
|
||||||
|
|
||||||
def checkConfig():
|
def checkConfig():
|
||||||
configAvailable = os.path.isfile("config.ini")
|
configAvailable = os.path.isfile("config.ini")
|
||||||
@ -53,23 +59,28 @@ def checkConfig():
|
|||||||
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 SFTP will be used)'
|
config['General'][';'] = 'If a local plugin folder exists (True/False) (If False SFTP/FTP will be used):'
|
||||||
config['General']['LocalPluginFolder'] = 'True'
|
config['General']['UseLocalPluginFolder'] = 'True'
|
||||||
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['Local - This Machine'] = {}
|
||||||
config['General']['SeperateDownloadPath'] = 'False'
|
config['Local - This Machine']['PathToPluginFolder'] = 'C:/Users/USER/Desktop/plugins'
|
||||||
config['General']['PathToSeperateDownloadPath'] = 'C:/Users/USER/Desktop/plugins'
|
config['Local - This Machine'][';'] = 'For a different folder to store the updated plugins change to (True/False) and the path below'
|
||||||
|
config['Local - This Machine']['SeperateDownloadPath'] = 'False'
|
||||||
|
config['Local - This Machine']['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'
|
||||||
config['SFTP - Remote Server']['Username'] = 'user'
|
config['SFTP - Remote Server']['Username'] = 'user'
|
||||||
config['SFTP - Remote Server']['Password'] = 'password'
|
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'][';'] = 'If a different Port for SFTP needs to be used (Works only for SFTP)'
|
||||||
config['SFTP - Remote Server']['Port'] = '22'
|
config['SFTP - Remote Server']['SFTPPort'] = '22'
|
||||||
config['SFTP - Remote Server']['PluginFolderOnServer'] = '.\\plugins'
|
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'][';_'] = 'If you want a different folder to store the updated plugins change to (True/False) and the path below'
|
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']['SeperateDownloadPath'] = 'False'
|
||||||
config['SFTP - Remote Server']['PathToSeperateDownloadPath'] = '.\\plugins'
|
config['SFTP - Remote Server']['PathToSeperateDownloadPath'] = './plugins'
|
||||||
|
|
||||||
|
|
||||||
with open('config.ini', 'w') as configfile:
|
with open('config.ini', 'w') as configfile:
|
||||||
|
95
src/handlers/handle_ftp.py
Normal file
95
src/handlers/handle_ftp.py
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import ftplib
|
||||||
|
|
||||||
|
from utils.consoleoutput import oColors
|
||||||
|
from handlers.handle_config import configurationValues
|
||||||
|
|
||||||
|
|
||||||
|
def createFTPConnection():
|
||||||
|
configValues = configurationValues()
|
||||||
|
ftp = ftplib.FTP(configValues.sftp_server, user=configValues.sftp_user, \
|
||||||
|
passwd=configValues.sftp_password)
|
||||||
|
try:
|
||||||
|
return ftp
|
||||||
|
except UnboundLocalError:
|
||||||
|
print(oColors.brightRed + "[FTP]: Check your config.ini!" + oColors.standardWhite)
|
||||||
|
print(oColors.brightRed + "Exiting program..." + oColors.standardWhite)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
def ftp_showPlugins(ftp):
|
||||||
|
configValues = configurationValues()
|
||||||
|
ftp.cwd(configValues.sftp_folderPath)
|
||||||
|
for attr in ftp.dir():
|
||||||
|
print(attr.filename, attr)
|
||||||
|
|
||||||
|
|
||||||
|
def ftp_upload_file(ftp, itemPath):
|
||||||
|
configValues = configurationValues()
|
||||||
|
try:
|
||||||
|
ftp.cwd(configValues.sftp_folderPath)
|
||||||
|
itemPath = os.path.relpath(itemPath, 'TempSFTPFolder/')
|
||||||
|
itemPath = str(itemPath)
|
||||||
|
currentDirectory = os.getcwd()
|
||||||
|
os.chdir('TempSFTPFolder')
|
||||||
|
with open (itemPath, 'rb') as plugin_file:
|
||||||
|
ftp.storbinary('STOR '+ str(itemPath), plugin_file)
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(oColors.brightRed + "[FTP]: The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||||
|
print(oColors.brightRed + "[FTP]: Aborting uploading." + oColors.standardWhite)
|
||||||
|
os.chdir(currentDirectory)
|
||||||
|
ftp.close()
|
||||||
|
|
||||||
|
|
||||||
|
def ftp_upload_server_jar(ftp, itemPath):
|
||||||
|
try:
|
||||||
|
print(f"itempath: {itemPath}")
|
||||||
|
ftp.cwd('.')
|
||||||
|
itemPath = os.path.relpath(itemPath, 'TempSFTPFolder/')
|
||||||
|
itemPath = str(itemPath)
|
||||||
|
currentDirectory = os.getcwd()
|
||||||
|
os.chdir('TempSFTPFolder')
|
||||||
|
with open (itemPath, 'rb') as server_jar:
|
||||||
|
ftp.storbinary('STOR '+ str(itemPath), server_jar)
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(oColors.brightRed + "[FTP]: The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||||
|
print(oColors.brightRed + "[FTP]: Aborting uploading." + oColors.standardWhite)
|
||||||
|
os.chdir(currentDirectory)
|
||||||
|
ftp.close()
|
||||||
|
|
||||||
|
|
||||||
|
def ftp_listAll(ftp):
|
||||||
|
configValues = configurationValues()
|
||||||
|
try:
|
||||||
|
ftp.cwd(configValues.sftp_folderPath)
|
||||||
|
installedPlugins = ftp.nlst()
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(oColors.brightRed + "[FTP]: The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||||
|
|
||||||
|
try:
|
||||||
|
return installedPlugins
|
||||||
|
except UnboundLocalError:
|
||||||
|
print(oColors.brightRed + "[FTP]: No plugins were found." + oColors.standardWhite)
|
||||||
|
|
||||||
|
|
||||||
|
def ftp_listFilesInServerRoot(ftp):
|
||||||
|
try:
|
||||||
|
ftp.cwd('.')
|
||||||
|
filesInServerRoot = ftp.nlst()
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(oColors.brightRed + "[FTP]: The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||||
|
|
||||||
|
try:
|
||||||
|
return filesInServerRoot
|
||||||
|
except UnboundLocalError:
|
||||||
|
print(oColors.brightRed + "[FTP]: No Serverjar was found." + oColors.standardWhite)
|
||||||
|
|
||||||
|
|
||||||
|
def ftp_downloadFile(ftp, downloadPath, fileToDownload):
|
||||||
|
configValues = configurationValues()
|
||||||
|
ftp.cwd(configValues.sftp_folderPath)
|
||||||
|
filedata = open(downloadPath,'wb')
|
||||||
|
ftp.retrbinary('RETR '+fileToDownload, filedata.write)
|
||||||
|
filedata.close()
|
||||||
|
ftp.quit()
|
@ -82,18 +82,24 @@ def handleInput(inputCommand, inputSelectedObject, inputParams):
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print(oColors.brightRed + "Error: Command not found. Please try again. :(" + oColors.standardWhite)
|
print(oColors.brightRed + "Error: Command not found. Please try again. :(" + oColors.standardWhite)
|
||||||
|
print(oColors.brightRed + "Use: '" + oColors.standardWhite +"help command" + oColors.brightRed +"' to get all available commands" + oColors.standardWhite)
|
||||||
getInput()
|
getInput()
|
||||||
getInput()
|
getInput()
|
||||||
|
|
||||||
|
|
||||||
def getInput():
|
def getInput():
|
||||||
|
inputCommand = None
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
inputCommand, inputSelectedObject, *inputParams = input("pluGET >> ").split()
|
inputCommand, inputSelectedObject, *inputParams = input("pluGET >> ").split()
|
||||||
break
|
break
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
if inputCommand == None:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
print(oColors.brightRed + "Wrong input! Use: > 'command' 'selectedObject' [optionalParams]" + oColors.standardWhite)
|
print(oColors.brightRed + "Wrong input! Use: > 'command' 'selectedObject' [optionalParams]" + oColors.standardWhite)
|
||||||
print(oColors.brightRed + "Use: '" + oColors.standardWhite +"help command" + oColors.brightRed +"' to get all available commands" + oColors.standardWhite)
|
print(oColors.brightRed + "Use: '" + oColors.standardWhite +"help command" + oColors.brightRed +"' to get all available commands" + oColors.standardWhite)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
sys.exit()
|
||||||
inputParams = inputParams[0] if inputParams else None
|
inputParams = inputParams[0] if inputParams else None
|
||||||
handleInput(inputCommand, inputSelectedObject, inputParams)
|
handleInput(inputCommand, inputSelectedObject, inputParams)
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
import pysftp
|
import pysftp
|
||||||
import paramiko
|
import paramiko
|
||||||
|
|
||||||
from utils.consoleoutput import oColors
|
from utils.consoleoutput import oColors
|
||||||
from handlers.handle_config import checkConfig
|
from handlers.handle_config import configurationValues
|
||||||
|
|
||||||
|
|
||||||
def createSFTPConnection():
|
def createSFTPConnection():
|
||||||
|
configValues = configurationValues()
|
||||||
cnopts = pysftp.CnOpts()
|
cnopts = pysftp.CnOpts()
|
||||||
cnopts.hostkeys = None # TODO fix this
|
cnopts.hostkeys = None # TODO fix this
|
||||||
try:
|
try:
|
||||||
sftp = pysftp.Connection(checkConfig().sftp_server, username=checkConfig().sftp_user, \
|
sftp = pysftp.Connection(configValues.sftp_server, username=configValues.sftp_user, \
|
||||||
password=checkConfig().sftp_password, port=checkConfig().sftp_port, cnopts=cnopts)
|
password=configValues.sftp_password, port=configValues.sftp_port, cnopts=cnopts)
|
||||||
except paramiko.ssh_exception.AuthenticationException:
|
except paramiko.ssh_exception.AuthenticationException:
|
||||||
print(oColors.brightRed + "[SFTP]: Wrong Username/Password" + oColors.standardWhite)
|
print(oColors.brightRed + "[SFTP]: Wrong Username/Password" + oColors.standardWhite)
|
||||||
except paramiko.ssh_exception.SSHException:
|
except paramiko.ssh_exception.SSHException:
|
||||||
@ -30,18 +32,14 @@ def sftp_showPlugins(sftp):
|
|||||||
print(attr.filename, attr)
|
print(attr.filename, attr)
|
||||||
|
|
||||||
|
|
||||||
def sftp_cdPluginDir(sftp):
|
|
||||||
sftp.cd('plugins')
|
|
||||||
|
|
||||||
|
|
||||||
def sftp_upload_file(sftp, itemPath):
|
def sftp_upload_file(sftp, itemPath):
|
||||||
try:
|
try:
|
||||||
sftp.chdir('plugins')
|
sftp.chdir('plugins')
|
||||||
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 + "[SFTP]: The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||||
print(oColors.brightRed + "Aborting installation." + oColors.standardWhite)
|
print(oColors.brightRed + "[SFTP]: Aborting uploading." + oColors.standardWhite)
|
||||||
sftp.close()
|
sftp.close()
|
||||||
|
|
||||||
|
|
||||||
@ -49,10 +47,9 @@ def sftp_upload_server_jar(sftp, itemPath):
|
|||||||
try:
|
try:
|
||||||
sftp.chdir('.')
|
sftp.chdir('.')
|
||||||
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 + "[SFTP]: The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||||
print(oColors.brightRed + "Aborting installation." + oColors.standardWhite)
|
print(oColors.brightRed + "[SFTP]: Aborting uploading." + oColors.standardWhite)
|
||||||
sftp.close()
|
sftp.close()
|
||||||
|
|
||||||
|
|
||||||
@ -60,25 +57,33 @@ def sftp_listAll(sftp):
|
|||||||
try:
|
try:
|
||||||
sftp.chdir('plugins')
|
sftp.chdir('plugins')
|
||||||
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 + "[SFTP]: The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return installedPlugins
|
return installedPlugins
|
||||||
except UnboundLocalError:
|
except UnboundLocalError:
|
||||||
print(oColors.brightRed + "No plugins were found." + oColors.standardWhite)
|
print(oColors.brightRed + "[SFTP]: No plugins were found." + oColors.standardWhite)
|
||||||
|
|
||||||
|
|
||||||
def sftp_listFilesInServerRoot(sftp):
|
def sftp_listFilesInServerRoot(sftp):
|
||||||
try:
|
try:
|
||||||
#sftp.chdir('plugins')
|
|
||||||
filesInServerRoot = sftp.listdir()
|
filesInServerRoot = sftp.listdir()
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print(oColors.brightRed + "The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
print(oColors.brightRed + "[SFTP]: The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return filesInServerRoot
|
return filesInServerRoot
|
||||||
except UnboundLocalError:
|
except UnboundLocalError:
|
||||||
print(oColors.brightRed + "No Serverjar was found." + oColors.standardWhite)
|
print(oColors.brightRed + "[SFTP]: No Serverjar was found." + oColors.standardWhite)
|
||||||
|
|
||||||
|
|
||||||
|
def sftp_downloadFile(sftp, downloadPath, fileToDownload):
|
||||||
|
configValues = configurationValues()
|
||||||
|
sftp.cwd(configValues.sftp_folderPath)
|
||||||
|
currentDirectory = os.getcwd()
|
||||||
|
os.chdir('TempSFTPFolder')
|
||||||
|
sftp.get(fileToDownload)
|
||||||
|
sftp.close()
|
||||||
|
os.chdir(currentDirectory)
|
||||||
|
|
@ -7,7 +7,8 @@ from utils.consoleoutput import oColors
|
|||||||
from utils.web_request import doAPIRequest
|
from utils.web_request import doAPIRequest
|
||||||
from utils.utilities import createTempPluginFolder, deleteTempPluginFolder, calculateFileSizeKb, calculateFileSizeMb
|
from utils.utilities import createTempPluginFolder, deleteTempPluginFolder, calculateFileSizeKb, calculateFileSizeMb
|
||||||
from handlers.handle_config import configurationValues
|
from handlers.handle_config import configurationValues
|
||||||
from handlers.handle_sftp import sftp_upload_file, sftp_cdPluginDir, createSFTPConnection
|
from handlers.handle_sftp import sftp_upload_file, createSFTPConnection
|
||||||
|
from handlers.handle_ftp import ftp_upload_file, createFTPConnection
|
||||||
|
|
||||||
|
|
||||||
def handleRegexPackageName(packageNameFull):
|
def handleRegexPackageName(packageNameFull):
|
||||||
@ -98,6 +99,10 @@ def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'):
|
|||||||
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...cloudflare :(
|
#url = f"https://api.spiget.org/v2/resources/{ressourceId}/versions/latest/download" #throws 403 forbidden error...cloudflare :(
|
||||||
|
|
||||||
|
urrlib_opener = urllib.request.build_opener()
|
||||||
|
urrlib_opener.addheaders = [('User-agent', 'pluGET/1.0')]
|
||||||
|
urllib.request.install_opener(urrlib_opener)
|
||||||
|
|
||||||
remotefile = urllib.request.urlopen(url)
|
remotefile = urllib.request.urlopen(url)
|
||||||
filesize = remotefile.info()['Content-Length']
|
filesize = remotefile.info()['Content-Length']
|
||||||
urllib.request.urlretrieve(url, downloadPath)
|
urllib.request.urlretrieve(url, downloadPath)
|
||||||
@ -110,8 +115,12 @@ def downloadSpecificVersion(ressourceId, downloadPath, versionID='latest'):
|
|||||||
filesizeData = calculateFileSizeKb(filesize)
|
filesizeData = calculateFileSizeKb(filesize)
|
||||||
print("Downloaded " + (str(filesizeData)).rjust(9) + f" KB here {downloadPath}")
|
print("Downloaded " + (str(filesizeData)).rjust(9) + f" KB here {downloadPath}")
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
|
if configValues.sftp_useSftp:
|
||||||
sftpSession = createSFTPConnection()
|
sftpSession = createSFTPConnection()
|
||||||
sftp_upload_file(sftpSession, downloadPath)
|
sftp_upload_file(sftpSession, downloadPath)
|
||||||
|
else:
|
||||||
|
ftpSession = createFTPConnection()
|
||||||
|
ftp_upload_file(ftpSession, downloadPath)
|
||||||
|
|
||||||
|
|
||||||
def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'):
|
def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'):
|
||||||
@ -125,17 +134,14 @@ def getSpecificPackage(ressourceId, downloadPath, inputPackageVersion='latest'):
|
|||||||
versionId = getVersionID(ressourceId, inputPackageVersion)
|
versionId = getVersionID(ressourceId, inputPackageVersion)
|
||||||
packageVersion = getVersionName(ressourceId, versionId)
|
packageVersion = getVersionName(ressourceId, versionId)
|
||||||
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
|
packageDownloadName = f"{packageNameNew}-{packageVersion}.jar"
|
||||||
|
#if not configValues.localPluginFolder:
|
||||||
|
#downloadPackagePath = f"{downloadPath}/{packageDownloadName}"
|
||||||
|
#else:
|
||||||
downloadPackagePath = Path(f"{downloadPath}/{packageDownloadName}")
|
downloadPackagePath = Path(f"{downloadPath}/{packageDownloadName}")
|
||||||
if configValues.localPluginFolder:
|
|
||||||
if inputPackageVersion is None or inputPackageVersion == 'latest':
|
if inputPackageVersion is None or inputPackageVersion == 'latest':
|
||||||
downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath)
|
downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath)
|
||||||
else:
|
else:
|
||||||
downloadSpecificVersion(ressourceId, downloadPackagePath, versionId)
|
downloadSpecificVersion(ressourceId, downloadPackagePath, versionId)
|
||||||
|
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
if inputPackageVersion is None or inputPackageVersion == 'latest':
|
|
||||||
downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath)
|
|
||||||
deleteTempPluginFolder(downloadPath)
|
|
||||||
else:
|
|
||||||
downloadSpecificVersion(ressourceId, downloadPackagePath, versionId)
|
|
||||||
deleteTempPluginFolder(downloadPath)
|
deleteTempPluginFolder(downloadPath)
|
||||||
|
@ -5,6 +5,7 @@ from pathlib import Path
|
|||||||
from utils.consoleoutput import oColors
|
from utils.consoleoutput import oColors
|
||||||
from handlers.handle_config import configurationValues
|
from handlers.handle_config import configurationValues
|
||||||
from handlers.handle_sftp import createSFTPConnection, sftp_listAll
|
from handlers.handle_sftp import createSFTPConnection, sftp_listAll
|
||||||
|
from handlers.handle_ftp import createFTPConnection, ftp_listAll
|
||||||
from plugin.plugin_updatechecker import getFileName, getFileVersion, getInstalledPlugin, createPluginList
|
from plugin.plugin_updatechecker import getFileName, getFileVersion, getInstalledPlugin, createPluginList
|
||||||
|
|
||||||
|
|
||||||
@ -12,6 +13,10 @@ def removePlugin(pluginToRemove):
|
|||||||
configValues = configurationValues()
|
configValues = configurationValues()
|
||||||
createPluginList()
|
createPluginList()
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
|
if not configValues.sftp_useSftp:
|
||||||
|
ftp = createFTPConnection()
|
||||||
|
pluginList = ftp_listAll(ftp)
|
||||||
|
else:
|
||||||
sftp = createSFTPConnection()
|
sftp = createSFTPConnection()
|
||||||
pluginList = sftp_listAll(sftp)
|
pluginList = sftp_listAll(sftp)
|
||||||
else:
|
else:
|
||||||
@ -32,6 +37,10 @@ def removePlugin(pluginToRemove):
|
|||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
pluginPath = configValues.sftp_folderPath
|
pluginPath = configValues.sftp_folderPath
|
||||||
pluginPath = f"{pluginPath}/{plugin}"
|
pluginPath = f"{pluginPath}/{plugin}"
|
||||||
|
if not configValues.sftp_useSftp:
|
||||||
|
ftp = createFTPConnection()
|
||||||
|
ftp.delete(pluginPath)
|
||||||
|
else:
|
||||||
sftp = createSFTPConnection()
|
sftp = createSFTPConnection()
|
||||||
sftp.remove(pluginPath)
|
sftp.remove(pluginPath)
|
||||||
print(f"Removed: {fileName}")
|
print(f"Removed: {fileName}")
|
||||||
|
@ -9,8 +9,10 @@ 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
|
||||||
from handlers.handle_config import configurationValues
|
from handlers.handle_config import configurationValues
|
||||||
from handlers.handle_sftp import createSFTPConnection, sftp_listAll
|
from handlers.handle_sftp import createSFTPConnection, sftp_listAll, sftp_downloadFile
|
||||||
|
from handlers.handle_ftp import createFTPConnection, ftp_listAll, ftp_downloadFile
|
||||||
from plugin.plugin_downloader import getSpecificPackage
|
from plugin.plugin_downloader import getSpecificPackage
|
||||||
|
from utils.utilities import createTempPluginFolder, deleteTempPluginFolder
|
||||||
|
|
||||||
|
|
||||||
def createPluginList():
|
def createPluginList():
|
||||||
@ -66,7 +68,16 @@ def compareVersions(plugin_latest_version, pluginVersion):
|
|||||||
def eggCrackingJar(localJarFileName):
|
def eggCrackingJar(localJarFileName):
|
||||||
configValues = configurationValues()
|
configValues = configurationValues()
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
pluginPath = configValues.sftp_folderPath
|
if configValues.sftp_useSftp:
|
||||||
|
tempPluginFolderPath = createTempPluginFolder()
|
||||||
|
sftp = createSFTPConnection()
|
||||||
|
pathToPluginJar = Path(f"{tempPluginFolderPath}/{localJarFileName}")
|
||||||
|
sftp_downloadFile(sftp, pathToPluginJar, localJarFileName)
|
||||||
|
else:
|
||||||
|
tempPluginFolderPath = createTempPluginFolder()
|
||||||
|
ftp = createFTPConnection()
|
||||||
|
pathToPluginJar = Path(f"{tempPluginFolderPath}/{localJarFileName}")
|
||||||
|
ftp_downloadFile(ftp, pathToPluginJar, localJarFileName)
|
||||||
else:
|
else:
|
||||||
pluginPath = configValues.pathToPluginFolder
|
pluginPath = configValues.pathToPluginFolder
|
||||||
pathToPluginJar = Path(f"{pluginPath}/{localJarFileName}")
|
pathToPluginJar = Path(f"{pluginPath}/{localJarFileName}")
|
||||||
@ -83,6 +94,8 @@ def eggCrackingJar(localJarFileName):
|
|||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pluginVersion = ''
|
pluginVersion = ''
|
||||||
|
if not configValues.localPluginFolder:
|
||||||
|
deleteTempPluginFolder(tempPluginFolderPath)
|
||||||
return pluginVersion
|
return pluginVersion
|
||||||
|
|
||||||
|
|
||||||
@ -90,8 +103,12 @@ def checkInstalledPackage(inputSelectedObject="all"):
|
|||||||
configValues = configurationValues()
|
configValues = configurationValues()
|
||||||
createPluginList()
|
createPluginList()
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
sftp = createSFTPConnection()
|
if configValues.sftp_useSftp:
|
||||||
pluginList = sftp_listAll(sftp)
|
connection = createSFTPConnection()
|
||||||
|
pluginList = sftp_listAll(connection)
|
||||||
|
else:
|
||||||
|
connection = createFTPConnection()
|
||||||
|
pluginList = ftp_listAll(connection)
|
||||||
else:
|
else:
|
||||||
pluginList = os.listdir(configValues.pathToPluginFolder)
|
pluginList = os.listdir(configValues.pathToPluginFolder)
|
||||||
i = 0
|
i = 0
|
||||||
@ -164,8 +181,12 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
|||||||
configValues = configurationValues()
|
configValues = configurationValues()
|
||||||
createPluginList()
|
createPluginList()
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
sftp = createSFTPConnection()
|
if configValues.sftp_useSftp:
|
||||||
pluginList = sftp_listAll(sftp)
|
connection = createSFTPConnection()
|
||||||
|
pluginList = sftp_listAll(connection)
|
||||||
|
else:
|
||||||
|
connection = createFTPConnection()
|
||||||
|
pluginList = ftp_listAll(connection)
|
||||||
else:
|
else:
|
||||||
pluginList = os.listdir(configValues.pathToPluginFolder)
|
pluginList = os.listdir(configValues.pathToPluginFolder)
|
||||||
i = 0
|
i = 0
|
||||||
@ -198,7 +219,6 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
|||||||
print(" ", end='')
|
print(" ", end='')
|
||||||
print(f"{fileName}".ljust(33), end='')
|
print(f"{fileName}".ljust(33), end='')
|
||||||
print(f"{fileVersion}".ljust(13), end='')
|
print(f"{fileVersion}".ljust(13), end='')
|
||||||
#print(" ", end='')
|
|
||||||
print(f"{latestVersion}".ljust(13))
|
print(f"{latestVersion}".ljust(13))
|
||||||
|
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
@ -248,10 +268,10 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
|||||||
print(" ", end='')
|
print(" ", end='')
|
||||||
print(f"{fileName}".ljust(33), end='')
|
print(f"{fileName}".ljust(33), end='')
|
||||||
print(f"{fileVersion}".ljust(13), end='')
|
print(f"{fileVersion}".ljust(13), end='')
|
||||||
#print(" ", end='')
|
|
||||||
print(f"{latestVersion}".ljust(13))
|
print(f"{latestVersion}".ljust(13))
|
||||||
|
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
|
if configValues.sftp_useSftp:
|
||||||
if configValues.sftp_seperateDownloadPath is True:
|
if configValues.sftp_seperateDownloadPath is True:
|
||||||
pluginPath = configValues.sftp_pathToSeperateDownloadPath
|
pluginPath = configValues.sftp_pathToSeperateDownloadPath
|
||||||
else:
|
else:
|
||||||
@ -265,10 +285,28 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
|||||||
if configValues.sftp_seperateDownloadPath is False:
|
if configValues.sftp_seperateDownloadPath is False:
|
||||||
sftp.remove(pluginPath)
|
sftp.remove(pluginPath)
|
||||||
except HTTPError as err:
|
except HTTPError as err:
|
||||||
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
|
print(oColors.brightRed + f"HTTPError: {err.code} - {err.reason}" + oColors.standardWhite)
|
||||||
pluginsUpdated -= 1
|
pluginsUpdated -= 1
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print(oColors.brightRed + f"Error: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
print(oColors.brightRed + f"FileNotFoundError: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
||||||
|
else:
|
||||||
|
if configValues.sftp_seperateDownloadPath is True:
|
||||||
|
pluginPath = configValues.sftp_pathToSeperateDownloadPath
|
||||||
|
else:
|
||||||
|
pluginPath = configValues.sftp_folderPath
|
||||||
|
pluginPath = f"{pluginPath}/{plugin}"
|
||||||
|
ftp = createFTPConnection()
|
||||||
|
indexNumberUpdated += 1
|
||||||
|
pluginsUpdated += 1
|
||||||
|
try:
|
||||||
|
getSpecificPackage(pluginId, configValues.sftp_folderPath)
|
||||||
|
if configValues.sftp_seperateDownloadPath is False:
|
||||||
|
ftp.delete(pluginPath)
|
||||||
|
except HTTPError as err:
|
||||||
|
print(oColors.brightRed + f"HTTPError: {err.code} - {err.reason}" + oColors.standardWhite)
|
||||||
|
pluginsUpdated -= 1
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(oColors.brightRed + f"FileNotFoundError: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if configValues.seperateDownloadPath is True:
|
if configValues.seperateDownloadPath is True:
|
||||||
@ -283,10 +321,10 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
|||||||
if configValues.seperateDownloadPath is False:
|
if configValues.seperateDownloadPath is False:
|
||||||
os.remove(pluginPath)
|
os.remove(pluginPath)
|
||||||
except HTTPError as err:
|
except HTTPError as err:
|
||||||
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
|
print(oColors.brightRed + f"HTTPError: {err.code} - {err.reason}" + oColors.standardWhite)
|
||||||
pluginsUpdated -= 1
|
pluginsUpdated -= 1
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print(oColors.brightRed + f"Error: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
print(oColors.brightRed + f"FileNotFoundError: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
||||||
|
|
||||||
i = i + 1
|
i = i + 1
|
||||||
except TypeError:
|
except TypeError:
|
||||||
|
@ -4,6 +4,7 @@ from urllib.error import HTTPError
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from handlers.handle_sftp import createSFTPConnection, sftp_listFilesInServerRoot
|
from handlers.handle_sftp import createSFTPConnection, sftp_listFilesInServerRoot
|
||||||
|
from handlers.handle_ftp import createFTPConnection, ftp_listFilesInServerRoot
|
||||||
from handlers.handle_config import configurationValues
|
from handlers.handle_config import configurationValues
|
||||||
from utils.consoleoutput import oColors
|
from utils.consoleoutput import oColors
|
||||||
from serverjar.serverjar_paper import paperCheckForUpdate, papermc_downloader
|
from serverjar.serverjar_paper import paperCheckForUpdate, papermc_downloader
|
||||||
@ -12,6 +13,10 @@ from serverjar.serverjar_paper import paperCheckForUpdate, papermc_downloader
|
|||||||
def checkInstalledServerjar():
|
def checkInstalledServerjar():
|
||||||
configValues = configurationValues()
|
configValues = configurationValues()
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
|
if not configValues.sftp_useSftp:
|
||||||
|
ftp = createFTPConnection()
|
||||||
|
serverRootList = ftp_listFilesInServerRoot(ftp)
|
||||||
|
else:
|
||||||
sftp = createSFTPConnection()
|
sftp = createSFTPConnection()
|
||||||
serverRootList = sftp_listFilesInServerRoot(sftp)
|
serverRootList = sftp_listFilesInServerRoot(sftp)
|
||||||
else:
|
else:
|
||||||
|
@ -7,7 +7,8 @@ from rich.console import Console
|
|||||||
|
|
||||||
from utils.consoleoutput import oColors
|
from utils.consoleoutput import oColors
|
||||||
from utils.web_request import doAPIRequest
|
from utils.web_request import doAPIRequest
|
||||||
from handlers.handle_sftp import sftp_upload_server_jar, sftp_cdPluginDir, createSFTPConnection
|
from handlers.handle_sftp import createSFTPConnection, sftp_upload_server_jar
|
||||||
|
from handlers.handle_ftp import createFTPConnection, ftp_upload_server_jar
|
||||||
from handlers.handle_config import configurationValues
|
from handlers.handle_config import configurationValues
|
||||||
from utils.utilities import createTempPluginFolder, deleteTempPluginFolder, calculateFileSizeMb
|
from utils.utilities import createTempPluginFolder, deleteTempPluginFolder, calculateFileSizeMb
|
||||||
|
|
||||||
@ -165,8 +166,13 @@ def papermc_downloader(paperBuild='latest', installedServerjarName=None, mcVersi
|
|||||||
filesizeData = calculateFileSizeMb(filesize)
|
filesizeData = calculateFileSizeMb(filesize)
|
||||||
print("Downloaded " + (str(filesizeData)).rjust(9) + f" MB here {downloadPackagePath}")
|
print("Downloaded " + (str(filesizeData)).rjust(9) + f" MB here {downloadPackagePath}")
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
|
if not configValues.sftp_useSftp:
|
||||||
|
ftpSession = createFTPConnection()
|
||||||
|
ftp_upload_server_jar(ftpSession, downloadPackagePath)
|
||||||
|
else:
|
||||||
sftpSession = createSFTPConnection()
|
sftpSession = createSFTPConnection()
|
||||||
sftp_upload_server_jar(sftpSession, downloadPackagePath)
|
sftp_upload_server_jar(sftpSession, downloadPackagePath)
|
||||||
|
|
||||||
deleteTempPluginFolder(downloadPath)
|
deleteTempPluginFolder(downloadPath)
|
||||||
|
|
||||||
print(oColors.brightGreen + "Downloaded successfully " + oColors.standardWhite + f"Paper {paperBuild}" + \
|
print(oColors.brightGreen + "Downloaded successfully " + oColors.standardWhite + f"Paper {paperBuild}" + \
|
||||||
|
@ -8,6 +8,7 @@ from pathlib import Path
|
|||||||
from utils.consoleoutput import oColors
|
from utils.consoleoutput import oColors
|
||||||
from handlers.handle_config import configurationValues
|
from handlers.handle_config import configurationValues
|
||||||
from handlers.handle_sftp import createSFTPConnection
|
from handlers.handle_sftp import createSFTPConnection
|
||||||
|
from handlers.handle_ftp import createFTPConnection
|
||||||
|
|
||||||
|
|
||||||
def getHelp():
|
def getHelp():
|
||||||
@ -134,16 +135,20 @@ def check_requirements():
|
|||||||
apiTest()
|
apiTest()
|
||||||
check_local_plugin_folder()
|
check_local_plugin_folder()
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
|
if configValues.sftp_useSftp:
|
||||||
createSFTPConnection()
|
createSFTPConnection()
|
||||||
|
else:
|
||||||
|
createFTPConnection()
|
||||||
|
|
||||||
|
|
||||||
def createTempPluginFolder():
|
def createTempPluginFolder():
|
||||||
tempPluginFolder = Path("./TempSFTPUploadFolder")
|
configValues = configurationValues()
|
||||||
|
tempPluginFolder = Path("./TempSFTPFolder")
|
||||||
if not os.path.isdir(tempPluginFolder):
|
if not os.path.isdir(tempPluginFolder):
|
||||||
try:
|
try:
|
||||||
os.mkdir(tempPluginFolder)
|
os.mkdir(tempPluginFolder)
|
||||||
except OSError:
|
except OSError:
|
||||||
print(oColors.brightRed + "Creation of directory %s failed" % checkConfig().pathToPluginFolder)
|
print(oColors.brightRed + "Creation of directory %s failed" % configValues.pathToPluginFolder)
|
||||||
print(oColors.brightRed + "Please check the config file!" + oColors.standardWhite)
|
print(oColors.brightRed + "Please check the config file!" + oColors.standardWhite)
|
||||||
input("Press any key + enter to exit...")
|
input("Press any key + enter to exit...")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
@ -3,7 +3,7 @@ import requests
|
|||||||
|
|
||||||
|
|
||||||
def doAPIRequest(url):
|
def doAPIRequest(url):
|
||||||
headers = {'user-agent': 'pluGET'}
|
headers = {'user-agent': 'pluGET/1.0'}
|
||||||
response = requests.get(url, headers=headers)
|
response = requests.get(url, headers=headers)
|
||||||
packageDetails = response.json()
|
packageDetails = response.json()
|
||||||
return packageDetails
|
return packageDetails
|
||||||
|
Loading…
Reference in New Issue
Block a user