Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/HUSKI3/Spark
Browse files Browse the repository at this point in the history
  • Loading branch information
Linkus authored and Linkus committed Jun 4, 2021
2 parents 6a49b5b + 909d4bc commit bf7cba0
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 34 deletions.
Empty file modified deploy
100755 → 100644
Empty file.
6 changes: 6 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
build: spark
@echo nothin much here

fish: spark
@sudo cp spark /usr/bin/spark

Empty file modified nano
100755 → 100644
Empty file.
126 changes: 92 additions & 34 deletions spark
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,42 @@ from pathlib import Path
from itertools import cycle
from shutil import get_terminal_size
from threading import Thread
from time import sleep
from time import *


#
# ==============================================
# MERROR
# ==============================================
#

point = "•"


class merrors:
def __init__(self):
self.errors = []

def error(self, msg):
print("\u001b[31m", point, f"[ERROR] {msg}")
self.errors += ["Error", msg, time.strftime("%H:%M:%S", time.localtime())]

def bigpanik(self):
print("\u001b[31m", point,
f"[PANIC] The program could not handle the request")
self.errors += ["Panic", time.strftime("%H:%M:%S", time.localtime())]

def getall(self):
return self.errors
#USAGE
#error("Could not load anything oopsie")


#
# ==============================================
# LOADER
# ==============================================
#


class Loader:
Expand Down Expand Up @@ -57,6 +92,10 @@ class Loader:
self.stop()






#
# ==============================================
# Ezconf
Expand Down Expand Up @@ -101,6 +140,11 @@ class ezconfig:
:param var: variable to get
:return var_val:
"""

# colours
fail = "\u001b[31m"
reset = "\u001b[0m"

#update datajson
self.read(self.filename)
try:
Expand All @@ -110,11 +154,11 @@ class ezconfig:
var_val = p.sub('\"', str(var_val))
return json.loads(str(var_val))[str(args[0])]
except Exception as e:
print("[1] could not get variable ["+str(var)+"] does it exist in "+self.filename+"?\nPython error: "+str(e))
print(fail+"[1] "+reset+ "could not get variable ["+str(var)+"] does it exist in "+self.filename+"?\nPython error: "+str(e))
print(self.datajson)
quit()
if var_val == None:
print("[2] could not get variable ["+str(var)+"]. It equals to None, is there a python problem?")
print(fail+"[2] "+reset+ "could not get variable ["+str(var)+"]. It equals to None, is there a python problem?")
quit()
else:
return var_val
Expand Down Expand Up @@ -203,12 +247,22 @@ def hex_to_rgb(hex):
hex = hex.replace('#', '')
return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))



# *boss music plays*

#
# ==============================================
# Spark
# ==============================================
#

# Path (made vars so easy to manage)
checkfile = "/usr/spark/spark.check"
dimensions_cfg = "/usr/spark/dimensions/dimensions.config"



# Colours:
reset = "\u001b[0m"
valid = "\u001b[32m"
Expand All @@ -217,22 +271,15 @@ fail = "\u001b[31m"
# Paths
def dirs(sudo):
try:
with open("/usr/spark/spark.check","r") as f:
with open(checkfile ,"r") as f:
f.read()
return 0
except:
if sudo:
os.system("sudo mkdir -p /usr/spark")
os.system("sudo mkdir -p /usr/spark/tmp")
os.system("sudo mkdir -p /usr/spark/packs && sudo touch /usr/spark/packs/installed && sudo touch /usr/spark/spark.check && sudo chmod 777 /usr/spark/packs/installed")
os.system("sudo mkdir -p /usr/spark/dimensions && sudo touch /usr/spark/dimensions/dimensions.config")
os.system("sudo mkdir -p /usr/spark/installed/_local")
else:
os.system(" mkdir -p /usr/spark")
os.system(" mkdir -p /usr/spark/tmp")
os.system(" mkdir -p /usr/spark/packs && touch /usr/spark/packs/installed && touch /usr/spark/spark.check && chmod 777 /usr/spark/packs/installed")
os.system(" mkdir -p /usr/spark/dimensions && touch /usr/spark/dimensions/dimensions.config")
os.system(" mkdir -p /usr/spark/installed/_local")
os.system("{}mkdir -p /usr/spark".format("sudo " if sudo else ""))
os.system("{}mkdir -p /usr/spark/tmp".format("sudo " if sudo else ""))
os.system("{}mkdir -p /usr/spark/packs && sudo touch /usr/spark/packs/installed && sudo touch /usr/spark/spark.check && sudo chmod 777 /usr/spark/packs/installed".format("sudo " if sudo else ""))
os.system("{}mkdir -p /usr/spark/dimensions && sudo touch /usr/spark/dimensions/dimensions.config".format("sudo " if sudo else ""))
os.system("{}mkdir -p /usr/spark/installed/_local".format("sudo " if sudo else ""))
return 1

# Help command
Expand All @@ -252,23 +299,29 @@ Usage:
""")

# Get dimensions information

# this is not a dic joke :kek:
sample_dim = ("""
{
"name":"dimensions_config",
"sources":[{
"name":"spark_official",
"url":"https://sparkofficial.ubuntulove2004.repl.co/",
"date":"",
"packs":[
"none"
]
}]
}""")

def dim():
dimensions = ezconfig()
try:
exit_code = dimensions.read("/usr/spark/dimensions/dimensions.config")
if exit_code == 1:
with open("/usr/spark/dimensions/dimensions.config","w+") as f:
f.write("""{
"name":"dimensions_config",
"sources":[{
"name":"spark_official",
"url":"https://sparkofficial.ubuntulove2004.repl.co/",
"date":"",
"packs":[
"none"
]
}]
}""")
f.write(sample_dim)

return "No dimensions set, fixing... "+valid+"fixed!"+reset
return 0
except Exception as e:
Expand All @@ -278,9 +331,13 @@ def dim():
def up_dim(silent=False):
dimensions = ezconfig()
try:
exit_code = dimensions.read("/usr/spark/dimensions/dimensions.config")

# dimensions_cfg: /usr/spark/dimensions/dimensions.config
exit_code = dimensions.read(dimensions_cfg)

if exit_code == 1:
return 1

else:
for source in dimensions.get('sources'):
if not silent:
Expand Down Expand Up @@ -399,11 +456,12 @@ def install(package,force=False, spec_ver=None):
inst=False
inst_list = []
else:
deps = []
deps = [] # unused var?
predeps = pack['depends']
inst=False
inst_list = []
dep_missing = False

for dep in predeps:
#print("dep in predeps 1 loop:",dep)
if '==' in dep:
Expand Down Expand Up @@ -443,7 +501,7 @@ def install(package,force=False, spec_ver=None):
print("Dependencies that are present:",inst_list)
print(reset)
inp = input("Install? [y/n] ")
if inp == "y" or inp == "Y":
if inp in ['Y', 'y']:
if 'depends' in pack:
if pack['depends']:
predeps.reverse()
Expand Down Expand Up @@ -524,7 +582,7 @@ def uninstall(package,force=False):
if ver_found:
print("If you manually removed the package,\nwould you like to remove it's entry?")
c = input("Remove? [Y/N] ")
if c == "Y" or c == "y":
if c in ['Y', 'y']:
return True
else:
return False
Expand All @@ -538,15 +596,15 @@ def uninstall(package,force=False):
if "uninstall" in make:
#print("Makefile has uninstall!")
c = input("Uninstall? [Y/N] ")
if c == "y" or c == "Y":
if c in ['Y', 'y']:
os.system("cd "+path_dir+" && make uninstall")
return True
else:
return False
print(fail+"Can't locate package source but directory is present?"+reset)
print("If you manually removed the package,\nwould you like to remove it's entry?")
c = input("Remove? [Y/N] ")
if c == "Y" or c == "y":
if c in ['Y', 'y']:
return True
else:
return False
Expand All @@ -556,7 +614,7 @@ def uninstall(package,force=False):
print(fail+"Package is installed but the source path is missing!"+reset)
print("If you manually removed the package,\nwould you like to remove it's entry?")
c = input("Remove? [Y/N] ")
if c == "Y" or c == "y":
if c in ['Y', 'y']:
return True
else:
return False
Expand Down

0 comments on commit bf7cba0

Please sign in to comment.