def delete(self, indent): dirname = input( str(indent) + "What directory would you like to delete? ") try: os.rmdir(os.path.dirname(__file__) + "/../../Files/" + dirname) except: cprint("Please empty the directory first", "red")
def list(self): method_list = [ func for func in dir(self) if callable(getattr(self, func)) and not func.startswith("__") ] method_list.append("ls") for i in wrap(" ".join(method_list), width=termInfo.termCols() * (2.0 / 3.0)): cprint(i, "cyan")
def make(self, indent): try: dirname = input( str(indent) + "What directory would you like to make? ") os.mkdir(os.path.dirname(__file__) + "/../../Files/" + dirname) except: cprint( "There was an error while making this directory, it may already exist", "red")
def make(self, indent): try: filename = input(str(indent) + "File name: ") myFile = open( os.path.dirname(__file__) + "/../../Files/" + filename, "w") contents = input( str(indent) + "Please write to the file (only one line): ") myFile.write(contents) myFile.close() except: cprint( "There was an error while making the file, it may already exist", "red")
def logout(): string = "Logging out" sleep(0.5) for i in range(4): if string == "Logging out...": string = "Logging out" sleep(0.5) else: string = string + "." cprint(" " * 14, end="\r") cprint(string, "red", end="\r") sleep(0.5) exit(1)
def mainOps(): built_ins = BaseBuilt_Ins() while True: choice = ask() command = choice.split(' ', 1) selected_builtin = built_ins.get_builtin(command[0]) if selected_builtin is not None: selected_builtin() elif find_exec_in_path(command[0]) is not None: try: subprocess.call(command, shell=True) except subprocess.CalledProcessError: pass else: cprint("That is not a function. Type help or list for a list of commands", "red")
def choose(): for i in wrap(" ".join(dirOps), width=termInfo.termCols() * (2.0 / 3.0)): cprint(i, "cyan") choice = input(colored("pyOS/operations/file> ", "white")) choice = choice.lower() if choice == dirOps[0]: Directories.make(Directories, "\t\t") elif choice == dirOps[1]: Directories.delete(Directories, "\t\t") else: cprint( "That is not a function. Type help or commands for a list of commands", "red")
def login(): try: fp = open( os.path.dirname(__file__) + "\\..\\user\\user_login.info", "r+") for i, line in enumerate(fp): line = line.rstrip() if i == 0: global user user = line elif i == 1: global password password = line except: cprint("Please make an account", "yellow") user = input(colored("pyOS/Login/new username> ", "white")) password = input(colored("pyOS/Login/new password> ", "white")) credentials.change(user, password) __main__.clear() login() global userI global passwordI if user and password: cprint("User authentication needed!", "yellow") userI = input(colored("pyOS/Login/username> ", "white")) passwordI = input(colored("pyOS/Login/password> ", "white")) if userI == user: if passwordI == password: print("Access Granted") sleep(1) __main__.mainOS() else: cprint("Password incorrect", "red") login() else: cprint("Username incorrect", "red") login()
def mainOS(): clear() cprint("PyOS v" + version, "magenta") cprint("Copyright DualKeys Inc. 2017-2018.", "magenta") mainOps()
def choose(): for i in wrap(" ".join(mathOps), width=termInfo.termCols() * (2.0/3.0)): cprint(i, "cyan") choice = input(colored("pyOS/operations/math> ", "white")) choice = choice.lower() if choice == mathOps[0]: try: Math.add(Math, "\t\t") except: cprint("Error: Unexpected Input/Internal Error", "red") elif choice == mathOps[1]: try: Math.subtract(Math, "\t\t") except: cprint("Error: Unexpected Input/Internal Error", "red") elif choice == mathOps[2]: try: Math.multiply(Math, "\t\t") except: cprint("Error: Unexpected Input/Internal Error", "red") elif choice == mathOps[3]: try: Math.divide(Math, "\t\t") except: cprint("Error: Unexpected Input/Internal Error", "red") else: cprint("That is not a function. Type help or commands for a list of commands", "red")