Upload files to "subfiles"
This commit is contained in:
parent
37f33f49ca
commit
cc433a5bbf
150
subfiles/comunic.py
Normal file
150
subfiles/comunic.py
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
#communication stuff here
|
||||||
|
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
from hashlib import sha256
|
||||||
|
from . import helpers, savetools
|
||||||
|
from websockets.sync.client import connect
|
||||||
|
from subprocess import Popen, PIPE
|
||||||
|
from sys import platform
|
||||||
|
from os import listdir
|
||||||
|
from os.path import isfile, join, exists
|
||||||
|
from pathlib import Path
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def downloadLatestDll(self, filepath):
|
||||||
|
x = requests.get('https://openwf.io/supplementals/client%20drop-in/meta')
|
||||||
|
meta = json.loads(x.text)
|
||||||
|
url = f"https://openwf.io/supplementals/client%20drop-in/{meta['version']}/dwmapi.dll"#
|
||||||
|
content = requests.get(url, stream=True).content
|
||||||
|
hashofdll = sha256()
|
||||||
|
hashofdll.update(content)#
|
||||||
|
if hashofdll.hexdigest() == meta['sha256']:
|
||||||
|
with open(filepath + "dwmapi.dll", "wb") as out_file:
|
||||||
|
out_file.write(content)
|
||||||
|
helpers.messageBox(self=self,title="Bootstrapper Downloaded", message="Bootstrapper Downloaded!", type="info")
|
||||||
|
else:
|
||||||
|
helpers.messageBox(self=self,title="Unknown Error.", message="SpaceninGUI could not verify the hash of the Bootstrapper. Sorry :(", type="error")#
|
||||||
|
|
||||||
|
def getLatestVersions(self, cacheFile, value):
|
||||||
|
ver = {
|
||||||
|
"server" : (
|
||||||
|
"no lol" #not finished update check for server, check back later :3
|
||||||
|
),
|
||||||
|
"client" : ""
|
||||||
|
}
|
||||||
|
#client code here
|
||||||
|
x = requests.get('https://openwf.io/supplementals/client%20drop-in/meta')
|
||||||
|
meta = json.loads(x.text)
|
||||||
|
ver["client"] = meta['version']
|
||||||
|
|
||||||
|
try:
|
||||||
|
oldVer = savetools.loadFile(self, cacheFile)["client"]
|
||||||
|
except:
|
||||||
|
with open('tempFile.json', 'w') as f:
|
||||||
|
json.dump({
|
||||||
|
"client":'notassigned',
|
||||||
|
'server':'notassigned'
|
||||||
|
},f,indent=2)
|
||||||
|
|
||||||
|
oldVer = savetools.loadFile(self, cacheFile)["client"]
|
||||||
|
if oldVer == ver["client"]:
|
||||||
|
client="Up To Date!"
|
||||||
|
else:
|
||||||
|
client="New Version " + ver["client"]
|
||||||
|
server = "server Check Not Implemented"
|
||||||
|
value[0].set("Latest Server Version: " + server)
|
||||||
|
value[1].set("Latest Client Version: " + client)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def serverBackground(self, cd, logArea): # To my knowledge, running the server in the main thread would stall the gui, fuck that lol
|
||||||
|
logmax = helpers.getLogMax()
|
||||||
|
logarr=[]
|
||||||
|
def mongo():
|
||||||
|
sysctl = Popen(['systemctl', 'start', 'mongodb'])
|
||||||
|
sysctl.wait()#
|
||||||
|
def execute(cd):
|
||||||
|
popen = Popen(['npm', 'run', 'dev'], stdin=PIPE, stdout=PIPE, universal_newlines=True, cwd=cd)
|
||||||
|
for stdout_line in iter(popen.stdout.readline, ""):
|
||||||
|
yield stdout_line
|
||||||
|
popen.stdout.close()
|
||||||
|
return_code = popen.wait()
|
||||||
|
if return_code:
|
||||||
|
raise subprocess.CalledProcessError(return_code)#
|
||||||
|
if platform == "linux":
|
||||||
|
helpers.messageBox(self, title="MongoDB", message="The mongodb server is required to start SNS\nYou will need to give sudo permission for this.", type="info")
|
||||||
|
mongo()
|
||||||
|
|
||||||
|
for path in execute(cd):
|
||||||
|
if len(logarr) < logmax:
|
||||||
|
logarr.append(path)
|
||||||
|
else:
|
||||||
|
logarr.pop(0)
|
||||||
|
logarr.append(path)
|
||||||
|
if logArea:
|
||||||
|
logArea.configure(state="normal")
|
||||||
|
logArea.delete(1.0, "end")
|
||||||
|
for element in logarr:
|
||||||
|
pass
|
||||||
|
logArea.configure(state="disabled")
|
||||||
|
|
||||||
|
def getClientResponse():
|
||||||
|
try:
|
||||||
|
with connect("ws://localhost:61558") as websocket:
|
||||||
|
message = json.loads(websocket.recv())
|
||||||
|
except:
|
||||||
|
message=False
|
||||||
|
return message
|
||||||
|
|
||||||
|
def checkForClient(clientpath):
|
||||||
|
onlyfiles = [f for f in listdir(clientpath) if isfile(join(clientpath, f))]
|
||||||
|
if "dwmapi.dll" in onlyfiles:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def runPluto(name, plutolist, conffile):
|
||||||
|
openwfpath = helpers.getclientpath(conffile) + "/OpenWF/scripts/"
|
||||||
|
onlyfiles = [f for f in listdir(openwfpath) if isfile(join(openwfpath, f))]
|
||||||
|
if helpers.getclientresponse():
|
||||||
|
running = []
|
||||||
|
print(helpers.getclientresponse()["running_scripts"])
|
||||||
|
if name in running:
|
||||||
|
requests.get(url=("http://localhost:61558/stop_script?OpenWF/scripts/" + name))
|
||||||
|
else:
|
||||||
|
requests.get(url=("http://localhost:61558/start_script?OpenWF/scripts/" + name))
|
||||||
|
|
||||||
|
for script in helpers.getclientresponse()["running_scripts"]:
|
||||||
|
running.append(script.removeprefix("OpenWF/scripts/"))#
|
||||||
|
for file in onlyfiles:
|
||||||
|
if file in running:
|
||||||
|
if plutolist[file]: plutolist[file].set("Running")
|
||||||
|
else:
|
||||||
|
if plutolist[file]: plutolist[file].set("Not Running")
|
||||||
|
|
||||||
|
def getSnPath(file):
|
||||||
|
if Path(file).is_file():
|
||||||
|
with open(file) as f:
|
||||||
|
d = json.load(f)
|
||||||
|
return d["spaceninjapath"]
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
77
subfiles/helpers.py
Normal file
77
subfiles/helpers.py
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
from CTkMessagebox import CTkMessagebox
|
||||||
|
import threading
|
||||||
|
from .savetools import loadFile
|
||||||
|
|
||||||
|
try:
|
||||||
|
from os import startfile
|
||||||
|
except:
|
||||||
|
from os import system
|
||||||
|
from sys import platform
|
||||||
|
|
||||||
|
def check():
|
||||||
|
print("Save Good")
|
||||||
|
|
||||||
|
def removeChildren(frame):
|
||||||
|
for element in frame.winfo_children():
|
||||||
|
element.destroy()
|
||||||
|
|
||||||
|
def bgThread(func, args):
|
||||||
|
th = threading.Thread(target=func, args=args)
|
||||||
|
th.daemon = True
|
||||||
|
th.start()
|
||||||
|
|
||||||
|
def openLocation(self, location):
|
||||||
|
if platform == "linux":
|
||||||
|
system('xdg-open "%s"' % location)
|
||||||
|
elif platform == "windows":
|
||||||
|
startfile(foldername)
|
||||||
|
|
||||||
|
|
||||||
|
def messageBox(self, title, message, type): #type will be implemented at a later point when required
|
||||||
|
CTkMessagebox(title=title, message=message)
|
||||||
|
|
||||||
|
def getLogMax(self, save):
|
||||||
|
return loadFile(self, save)['maxlogsize'] #not entirely sure why I made this a seperate function but eh
|
||||||
|
|
||||||
|
def isNumber(data):
|
||||||
|
if data == '':
|
||||||
|
return True
|
||||||
|
try:
|
||||||
|
rv = int(data)
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
#Old Helper options, left here for future reference. Shitty code, but it works, and it may be useful in the future
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# def getlogmax():
|
||||||
|
# file = 'sngconfig.json'
|
||||||
|
# if Path(file).is_file():
|
||||||
|
# with open(file) as f:
|
||||||
|
# d = json.load(f)
|
||||||
|
#
|
||||||
|
# else:
|
||||||
|
# return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# def check4sn(configfile):
|
||||||
|
# file = helpers.getsnpath(configfile) + "package.json"
|
||||||
|
# if Path(file).is_file():
|
||||||
|
# with open(file) as f:
|
||||||
|
# d = json.load(f)
|
||||||
|
# if (d["name"] == "wf-emulator"):
|
||||||
|
# return True
|
||||||
|
# else:
|
||||||
|
# return False#
|
||||||
|
|
||||||
|
|
23
subfiles/install.py
Normal file
23
subfiles/install.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
def check():
|
||||||
|
print("install Good")
|
||||||
|
|
||||||
|
|
||||||
|
def installFiles(self, clientpath, serverpath):
|
||||||
|
#first install server
|
||||||
|
self.installstep.set("Downloading Server Through Git")
|
||||||
|
sysctl = Popen(['git', 'clone', 'https://openwf.io/SpaceNinjaServer.git', serverpath])
|
||||||
|
self.installprog.set(1)
|
||||||
|
sysctl.wait()
|
||||||
|
self.installstep.set("Installing Server Requirements (via npm)")
|
||||||
|
self.installprog.set(25)
|
||||||
|
sysctl = Popen(["npm", '--prefix', f'{serverpath}', 'install'])
|
||||||
|
sysctl.wait()
|
||||||
|
self.installstep.set("Copying Config File")
|
||||||
|
shutil.copy(serverpath + "/config.json.example", serverpath + "/config.json")
|
||||||
|
self.installstep.set("Starting Bootstrapper Download")
|
||||||
|
self.installprog.set(50)
|
||||||
|
print("Server install worked. ")
|
||||||
|
helpers.downloadlatestdll(clientpath)
|
||||||
|
self.installprog.set(99)
|
||||||
|
self.installstep.set("Install Complete!\nPress next then restart to get started!")
|
||||||
|
|
22
subfiles/savetools.py
Normal file
22
subfiles/savetools.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import json
|
||||||
|
|
||||||
|
def check():
|
||||||
|
print("Save Check Good")
|
||||||
|
|
||||||
|
# Yea I know this is pretty pointless in a seperate file but it's nice to have these things
|
||||||
|
def loadFile(self, file1):
|
||||||
|
with open(file1, "r") as file:
|
||||||
|
|
||||||
|
data = json.load(file)
|
||||||
|
return data
|
||||||
|
|
||||||
|
#Data should be recived in [[data, position], [data, position]] format
|
||||||
|
def saveFile(self, fileP, data):
|
||||||
|
with open(fileP, 'r') as file:
|
||||||
|
data = json.load(file)
|
||||||
|
for subData in data:
|
||||||
|
data[subData[1]] = subData[0]
|
||||||
|
with open(fileP, 'w'):
|
||||||
|
json.dump(file, indent=2)
|
||||||
|
|
||||||
|
|
12
subfiles/themes.py
Normal file
12
subfiles/themes.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
def getThemes(self):
|
||||||
|
themes = {
|
||||||
|
"black_orange" : {
|
||||||
|
"fg_color" : "#000000",
|
||||||
|
"bg_color" : "#14213D",
|
||||||
|
"bg_deep" : "#121e37",
|
||||||
|
"border_color" : "#14213D",
|
||||||
|
"highlight_color" : '#FCA311',
|
||||||
|
"text_color" : ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return themes
|
Loading…
x
Reference in New Issue
Block a user