Files
HP_InHand_IG502/Pub_Sub/convert_config.py
2022-08-20 10:07:01 -05:00

58 lines
1.8 KiB
Python

from base64 import encode
import os
import json
def get_config(path):
checkFileExist(path)
with open(path, "r", encoding="utf-8") as f:
return json.load(f)
def get_config_pub(path):
checkFileExist(path)
with open(path, "r") as f:
codeString = json.load(f)
return codeString["quickfaas"]["uploadFuncs"][0]["script"]
def get_config_sub(path):
checkFileExist(path)
with open(path, "r") as f:
codeString = json.load(f)
return codeString["quickfaas"]["downloadFuncs"][0]["script"]
def code_to_string(path):
checkFileExist(path)
try:
with open(path, "r") as f:
return f.read()
except:
return False
def write_code(path, codestr):
checkFileExist(path)
with open(path, "w") as f:
f.write(codestr)
def write_config(path, config, pubDir, subDir):
checkFileExist(path)
with open(path, "w") as f:
if pubDir:
with os.scandir(pubDir) as it:
for ind, entry in enumerate(it):
config["quickfaas"]["uploadFuncs"][ind]["script"] = code_to_string(entry.path)
if subDir:
with os.scandir(subDir) as it:
for ind, entry in enumerate(it):
config["quickfaas"]["downloadFuncs"][ind]["script"] = code_to_string(entry.path)
config["clouds"][0]["args"]["host"] = "hp.henrypump.cloud"
config["clouds"][0]["args"]["clientId"] = "unknown"
config["clouds"][0]["args"]["username"] = "unknown"
config["clouds"][0]["args"]["passwd"] = "unknown"
json.dump(config, f, indent=4)
def checkFileExist(path):
if not os.path.exists("/".join(path.split("/")[:-1])):
os.makedirs("/".join(path.split("/")[:-1]))
open(path, "a").close()
if not os.path.exists(path):
open(path, "a").close()