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:
parent
9d034a79de
commit
f773f3fa91
45
helper/helper.py
Normal file
45
helper/helper.py
Normal 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
44
main.py
@ -11,12 +11,7 @@ if os.name != "nt":
|
||||
import threading
|
||||
import signal
|
||||
import requests
|
||||
|
||||
def handler(signum, frame):
|
||||
return
|
||||
|
||||
# Set the signal handler
|
||||
signal.signal(signal.SIGINT, handler)
|
||||
import subprocess
|
||||
|
||||
|
||||
|
||||
@ -25,12 +20,18 @@ 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 restart_program():
|
||||
python = sys.executable
|
||||
subprocess.call([python, __file__])
|
||||
sys.exit()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def clear():
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
@ -139,19 +140,25 @@ class packagemanager:
|
||||
|
||||
def install(self, name: str) -> int:
|
||||
try:
|
||||
print("Checking for package source.")
|
||||
with open(("./packages/"+name+".py"), "r") as f:
|
||||
f.close()
|
||||
if not os.path.exists(f"./packages/{name}.py"):
|
||||
raise FileNotFoundError(name)
|
||||
|
||||
|
||||
except FileNotFoundError:
|
||||
try:
|
||||
print("Downloading File from Source")
|
||||
url = f"https://raw.githubusercontent.com/OusmBlueNinja/TermPY/main/packages/{name}.py"
|
||||
r = requests.get(url)
|
||||
#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:
|
||||
newFile.write(r.text)
|
||||
except Exception as e:
|
||||
raise Exception("Package could not be found, make sure package source is in [ packages ] folder.")
|
||||
time.sleep(1)
|
||||
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:
|
||||
|
||||
@ -258,9 +265,10 @@ def main():
|
||||
|
||||
def start():
|
||||
try:
|
||||
print("")
|
||||
main()
|
||||
except KeyboardInterrupt:
|
||||
start()
|
||||
except (KeyboardInterrupt, EOFError):
|
||||
restart_program()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -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']]]
|
Loading…
Reference in New Issue
Block a user