1
1
#!/usr/bin/env python3
2
2
3
- root = ["" , "root" ]
4
- dirs = []
5
- path = []
6
- current_path = [] or ["" , "root" ]
3
+ # root = ["", "root"]
4
+ # dirs = []
5
+ # path = []
6
+ # current_path = [] or ["", "root"]
7
+
8
+ dict_path = {
9
+ "root" : ["" , "root" ],
10
+ "current_path" : [] or ["" , "root" ],
11
+ "dirs" : [],
12
+ "path" : []
13
+ }
7
14
8
15
9
16
"""
10
17
* mkdir method is used to make/create directories
11
18
* [dirs delared global list for directories]
12
19
"""
13
20
def mkdir ():
14
- global dirs
15
- if dir in dirs :
16
- print ("ERR: DIRECTORY ALREADY EXISTS" )
21
+ global dict_path
22
+ if dir in dict_path [ "path" ] and dir in dict_path [ " dirs" ] :
23
+ print ("ERR: DIRECTORY ALREADY EXISTS" )
17
24
else :
18
- dirs .append (dir )
19
- path .append (dir )
25
+ dict_path ["dirs" ].append (dir )
20
26
print ("SUCC: CREATED" )
27
+ dict_path ["path" ].append (dir )
21
28
22
29
23
30
"""
24
31
* ls method is used to list all the directries
25
32
* path declared globally
26
33
"""
27
34
def ls ():
28
- global path
29
- if path == root :
30
- path = dirs
31
- path = path [0 ]
35
+ if dict_path ["path" ] == dict_path ["root" ]:
36
+ dict_path ["path" ] = dict_path ["dirs" ]
37
+ # dict_path["path"] = dict_path["path"]
32
38
print ("DIRS: " )
33
- print (* path , sep = "\t " )
39
+ print (* dict_path [ " path" ] , sep = "\t " )
34
40
35
41
36
42
"""
37
43
* cd method is used to change the directory
38
44
* current_path, dir, path declared globally
39
45
"""
40
46
def cd ():
41
- global current_path , dir , path
47
+ global dict_path
42
48
if dir == "" :
43
- current_path = root
44
- path = root
45
- elif dir in dirs :
46
- current_path .append (dir )
47
- path .clear ()
48
- elif dir == ".." :
49
- current_path .pop ()
50
- print ("SUCC: REACHED" )
51
- print (* current_path , sep = "/" )
52
- i = len (dirs ) - 1
53
- if dirs [i ] in path :
54
- i = i - 1
55
- path .pop ()
56
- path .append (dirs [i ])
57
- else :
58
- path .append (dirs [i ])
49
+ dict_path ["current_path" ] = dict_path ["root" ]
50
+ dict_path ["path" ] = dict_path ["root" ]
51
+ print ("ENTERED IN ROOT DIRECTORY" )
52
+ elif dir in dict_path ["dirs" ] and dir in dict_path ["path" ]:
53
+ dict_path ["current_path" ].append (dir )
54
+ dict_path ["path" ].clear ()
55
+ print ("ENTERED IN DIRECTORY: " , dict_path ["current_path" ])
59
56
else :
60
57
print ("ERR: INVALID PATH" )
61
58
@@ -65,22 +62,21 @@ def cd():
65
62
* current_path declared globally
66
63
"""
67
64
def pwd ():
68
- global current_path
65
+ global dict_path
69
66
print ("PATH: " )
70
- print (* current_path , sep = "/" )
67
+ print (* dict_path [ " current_path" ] , sep = "/" )
71
68
72
69
73
70
"""
74
71
* rm method is used to remove the directories created.
75
72
* dirs declared globabally
76
73
"""
77
74
def rm ():
78
- global dirs
79
- if dir in dirs :
80
- dirs .remove (dir )
81
- if dir in path :
82
- print ("SUCC: DELETED" )
83
- path .remove (dir )
75
+ global dict_path
76
+ if dir in dict_path ["dirs" ]:
77
+ dict_path ["dirs" ].remove (dir )
78
+ dict_path ["path" ].remove (dir )
79
+ print ("SUCC: DELETED" )
84
80
else :
85
81
print ("ERR: DIRECTORY DOES NOT EXIST" )
86
82
@@ -90,13 +86,11 @@ def rm():
90
86
* dirs, current_path, path declared globally.
91
87
"""
92
88
def session_clear ():
93
- global dirs
94
- dirs .clear ()
95
- global current_path
96
- current_path .clear ()
97
- current_path = root
98
- global path
99
- path .clear ()
89
+ global dict_path
90
+ dict_path ["dirs" ].clear ()
91
+ dict_path ["current_path" ].clear ()
92
+ dict_path ["current_path" ] = dict_path ["root" ] or dict_path ["" ]
93
+ dict_path ["path" ].clear ()
100
94
print ("SUCC: CLEARED: RESET TO ROOT" )
101
95
102
96
@@ -119,14 +113,14 @@ def commands(argument):
119
113
# Execute the function
120
114
func ()
121
115
else :
122
- print ("ERR: COMMANDS DOES NOT EXIST!" )
116
+ print ("ERR: COMMAND ENTERED DOES NOT EXIST!" )
123
117
124
118
125
119
print ("INFO - COMMANDS TO USE : mkdir, ls, cd, pwd, rm, session_clear, exit" )
126
120
print ("<Starting your application...>" )
127
121
128
122
while True :
129
- char = input ("$: " )
123
+ char = input ("$:" )
130
124
command_list = []
131
125
command_list .append (char .split (" " ))
132
126
char = command_list [0 ][0 ]
0 commit comments