2021-03-12 00:39:39 +00:00
|
|
|
import os
|
|
|
|
import re
|
2021-03-16 00:04:13 +00:00
|
|
|
from pathlib import Path
|
2021-03-12 00:39:39 +00:00
|
|
|
|
|
|
|
from utils.consoleoutput import oColors
|
2021-03-27 11:07:19 +00:00
|
|
|
from handlers.handle_config import configurationValues
|
2021-03-12 00:39:39 +00:00
|
|
|
from handlers.handle_sftp import createSFTPConnection, sftp_listAll
|
|
|
|
from plugin.plugin_updatechecker import getFileName, getFileVersion, getInstalledPlugin, createPluginList
|
|
|
|
|
|
|
|
|
|
|
|
def removePlugin(pluginToRemove):
|
2021-03-27 11:07:19 +00:00
|
|
|
configValues = configurationValues()
|
2021-03-12 00:39:39 +00:00
|
|
|
createPluginList()
|
2021-03-27 11:07:19 +00:00
|
|
|
if not configValues.localPluginFolder:
|
2021-03-12 00:39:39 +00:00
|
|
|
sftp = createSFTPConnection()
|
|
|
|
pluginList = sftp_listAll(sftp)
|
|
|
|
else:
|
2021-03-27 11:07:19 +00:00
|
|
|
pluginList = os.listdir(configValues.pathToPluginFolder)
|
2021-03-12 00:39:39 +00:00
|
|
|
i = 0
|
|
|
|
try:
|
|
|
|
for plugin in pluginList:
|
|
|
|
try:
|
|
|
|
fileName = getFileName(plugin)
|
|
|
|
fileVersion = getFileVersion(plugin)
|
|
|
|
pluginId = getInstalledPlugin(fileName, fileVersion)
|
|
|
|
except TypeError:
|
|
|
|
continue
|
|
|
|
pluginIdStr = str(pluginId)
|
|
|
|
|
|
|
|
if pluginToRemove == pluginIdStr or re.search(pluginToRemove, fileName, re.IGNORECASE):
|
|
|
|
print(f"Removing: {fileName}")
|
2021-03-27 11:07:19 +00:00
|
|
|
if not configValues.localPluginFolder:
|
|
|
|
pluginPath = configValues.sftp_folderPath
|
2021-03-16 00:04:13 +00:00
|
|
|
pluginPath = f"{pluginPath}/{plugin}"
|
2021-03-12 00:39:39 +00:00
|
|
|
sftp = createSFTPConnection()
|
|
|
|
sftp.remove(pluginPath)
|
|
|
|
print(f"Removed: {fileName}")
|
|
|
|
i += 1
|
|
|
|
break
|
|
|
|
else:
|
2021-03-27 11:07:19 +00:00
|
|
|
pluginPath = configValues.pathToPluginFolder
|
2021-03-16 00:04:13 +00:00
|
|
|
pluginPath = Path(f"{pluginPath}/{plugin}")
|
2021-03-12 00:39:39 +00:00
|
|
|
os.remove(pluginPath)
|
|
|
|
print(f"Removed: {fileName}")
|
|
|
|
i += 1
|
|
|
|
break
|
|
|
|
except TypeError:
|
|
|
|
print(oColors.brightRed + f"Aborted removing of: {pluginToRemove}." + oColors.standardWhite)
|
|
|
|
if i == 0:
|
|
|
|
print(oColors.brightRed + f"Couldn't remove plugin: {pluginToRemove}" + oColors.standardWhite)
|