-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfat_reader.py
More file actions
executable file
·89 lines (75 loc) · 2.25 KB
/
Copy pathfat_reader.py
File metadata and controls
executable file
·89 lines (75 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
import colorama
import sys
from auxiliary.fat_worker import FatWorker
from auxiliary.file_system import FileSystem
from auxiliary.CLI import CLI
from colorama import Fore, Style
from auxiliary.parsers import Parsers
def main():
colorama.init()
parser = Parsers.main_parser()
args = parser.parse_args()
file = args.file
try:
fs = FileSystem(FatWorker(file))
except PermissionError:
print(
'Not able to read image because of Permission Error.',
file=sys.stderr
)
print('Good bye')
return 1
except IsADirectoryError as e:
print(e, file=sys.stderr)
return 5
except FileNotFoundError as e:
print(e, file=sys.stderr)
return 6
cli = CLI(fs)
try:
while True:
try:
command = input(
f'{Fore.LIGHTCYAN_EX}{fs.current_dir}'
f'{Fore.BLUE}${Style.RESET_ALL}: '
)
if len(command) == 0:
continue
command = ' '.join(command.split(' '))
except UnicodeDecodeError as e:
print(
e.__doc__,
e.reason,
e.args[1][e.start:e.end],
f'at position {e.start}.'
)
continue
except EOFError:
fs.exit()
print('\nGood bye')
break
command = command.replace('\n', '')
util = command.split()[0]
params = command[len(util) + 1:]
if util == 'exit':
print('Good bye')
fs.exit()
break
try:
cli.execute_command(util, params)
except (FileNotFoundError, PermissionError) as e:
print(e)
continue
except OSError as e:
print('Critical Error occurred:', e, file=sys.stderr)
fs.exit()
print('Good bye', file=sys.stderr)
return 2
except KeyboardInterrupt as e:
fs.exit()
print(e, file=sys.stderr)
return 3
return 0
if __name__ == '__main__':
sys.exit(main())