Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess , os , enum , time , sys
- class Types(enum.Enum) :
- TYPE = "<class 'type'>"
- INTEGER = "<class 'int'>"
- wd = "C:\\"
- prompt = wd + ">"
- path = "."
- def handleBuiltIn(txt) :
- global wd
- txt = calculateFormat(txt)
- if txt[0] == "cd" :
- if len(txt) < 2 :
- print(wd)
- return 0
- else :
- if checkPath(txt[1] , 1) :
- wd = os.path.abspath(txt[1])
- return 0
- else :
- return 1
- return 0
- if txt[0] == "ls" :
- if len(txt) < 2 :
- ls(wd)
- return 0
- else :
- if checkPath(txt[1] , 1) :
- ls(txt[1])
- return 0
- else :
- return 1
- return 2
- def checkPath(path , mode) :
- if os.path.exists(path) :
- if os.path.isdir(path) :
- if mode == 0 :
- print("The path is a directory")
- return False
- elif mode == 1 :
- return True
- else :
- if mode == 0 :
- return True
- elif mode == 1 :
- print("The path is a file")
- return False
- else :
- print("Invalid Path")
- return False
- def ls(path) :
- files = os.listdir(os.path.abspath(path))
- totalsize = 0
- print(".\n..")
- for file in files :
- if os.path.isfile(os.path.abspath(path) + os.sep + file) :
- print(file)
- else :
- print(file + os.sep)
- totalsize += os.path.getsize(os.path.abspath(path) + os.sep + file)
- print("\nTotal Size: " + str(totalsize) + "B")
- def updatePrompt() :
- global prompt
- global wd
- prompt = wd + ">"
- os.chdir(wd)
- def calculateFormat(cmd) :
- i = 0
- cmd = list(cmd)
- for c in cmd :
- if c == " " :
- cmd[i] = "§"
- i += 1
- cmd.append("§")
- calculated = list()
- temp = ""
- for c in cmd :
- if c == '§' :
- calculated.append(temp)
- temp = ""
- continue
- temp+=c
- return calculated
- def getPrograms() :
- files = os.listdir(path)
- programs = list()
- for file in files :
- if file.endswith(".exe") :
- programs.append(file)
- return programs
- def handle(txt) :
- if txt == "" :
- return 7
- code = handleBuiltIn(txt)
- if code < 1 :
- return 0
- programs = getPrograms()
- for program in programs :
- if txt.lower() == program.split(".")[0] :
- try :
- subprocess.run(path + os.sep + program, shell=True, check=True)
- return 0
- except :
- print("Process exited with non-0 exit code")
- return 1
- return code
- def handleError(error) :
- if str(type(error)) == Types.INTEGER.value :
- if error == 7 :
- print(end='')
- if error == 2 :
- print("Command not found")
- if error == -1 :
- print("Exiting..." , end='')
- time.sleep(1)
- sys.exit(0)
- def main() :
- print("Tecnosoft OS [Versione 1.2.4657]")
- print("Copyright <c> 2017 MRtecno98 Inc. Tutti i diritti riservati")
- try :
- while True :
- updatePrompt()
- txt = input("\n" + prompt)
- handleError(handle(txt))
- except KeyboardInterrupt :
- handleError(-1)
- if __name__ == "__main__" :
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement