Update shell.py

This commit is contained in:
JaydenMW 2021-02-20 21:16:23 +00:00
parent 94ff8842fb
commit 108ed6a3f9
1 changed files with 4 additions and 18 deletions

View File

@ -1,24 +1,18 @@
# Import Modules
import os import os
import subprocess import subprocess
import psutil import psutil
import platform import platform
import socket import socket
# Get System Information
RAM = psutil.virtual_memory() RAM = psutil.virtual_memory()
CPU = platform.processor() CPU = platform.processor()
OS = os_name = platform.system() OS = os_name = platform.system()
# Shell Version
VER = "PCLISH v0.0.4a" VER = "PCLISH v0.0.4a"
# Configuration
PROMPT = "shell@localhost" PROMPT = "shell@localhost"
# Command Interpretation -- This is the core of the shell
def execute_command(command): def execute_command(command):
# execute commands and handle piping#
try: try:
if "|" in command: if "|" in command:
s_in, s_out = (0, 0) s_in, s_out = (0, 0)
@ -54,20 +48,16 @@ def execute_command(command):
print("pclish: command not found: {}".format(command)) print("pclish: command not found: {}".format(command))
# Commands - Commands are defined here.
def pclish_cd(path): def pclish_cd(path):
# convert to absolute path and change directory#
try: try:
os.chdir(os.path.abspath(path)) os.chdir(os.path.abspath(path))
except Exception: except Exception:
print("cd: no such file or directory: {}".format(path)) print("cd: no such file or directory: {}".format(path))
def pclish_echo(): def pclish_echo(txt):
txt = input("What would you like to echo?:\n")
print(txt) print(txt)
def pclish_oscmd(): def pclish_oscmd(ARGS):
ARGS = input("What OS command would you like to run")
os.system(ARGS) os.system(ARGS)
def pclish_help(): def pclish_help():
@ -79,8 +69,7 @@ def pclish_help():
system: shows system information system: shows system information
mkdir: creates a directory mkdir: creates a directory
shtdwnsubsys: shuts down the sub system shtdwnsubsys: shuts down the sub system
oscmd: allows you to run an OS level command"""
note: you have to type mkdir by its self then it will ask for what you want to name the directory""")
def pclish_ls(): def pclish_ls():
print("pclish: this feature is not yet supported") print("pclish: this feature is not yet supported")
@ -88,9 +77,7 @@ def pclish_ls():
def pclish_ver(): def pclish_ver():
print(VER) print(VER)
def pclish_mkdir(): def pclish_mkdir(dir):
value = input("What would you like to name this new directory:\n")
dir = value
os.mkdir(dir) os.mkdir(dir)
def pclish_system(): def pclish_system():
@ -109,7 +96,6 @@ def pclish_shtdwnsubsys():
print("Shutting Down XCU Python Based Shell Env") print("Shutting Down XCU Python Based Shell Env")
exit() exit()
# Shell Prompt Customization and step 2 of command interpritation
def main(): def main():
while True: while True:
inp = input(PROMPT) inp = input(PROMPT)