2021-03-08 21:13:57 +00:00
|
|
|
# misc functions
|
2021-03-10 01:05:56 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import shutil
|
2021-03-12 00:39:39 +00:00
|
|
|
import requests
|
|
|
|
|
|
|
|
from utils.consoleoutput import oColors
|
|
|
|
from handlers.handle_config import checkConfig
|
2021-03-13 21:09:32 +00:00
|
|
|
from handlers.handle_sftp import createSFTPConnection
|
2021-03-10 01:05:56 +00:00
|
|
|
|
2021-03-08 21:13:57 +00:00
|
|
|
|
|
|
|
def getHelp():
|
|
|
|
print(oColors.brightYellow+ "Need help?" + oColors.standardWhite)
|
|
|
|
print("Check the docs here:")
|
|
|
|
print("https://github.com/Neocky/pluGET")
|
|
|
|
print("Or go to the official discord.")
|
|
|
|
print("The link for discord can also be found on Github!")
|
2021-03-10 01:05:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
def check_local_plugin_folder():
|
|
|
|
if checkConfig().localPluginFolder:
|
2021-03-14 12:25:13 +00:00
|
|
|
if checkConfig().seperateDownloadPath:
|
|
|
|
pluginFolderPath = checkConfig().pathToSeperateDownloadPath
|
|
|
|
else:
|
|
|
|
pluginFolderPath = checkConfig().pathToPluginFolder
|
|
|
|
|
|
|
|
if not os.path.isdir(pluginFolderPath):
|
2021-03-10 01:05:56 +00:00
|
|
|
print(oColors.brightRed + "Plugin folder coulnd*t be found. Creating one..." + oColors.standardWhite)
|
|
|
|
try:
|
2021-03-14 12:25:13 +00:00
|
|
|
os.mkdir(pluginFolderPath)
|
2021-03-10 01:05:56 +00:00
|
|
|
except OSError:
|
2021-03-14 12:25:13 +00:00
|
|
|
print(oColors.brightRed + "Creation of directory %s failed" % pluginFolderPath)
|
2021-03-10 01:05:56 +00:00
|
|
|
print(oColors.brightRed + "Please check the config file!" + oColors.standardWhite)
|
2021-03-13 22:12:56 +00:00
|
|
|
input("Press any key + enter to exit...")
|
2021-03-10 01:05:56 +00:00
|
|
|
sys.exit()
|
|
|
|
else:
|
2021-03-14 12:25:13 +00:00
|
|
|
print("Created directory %s" % pluginFolderPath)
|
2021-03-10 01:05:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
def apiTest():
|
|
|
|
apiStatusUrl = 'https://api.spiget.org/v2/status'
|
|
|
|
try:
|
|
|
|
r = requests.get(apiStatusUrl)
|
|
|
|
except requests.exceptions.HTTPError:
|
2021-03-12 00:39:39 +00:00
|
|
|
print(oColors.brightRed + "Couldn't make a connection to the API. Check you connection to the internet!" + oColors.standardWhite)
|
2021-03-13 22:12:56 +00:00
|
|
|
input("Press any key + enter to exit...")
|
2021-03-10 01:05:56 +00:00
|
|
|
sys.exit()
|
|
|
|
if r.status_code != 200:
|
|
|
|
print(oColors.brightRed + "Problems with the API detected. Plese try it again later!" + oColors.standardWhite)
|
2021-03-13 22:12:56 +00:00
|
|
|
input("Press any key + enter to exit...")
|
2021-03-10 01:05:56 +00:00
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
|
|
|
|
def check_requirements():
|
|
|
|
apiTest()
|
|
|
|
check_local_plugin_folder()
|
2021-03-13 21:09:32 +00:00
|
|
|
if not checkConfig().localPluginFolder:
|
|
|
|
createSFTPConnection()
|
|
|
|
|
2021-03-10 01:05:56 +00:00
|
|
|
|
|
|
|
def createTempPluginFolder():
|
|
|
|
tempPluginFolder = ".\\plugins"
|
|
|
|
if not os.path.isdir(tempPluginFolder):
|
|
|
|
try:
|
|
|
|
os.mkdir(tempPluginFolder)
|
|
|
|
except OSError:
|
|
|
|
print(oColors.brightRed + "Creation of directory %s failed" % checkConfig().pathToPluginFolder)
|
|
|
|
print(oColors.brightRed + "Please check the config file!" + oColors.standardWhite)
|
2021-03-13 22:12:56 +00:00
|
|
|
input("Press any key + enter to exit...")
|
2021-03-10 01:05:56 +00:00
|
|
|
sys.exit()
|
|
|
|
return tempPluginFolder
|
|
|
|
|
|
|
|
|
|
|
|
def deleteTempPluginFolder(tempPluginFolder):
|
|
|
|
try:
|
|
|
|
shutil.rmtree(tempPluginFolder)
|
|
|
|
except OSError as e:
|
2021-03-12 00:39:39 +00:00
|
|
|
print ("Error: %s - %s." % (e.filename, e.strerror))
|