80 lines
2.7 KiB
Python
80 lines
2.7 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):
|
|
print("checking path exists: " + 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):
|
|
print("Write Code Path: " + path)
|
|
#print(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:
|
|
checkFolderExist(pubDir)
|
|
with os.scandir(pubDir) as it:
|
|
funcNum = 0
|
|
for entry in it:
|
|
#print(entry)
|
|
#print(config["quickfaas"]["uploadFuncs"][ind])
|
|
if not entry.name.startswith('.') and entry.is_file():
|
|
config["quickfaas"]["uploadFuncs"][funcNum]["script"] = code_to_string(entry.path)
|
|
funcNum += 1
|
|
if subDir:
|
|
checkFolderExist(subDir)
|
|
with os.scandir(subDir) as it:
|
|
funcNum = 0
|
|
for entry in it:
|
|
print(entry)
|
|
print(config["quickfaas"]["downloadFuncs"][funcNum])
|
|
if not entry.name.startswith('.') and entry.is_file():
|
|
config["quickfaas"]["downloadFuncs"][funcNum]["script"] = code_to_string(entry.path)
|
|
funcNum += 1
|
|
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):
|
|
print("/".join(path.split("/")[:-1]))
|
|
if not os.path.exists("/".join(path.split("/")[:-1])):
|
|
print("Path didn't exist creating path: " + "/".join(path.split("/")[:-1]))
|
|
os.makedirs("/".join(path.split("/")[:-1]))
|
|
open(path, "a").close()
|
|
if not os.path.exists(path):
|
|
print("Path did not exist creating path: " + path)
|
|
open(path, "a").close()
|
|
|
|
def checkFolderExist(path):
|
|
if not os.path.exists(path):
|
|
print("Making folder" + path)
|
|
os.makedirs(path) |