Fixed updator

This commit is contained in:
OusmBlueNinja 2023-08-26 23:19:57 -05:00
parent e816eae2e5
commit b8448dea16
2 changed files with 138 additions and 143 deletions

View File

@ -1,133 +1,133 @@
#["builtin", "packages.builtin", ["echo", "ls", "rm", "clear", "cd", "ll"]] #["builtin", "packages.builtin", ["echo", "ls", "rm", "clear", "cd", "ll"]]
import os import os
import stat import stat
if os.name != 'nt': if os.name != 'nt':
import pwd import pwd
import grp import grp
import time import time
def echo(message: list) -> int: def echo(message: list) -> int:
try: try:
print(" ".join(message)) print(" ".join(message))
except: except:
return return
def ls(args): def ls(args):
del args del args
pass pass
def rm(files: list): def rm(files: list):
for file in files: for file in files:
os.remove(file) os.remove(file)
def clear(args): def clear(args):
del args del args
os.system('cls' if os.name == 'nt' else 'clear') os.system('cls' if os.name == 'nt' else 'clear')
def cd(args): def cd(args):
if len(args) == 0 or args[0] == "~": if len(args) == 0 or args[0] == "~":
new_path = os.path.expanduser("~") # Get the home directory path new_path = os.path.expanduser("~") # Get the home directory path
elif len(args) == 1: elif len(args) == 1:
new_path = os.path.abspath(args[0]) # Get the absolute path new_path = os.path.abspath(args[0]) # Get the absolute path
else: else:
print("Usage: cd <path> or cd ~") print("Usage: cd <path> or cd ~")
return return
try: try:
os.chdir(new_path) # Change the current working directory os.chdir(new_path) # Change the current working directory
except FileNotFoundError: except FileNotFoundError:
print("Directory not found.") print("Directory not found.")
except Exception as e: except Exception as e:
print(f"An error occurred: {e}") print(f"An error occurred: {e}")
def ls(args): def ls(args):
del args # You can remove this line if you're not using args del args # You can remove this line if you're not using args
blue_color = '\033[34m' blue_color = '\033[34m'
green_color = '\033[32m' green_color = '\033[32m'
white_color = '\033[37m' white_color = '\033[37m'
reset_color = '\033[0m' reset_color = '\033[0m'
dir_path = os.getcwd() dir_path = os.getcwd()
try: try:
with os.scandir(dir_path) as entries: with os.scandir(dir_path) as entries:
for entry in entries: for entry in entries:
if not entry.name.startswith('.'): if not entry.name.startswith('.'):
file_path = os.path.join(dir_path, entry.name) file_path = os.path.join(dir_path, entry.name)
file_stat = os.stat(file_path) file_stat = os.stat(file_path)
if stat.S_ISDIR(file_stat.st_mode): if stat.S_ISDIR(file_stat.st_mode):
print(blue_color + entry.name + '/' + reset_color, end=' ') print(blue_color + entry.name + '/' + reset_color, end=' ')
elif file_stat.st_mode & stat.S_IXUSR: elif file_stat.st_mode & stat.S_IXUSR:
print(green_color + entry.name + '*' + reset_color, end=' ') print(green_color + entry.name + '*' + reset_color, end=' ')
else: else:
print(white_color + entry.name + reset_color, end=' ') print(white_color + entry.name + reset_color, end=' ')
print() # Newline after listing print() # Newline after listing
except Exception as e: except Exception as e:
print(f"An error occurred: {e}") print(f"An error occurred: {e}")
def ll(args): def ll(args):
if os.name != 'nt': if os.name != 'nt':
print("This command only works for linux") print("This command only works for linux")
return return
dir_path = os.getcwd() dir_path = os.getcwd()
green_color = '\033[32m' green_color = '\033[32m'
blue_color = '\033[34m' blue_color = '\033[34m'
whiteColor = '\033[37m' whiteColor = '\033[37m'
orange_color = '\033[33m' orange_color = '\033[33m'
reset_color = '\033[0m' reset_color = '\033[0m'
try: try:
with os.scandir(dir_path) as entries: with os.scandir(dir_path) as entries:
for entry in entries: for entry in entries:
file_stat = entry.stat() file_stat = entry.stat()
file_name = entry.name file_name = entry.name
if os.name != 'nt': if os.name != 'nt':
pw = pwd.getpwuid(file_stat.st_uid) pw = pwd.getpwuid(file_stat.st_uid)
gr = grp.getgrgid(file_stat.st_gid) gr = grp.getgrgid(file_stat.st_gid)
is_hidden = (file_name and file_name[0] == '.') is_hidden = (file_name and file_name[0] == '.')
time_str = time.ctime(file_stat.st_mtime) time_str = time.ctime(file_stat.st_mtime)
if time_str.endswith('\n'): if time_str.endswith('\n'):
time_str = time_str[:-1] # Remove newline character time_str = time_str[:-1] # Remove newline character
permission_str = ( permission_str = (
(green_color + "r" if file_stat.st_mode & stat.S_IRUSR else whiteColor + "-") + (green_color + "r" if file_stat.st_mode & stat.S_IRUSR else whiteColor + "-") +
(blue_color + "w" if file_stat.st_mode & stat.S_IWUSR else whiteColor + "-") + (blue_color + "w" if file_stat.st_mode & stat.S_IWUSR else whiteColor + "-") +
((orange_color if is_hidden else green_color) + "x" if file_stat.st_mode & stat.S_IXUSR else whiteColor + "-") + ((orange_color if is_hidden else green_color) + "x" if file_stat.st_mode & stat.S_IXUSR else whiteColor + "-") +
(green_color + "r" if file_stat.st_mode & stat.S_IRGRP else whiteColor + "-") + (green_color + "r" if file_stat.st_mode & stat.S_IRGRP else whiteColor + "-") +
(blue_color + "w" if file_stat.st_mode & stat.S_IWGRP else whiteColor + "-") + (blue_color + "w" if file_stat.st_mode & stat.S_IWGRP else whiteColor + "-") +
((orange_color if is_hidden else green_color) + "x" if file_stat.st_mode & stat.S_IXGRP else whiteColor + "-") + ((orange_color if is_hidden else green_color) + "x" if file_stat.st_mode & stat.S_IXGRP else whiteColor + "-") +
(green_color + "r" if file_stat.st_mode & stat.S_IROTH else whiteColor + "-") + (green_color + "r" if file_stat.st_mode & stat.S_IROTH else whiteColor + "-") +
(blue_color + "w" if file_stat.st_mode & stat.S_IWOTH else whiteColor + "-") + (blue_color + "w" if file_stat.st_mode & stat.S_IWOTH else whiteColor + "-") +
((orange_color if is_hidden else green_color) + "x" if file_stat.st_mode & stat.S_IXOTH else whiteColor + "-") ((orange_color if is_hidden else green_color) + "x" if file_stat.st_mode & stat.S_IXOTH else whiteColor + "-")
) )
print( print(
"{:<11}{:>4} {:<8} {:<8} {:>8} {} {}{}".format( "{:<11}{:>4} {:<8} {:<8} {:>8} {} {}{}".format(
permission_str, permission_str,
file_stat.st_nlink, file_stat.st_nlink,
pw.pw_name, pw.pw_name,
gr.gr_name, gr.gr_name,
file_stat.st_size, file_stat.st_size,
time_str, time_str,
(blue_color if entry.is_dir() else (orange_color if is_hidden else green_color) if file_stat.st_mode & stat.S_IXUSR else whiteColor), (blue_color if entry.is_dir() else (orange_color if is_hidden else green_color) if file_stat.st_mode & stat.S_IXUSR else whiteColor),
file_name, file_name,
reset_color reset_color
) )
) )
except Exception as e: except Exception as e:
print(f"An error occurred: {e}") print(f"An error occurred: {e}")

View File

@ -4,23 +4,18 @@ import os, sys, requests, threading, time
fileList = [ fileList = [
"https://raw.githubusercontent.com/OusmBlueNinja/TermPY/main/packages/builtin.py", "https://raw.githubusercontent.com/OusmBlueNinja/TermPY/main/packages/builtin.py",
"https://raw.githubusercontent.com/OusmBlueNinja/TermPY/main/packages/echo.py",
"https://raw.githubusercontent.com/OusmBlueNinja/TermPY/main/packages/nano.py", "https://raw.githubusercontent.com/OusmBlueNinja/TermPY/main/packages/nano.py",
"https://raw.githubusercontent.com/OusmBlueNinja/TermPY/main/packages/netget.py", "https://raw.githubusercontent.com/OusmBlueNinja/TermPY/main/packages/netget.py",
"https://raw.githubusercontent.com/OusmBlueNinja/TermPY/main/packages/pip.py", "https://raw.githubusercontent.com/OusmBlueNinja/TermPY/main/packages/pip.py",
"https://raw.githubusercontent.com/OusmBlueNinja/TermPY/main/packages/upd.py" "https://raw.githubusercontent.com/OusmBlueNinja/TermPY/main/packages/update.py"
] ]
def download_and_save(url): def download_and_save(url):
r = requests.get(url) r = requests.get(url)
print(r) #print(r.text)
if 'Requests:' in r.text: fileInstallingCreator = os.path.join(os.path.dirname(os.path.realpath(__file__)), os.path.basename(url))
with open(fileInstallingCreator, "w") as newFile:
print(r.text) newFile.write(r.text)
print(r.headers['Content-Type'])
fileInstallingCreator = os.path.join(os.path.dirname(os.path.realpath(__file__)), os.path.basename(url))
with open(fileInstallingCreator, "w") as newFile:
newFile.write(r.text)
def upd(command): def upd(command):
input(f"Settings: {fileList}, {os.path.dirname(os.path.realpath(__file__))}\nPress enter to continue") input(f"Settings: {fileList}, {os.path.dirname(os.path.realpath(__file__))}\nPress enter to continue")