-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglance.py
63 lines (53 loc) · 1.49 KB
/
glance.py
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
import sys
import os
def if_not_exists(file_name):
"""
Function to check if the file with a given file name exists or not
...
Parameters
----------
file_name : str
File name of the file to check for existence
"""
file_path = os.getcwd() + '/' + file_name
if(os.path.exists(file_path) == False):
print(file_name + ': Cannot open \'' + file_name + '\' (No such file or directory)')
sys.exit()
def cat(f_name):
"""
Function to take a file name and print out the contents of the file
...
Parameters
----------
f_name : str
File name of the file to print contents of
"""
if f_name.startswith('>'):
file_name = f_name[1:]
if_not_exists(file_name)
f = open(file_name, 'a')
i = input()
f.write(i)
elif ">>" in f_name:
file_name = f_name.split('>>')
if_not_exists(file_name[1])
f1 = open(file_name[0], 'r')
f2 = open(file_name[1], 'a')
i = f1.read()
f2.write(i)
else:
file_name = f_name
if_not_exists(file_name)
f = open(file_name)
i = f.read()
print(i)
if(sys.argv[1] == '--help'):
f = open('help_files/help_cat.txt', 'r')
print(f.read())
elif(sys.argv[1] == "--version" or sys.argv[1] == "-v"):
print("cat (sea shell) 1.0.0")
elif(sys.argv[1] == "treasure-map"):
f = open('man_files/man_cat.txt', 'r')
print(f.read())
else:
cat(sys.argv[1])