137 lines
3.5 KiB
Python
137 lines
3.5 KiB
Python
# AGPL 3 or any later version
|
|
# (C) J.Y.Amihud ( Blender Dumbass )
|
|
|
|
from modules.Common import *
|
|
|
|
import os
|
|
import sys
|
|
import json
|
|
|
|
def Folder():
|
|
|
|
conf = "BDServer"
|
|
|
|
try:
|
|
data_dir = os.environ["XDG_DATA_HOME"] + "/" + conf
|
|
except:
|
|
data_dir = os.path.expanduser("~/.local/share/"+ conf)
|
|
|
|
try:
|
|
os.makedirs(data_dir)
|
|
except:
|
|
pass
|
|
|
|
return data_dir
|
|
|
|
def Load():
|
|
|
|
try:
|
|
with open(Folder()+"/config.json") as o:
|
|
data = json.load(o)
|
|
except Exception as e:
|
|
data = {}
|
|
print(clr["bold"]+clr["tdyl"]+"Error:"+clr["norm"]+" Config doesn't exist! Making new config.")
|
|
|
|
return data
|
|
|
|
def Save(data):
|
|
|
|
try:
|
|
with open(Folder()+"/config.json", "w") as save:
|
|
json.dump(data, save, indent=4, sort_keys=True)
|
|
|
|
except Exception as e:
|
|
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Cannot save config!", e)
|
|
|
|
def Set():
|
|
|
|
if len(sys.argv) < 3:
|
|
from modules import Help
|
|
Help.Set()
|
|
|
|
if "--title" in sys.argv:
|
|
try:
|
|
title = sys.argv[ sys.argv.index("--title") + 1]
|
|
if "--" in title: 1/0 # Failing this for the error message.
|
|
Title(title)
|
|
|
|
except Exception as e:
|
|
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Title Wasn't Specified!")
|
|
|
|
if "--port" in sys.argv:
|
|
try:
|
|
port = int(sys.argv[ sys.argv.index("--port") + 1])
|
|
Port(port)
|
|
|
|
except Exception as e:
|
|
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Port Wasn't Specified Correctly!", e)
|
|
|
|
|
|
if "--add_tab" in sys.argv:
|
|
try:
|
|
tab = sys.argv[ sys.argv.index("--add_tab") + 1]
|
|
if "--" in tab: 1/0 # Failing this for the error message.
|
|
AddTab(tab)
|
|
|
|
except Exception as e:
|
|
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Tab Name Wasn't Specified!")
|
|
|
|
if "--edit_tab" in sys.argv:
|
|
try:
|
|
tab = sys.argv[ sys.argv.index("--edit_tab") + 1]
|
|
if "--" in tab: 1/0 # Failing this for the error message.
|
|
EditTab(tab)
|
|
|
|
except Exception as e:
|
|
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Tab Name Wasn't Specified!")
|
|
|
|
def Title(title):
|
|
|
|
data = Load()
|
|
data["title"] = title
|
|
|
|
Save(data)
|
|
|
|
print(clr["bold"]+clr["tbyl"]+title+clr["norm"]+" is set as title.")
|
|
|
|
def Port(port):
|
|
|
|
data = Load()
|
|
data["port"] = port
|
|
|
|
Save(data)
|
|
|
|
print(clr["bold"]+clr["tbyl"]+str(port)+clr["norm"]+" is set as the website's port.")
|
|
|
|
def AddTab(tab):
|
|
|
|
# Tab's Folder
|
|
|
|
tabsFolder = Folder()+"/tabs/"+Simplify(tab)
|
|
try: os.makedirs(tabsFolder)
|
|
except Exception as e:
|
|
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Could not add tab!", e)
|
|
return
|
|
|
|
# Tab's Config File
|
|
data = {"title":tab,
|
|
"icon":"folder"}
|
|
try:
|
|
with open(tabsFolder+"/config.json", "w") as save:
|
|
json.dump(data, save, indent=4, sort_keys=True)
|
|
|
|
except Exception as e:
|
|
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Cannot save tab's config!", e)
|
|
return
|
|
|
|
print(clr["bold"]+clr["tbyl"]+tab+clr["norm"]+" tab is added as "+clr["bold"]+"/"+Simplify(tab)+clr["norm"])
|
|
|
|
def EditTab(tab):
|
|
|
|
tabsFolder = Folder()+"/tabs/"+Simplify(tab)
|
|
os.system("nano "+tabsFolder+"/config.json")
|
|
|
|
|
|
|
|
|
|
|