Skip to content

Instantly share code, notes, and snippets.

@ramitsurana
Last active March 25, 2018 13:49
Show Gist options
  • Save ramitsurana/ed4b74e24baa9ae7ab6f83d0d7e1e14a to your computer and use it in GitHub Desktop.
Save ramitsurana/ed4b74e24baa9ae7ab6f83d0d7e1e14a to your computer and use it in GitHub Desktop.
Tree Description and Nodes Formation
from anytree import Node, RenderTree
import json
parent_node = Node('/')
print ("$ <Starting your application....>")
def get_input(input_cmd = input("$")):
#find length of input command. if length is 1 -> ls, pwd; if length = 2 cd </home/user>, makdir qwerty
length = len(input_cmd.split())
if length == 1:
if input_cmd == 'pwd':
list_node(input_cmd)
elif input_cmd == 'ls':
#put_ls()
list_node(input_cmd)
print("ls command")
else:
print("Wrong Command")
elif length == 2:
if input_cmd == 'session clear':
#put_clear()
print("Session cleared")
else:
pass
#split the input string into 2 parts; 1st part is command, 2nd part is path
cmd1, path1 = input_cmd.split(" ")
#print(b, b)
#words = path1.split("/")
#words = filter(None, words)
# Remove null values
#words[:] = [i for i in words if i != '']
#print(set(words))
#print(type(words))
#for i in words:
#print(i)
#print(type(i))
if cmd1 == 'cd':
#put_cd()
print("cd command")
elif cmd1 == 'rm':
#put_rm()
print("rm command")
if cmd1 == 'mkdir':
#put_mkdir()
print("mkdir command")
else:
print("invalid command")
def create_node(input_cmd):
node1 = Node(input_cmd, parent=parent_node)
output = print(node1)
def list_node(input_cmd):
y = str(parent_node)
o = y.split('Node')[1]
p = print(o)
def check_cmd():
if input_cmd == 'pwd' and file_name == NULL:
print ("PATH: /")
if input_cmd == 'ls':
print ('ls')
get_input()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment