Stopped CTRL+C

and added the abulity to just run pakk install <package>. and it download it from the internet if it excists
This commit is contained in:
OusmBlueNinja 2023-08-26 23:56:55 -05:00
parent 9d034a79de
commit f773f3fa91
3 changed files with 72 additions and 19 deletions

45
helper/helper.py Normal file
View File

@ -0,0 +1,45 @@
import ast
class color:
green = "\033[1;32m"
blue = "\033[1;34m"
white = "\033[0m"
green = "\033[1;32m"
red = "\033[1;31m"
white = "\033[0m"
blue = "\033[1;34m"
orange = "\033[1;33m"
def update(self, packages):
with open(("./packages/pakk.conf"), "w") as f:
f.write(str(packages))
def toList(List: str) -> list:
newList = ast.literal_eval(List)
if isinstance(newList, list):
return newList
def install(name:str, Packages:list):
try:
if name in [row[0] for row in Packages.packages]:
raise Exception("Package already installed")
with open(("./packages/"+name+".py"), "r") as f:
line = f.readline()
line = line.strip("#")
# ... (existing code)
print("Installing Package")
Packages.packages.append(toList(line))
Packages.update(Packages.packages)
print(f"\n{color.green}Success:{color.white} Successfully installed {name}.")
except Exception as e:
raise Exception(f"{color.red}{e}")

44
main.py
View File

@ -11,12 +11,7 @@ if os.name != "nt":
import threading import threading
import signal import signal
import requests import requests
import subprocess
def handler(signum, frame):
return
# Set the signal handler
signal.signal(signal.SIGINT, handler)
@ -25,12 +20,18 @@ class color:
green = "\033[1;32m" green = "\033[1;32m"
blue = "\033[1;34m" blue = "\033[1;34m"
white = "\033[0m" white = "\033[0m"
green = "\033[1;32m"
red = "\033[1;31m" red = "\033[1;31m"
white = "\033[0m"
blue = "\033[1;34m"
orange = "\033[1;33m" orange = "\033[1;33m"
def restart_program():
python = sys.executable
subprocess.call([python, __file__])
sys.exit()
def clear(): def clear():
os.system('cls' if os.name == 'nt' else 'clear') os.system('cls' if os.name == 'nt' else 'clear')
@ -139,19 +140,25 @@ class packagemanager:
def install(self, name: str) -> int: def install(self, name: str) -> int:
try: try:
print("Checking for package source.") if not os.path.exists(f"./packages/{name}.py"):
with open(("./packages/"+name+".py"), "r") as f: raise FileNotFoundError(name)
f.close()
except FileNotFoundError: except FileNotFoundError:
try: print("Downloading File from Source")
url = f"https://raw.githubusercontent.com/OusmBlueNinja/TermPY/main/packages/{name}.py" url = f"https://raw.githubusercontent.com/OusmBlueNinja/TermPY/main/packages/{name}.py"
r = requests.get(url) r = requests.get(url)
#print(r.text) #print(r.text)
fileInstallingCreator = os.path.join(os.path.dirname(os.path.realpath(__file__)), os.path.basename(url)) fileInstallingCreator = os.path.join(os.path.dirname(os.path.realpath(__file__)), "packages", name+".py")
print("Saving file to disk")
with open(fileInstallingCreator, "w") as newFile: with open(fileInstallingCreator, "w") as newFile:
newFile.write(r.text) newFile.write(r.text)
except Exception as e: time.sleep(1)
raise Exception("Package could not be found, make sure package source is in [ packages ] folder.") call("helper.helper", "install", name, Packages)
print(f"{color.orange}WARNING: {color.white}Restarting Program")
restart_program()
except Exception as e:
raise Exception(f"Package could not be found, make sure package source is in [ packages ] folder. {e}")
try: try:
@ -258,9 +265,10 @@ def main():
def start(): def start():
try: try:
print("")
main() main()
except KeyboardInterrupt: except (KeyboardInterrupt, EOFError):
start() restart_program()
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -1 +1 @@
[['builtin', 'packages.builtin', ['echo', 'ls', 'rm', 'clear', 'cd', 'll']], ['upd', 'packages.update', ['upd']], ['pip', 'packages.pip', ['pip']]] [['builtin', 'packages.builtin', ['echo', 'ls', 'rm', 'clear', 'cd', 'll']], ['netget', 'packages.netget', ['netget']], ['netget', 'packages.netget', ['netget']], ['netget', 'packages.netget', ['netget']]]