mirror of
https://github.com/Neocky/pluGET.git
synced 2024-04-29 16:12:30 +00:00
Added FTP support
Changes: - added ftp support - added ftp to every function which had already sftp interaction - edited config - added handle_ftp.py fixed old configcheck() bugs - added sftp/ftp to eggcrackingjar mechanism - added new line input with enter
This commit is contained in:
parent
2a7372dae1
commit
927767b0aa
@ -12,5 +12,4 @@ def mainFunction():
|
|||||||
createInputLists()
|
createInputLists()
|
||||||
printMainMenu()
|
printMainMenu()
|
||||||
getInput()
|
getInput()
|
||||||
|
|
||||||
mainFunction()
|
mainFunction()
|
||||||
|
@ -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:
|
||||||
|
100
src/handlers/handle_ftp.py
Normal file
100
src/handlers/handle_ftp.py
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
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_cdPluginDir(ftp):
|
||||||
|
configValues = configurationValues()
|
||||||
|
ftp.cwd(configValues.sftp_folderPath)
|
||||||
|
|
||||||
|
|
||||||
|
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 + "The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||||
|
print(oColors.brightRed + "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 + "The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||||
|
print(oColors.brightRed + "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 + "The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||||
|
|
||||||
|
try:
|
||||||
|
return installedPlugins
|
||||||
|
except UnboundLocalError:
|
||||||
|
print(oColors.brightRed + "No plugins were found." + oColors.standardWhite)
|
||||||
|
|
||||||
|
|
||||||
|
def ftp_listFilesInServerRoot(ftp):
|
||||||
|
try:
|
||||||
|
ftp.cwd('.')
|
||||||
|
filesInServerRoot = ftp.nlst()
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(oColors.brightRed + "The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||||
|
|
||||||
|
try:
|
||||||
|
return filesInServerRoot
|
||||||
|
except UnboundLocalError:
|
||||||
|
print(oColors.brightRed + "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:
|
||||||
print(oColors.brightRed + "Wrong input! Use: > 'command' 'selectedObject' [optionalParams]" + oColors.standardWhite)
|
if inputCommand == None:
|
||||||
print(oColors.brightRed + "Use: '" + oColors.standardWhite +"help command" + oColors.brightRed +"' to get all available commands" + oColors.standardWhite)
|
continue
|
||||||
|
else:
|
||||||
|
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)
|
||||||
|
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,20 @@
|
|||||||
import sys
|
import sys
|
||||||
|
import os
|
||||||
import pysftp
|
import pysftp
|
||||||
import paramiko
|
import paramiko
|
||||||
|
import ftplib
|
||||||
|
|
||||||
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:
|
||||||
@ -41,7 +44,7 @@ def sftp_upload_file(sftp, 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 uploading." + oColors.standardWhite)
|
||||||
sftp.close()
|
sftp.close()
|
||||||
|
|
||||||
|
|
||||||
@ -49,10 +52,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 + "The 'root' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||||
print(oColors.brightRed + "Aborting installation." + oColors.standardWhite)
|
print(oColors.brightRed + "Aborting uploading." + oColors.standardWhite)
|
||||||
sftp.close()
|
sftp.close()
|
||||||
|
|
||||||
|
|
||||||
@ -60,7 +62,6 @@ 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 + "The 'plugins' folder couldn*t be found on the remote host!" + oColors.standardWhite)
|
||||||
|
|
||||||
@ -72,13 +73,22 @@ def sftp_listAll(sftp):
|
|||||||
|
|
||||||
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 + "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 + "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, ftp_cdPluginDir, createFTPConnection
|
||||||
|
|
||||||
|
|
||||||
def handleRegexPackageName(packageNameFull):
|
def handleRegexPackageName(packageNameFull):
|
||||||
@ -110,8 +111,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:
|
||||||
sftpSession = createSFTPConnection()
|
if configValues.sftp_useSftp:
|
||||||
sftp_upload_file(sftpSession, downloadPath)
|
sftpSession = createSFTPConnection()
|
||||||
|
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 +130,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':
|
deleteTempPluginFolder(downloadPath)
|
||||||
downloadSpecificVersion(ressourceId=ressourceId, downloadPath=downloadPackagePath)
|
|
||||||
deleteTempPluginFolder(downloadPath)
|
|
||||||
else:
|
|
||||||
downloadSpecificVersion(ressourceId, downloadPackagePath, versionId)
|
|
||||||
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,8 +13,12 @@ def removePlugin(pluginToRemove):
|
|||||||
configValues = configurationValues()
|
configValues = configurationValues()
|
||||||
createPluginList()
|
createPluginList()
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
sftp = createSFTPConnection()
|
if not configValues.sftp_useSftp:
|
||||||
pluginList = sftp_listAll(sftp)
|
ftp = createFTPConnection()
|
||||||
|
pluginList = ftp_listAll(ftp)
|
||||||
|
else:
|
||||||
|
sftp = createSFTPConnection()
|
||||||
|
pluginList = sftp_listAll(sftp)
|
||||||
else:
|
else:
|
||||||
pluginList = os.listdir(configValues.pathToPluginFolder)
|
pluginList = os.listdir(configValues.pathToPluginFolder)
|
||||||
i = 0
|
i = 0
|
||||||
@ -32,8 +37,12 @@ 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}"
|
||||||
sftp = createSFTPConnection()
|
if not configValues.sftp_useSftp:
|
||||||
sftp.remove(pluginPath)
|
ftp = createFTPConnection()
|
||||||
|
ftp.delete(pluginPath)
|
||||||
|
else:
|
||||||
|
sftp = createSFTPConnection()
|
||||||
|
sftp.remove(pluginPath)
|
||||||
print(f"Removed: {fileName}")
|
print(f"Removed: {fileName}")
|
||||||
i += 1
|
i += 1
|
||||||
break
|
break
|
||||||
|
@ -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,10 +68,19 @@ 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}")
|
||||||
pluginVersion = ''
|
pluginVersion = ''
|
||||||
with ZipFile(pathToPluginJar, 'r') as pluginJar:
|
with ZipFile(pathToPluginJar, 'r') as pluginJar:
|
||||||
try:
|
try:
|
||||||
@ -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,27 +268,45 @@ 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_seperateDownloadPath is True:
|
if configValues.sftp_useSftp:
|
||||||
pluginPath = configValues.sftp_pathToSeperateDownloadPath
|
if configValues.sftp_seperateDownloadPath is True:
|
||||||
|
pluginPath = configValues.sftp_pathToSeperateDownloadPath
|
||||||
|
else:
|
||||||
|
pluginPath = configValues.sftp_folderPath
|
||||||
|
pluginPath = f"{pluginPath}/{plugin}"
|
||||||
|
sftp = createSFTPConnection()
|
||||||
|
indexNumberUpdated += 1
|
||||||
|
pluginsUpdated += 1
|
||||||
|
try:
|
||||||
|
getSpecificPackage(pluginId, configValues.sftp_folderPath)
|
||||||
|
if configValues.sftp_seperateDownloadPath is False:
|
||||||
|
sftp.remove(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:
|
||||||
pluginPath = configValues.sftp_folderPath
|
if configValues.sftp_seperateDownloadPath is True:
|
||||||
pluginPath = f"{pluginPath}/{plugin}"
|
pluginPath = configValues.sftp_pathToSeperateDownloadPath
|
||||||
sftp = createSFTPConnection()
|
else:
|
||||||
indexNumberUpdated += 1
|
pluginPath = configValues.sftp_folderPath
|
||||||
pluginsUpdated += 1
|
pluginPath = f"{pluginPath}/{plugin}"
|
||||||
try:
|
ftp = createFTPConnection()
|
||||||
getSpecificPackage(pluginId, configValues.sftp_folderPath)
|
indexNumberUpdated += 1
|
||||||
if configValues.sftp_seperateDownloadPath is False:
|
pluginsUpdated += 1
|
||||||
sftp.remove(pluginPath)
|
try:
|
||||||
except HTTPError as err:
|
getSpecificPackage(pluginId, configValues.sftp_folderPath)
|
||||||
print(oColors.brightRed + f"Error: {err.code} - {err.reason}" + oColors.standardWhite)
|
if configValues.sftp_seperateDownloadPath is False:
|
||||||
pluginsUpdated -= 1
|
ftp.delete(pluginPath)
|
||||||
except FileNotFoundError:
|
except HTTPError as err:
|
||||||
print(oColors.brightRed + f"Error: Old plugin file coulnd't be deleted" + oColors.standardWhite)
|
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:
|
||||||
@ -282,11 +320,11 @@ def updateInstalledPackage(inputSelectedObject='all'):
|
|||||||
getSpecificPackage(pluginId, configValues.pathToPluginFolder)
|
getSpecificPackage(pluginId, configValues.pathToPluginFolder)
|
||||||
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,8 +13,12 @@ from serverjar.serverjar_paper import paperCheckForUpdate, papermc_downloader
|
|||||||
def checkInstalledServerjar():
|
def checkInstalledServerjar():
|
||||||
configValues = configurationValues()
|
configValues = configurationValues()
|
||||||
if not configValues.localPluginFolder:
|
if not configValues.localPluginFolder:
|
||||||
sftp = createSFTPConnection()
|
if not configValues.sftp_useSftp:
|
||||||
serverRootList = sftp_listFilesInServerRoot(sftp)
|
ftp = createFTPConnection()
|
||||||
|
serverRootList = ftp_listFilesInServerRoot(ftp)
|
||||||
|
else:
|
||||||
|
sftp = createSFTPConnection()
|
||||||
|
serverRootList = sftp_listFilesInServerRoot(sftp)
|
||||||
else:
|
else:
|
||||||
serverRootList = os.path.dirname(configValues.pathToPluginFolder)
|
serverRootList = os.path.dirname(configValues.pathToPluginFolder)
|
||||||
serverRootList = os.listdir(serverRootList)
|
serverRootList = os.listdir(serverRootList)
|
||||||
|
@ -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:
|
||||||
sftpSession = createSFTPConnection()
|
if not configValues.sftp_useSftp:
|
||||||
sftp_upload_server_jar(sftpSession, downloadPackagePath)
|
ftpSession = createFTPConnection()
|
||||||
|
ftp_upload_server_jar(ftpSession, downloadPackagePath)
|
||||||
|
else:
|
||||||
|
sftpSession = createSFTPConnection()
|
||||||
|
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:
|
||||||
createSFTPConnection()
|
if configValues.sftp_useSftp:
|
||||||
|
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()
|
||||||
@ -167,4 +172,4 @@ def calculateFileSizeKb(downloadFileSize):
|
|||||||
fileSizeDownload = int(downloadFileSize)
|
fileSizeDownload = int(downloadFileSize)
|
||||||
fileSizeKb = fileSizeDownload / 1024
|
fileSizeKb = fileSizeDownload / 1024
|
||||||
roundedFileSize = round(fileSizeKb, 2)
|
roundedFileSize = round(fileSizeKb, 2)
|
||||||
return roundedFileSize
|
return roundedFileSize
|
||||||
|
Loading…
Reference in New Issue
Block a user