-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfileops_v2.py
More file actions
79 lines (73 loc) · 1.85 KB
/
fileops_v2.py
File metadata and controls
79 lines (73 loc) · 1.85 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
#!/usr/bin/python
import os
print '1. append - Append a new line to the file.'
print '2. del - Delete a line from the file.'
print '3. disp - Display the file contents.'
print '4. commit - commit the file as a new version.'
print '5. revert - revert the file back to older version.'
print '6. quit - end the session.'
linesinfile=0
append=0
delete=0
mainline=""
filename="svc.txt"
if os.system('test -e svc.txt') != 0:
print 'made'
os.system('touch svc.txt')
while True:
print 'Enter command:'
comm = raw_input("")
if comm == "append":
if linesinfile == 20:
print "No more appending allowed!"
continue
#f = raw_input("Enter filename:")
line = raw_input("Enter line to append:")
if len(line)>10:
print "No more that 10 chars per line allowed!"
continue
fd = open(filename,'a')
fd.write(line+'\n')
print 'Line appended in file ',filename
fd.close()
append=1
delete=0
mainline=line
linesinfile=linesinfile+1
if comm == "del":
if linesinfile == 0:
print "Cant delete anymore!"
continue
#f = raw_input("Enter filename:")
line_no = raw_input("Enter line no. to delete:")
fd = open(filename,'r')
lines = fd.readlines()
fd.close()
fd = open(filename,'w')
i=0
for line in lines:
i=i+1
if i != int(line_no):
fd.write(line)
else:
mainline=line
fd.close()
delete=1
append=0
linesinfile=linesinfile-1
if comm == "disp":
#f = raw_input("Enter filename:")
os.system('cat '+filename)
if comm == "commit":
#f = raw_input("Enter filename:")
if append==1:
os.system('python svc_v2.py '+filename+' 0 '+mainline)
if delete==1:
os.system('python svc_v2.py '+filename+' '+line_no+' '+mainline)
print 'File commited!'
if comm == "revert":
#f = raw_input("Enter filename:")
ver = raw_input("Enter file version:")
os.system('python svc_v2.py '+filename+' '+ver)
if comm == "quit":
break