-
Notifications
You must be signed in to change notification settings - Fork 3
/
manipulator.py
138 lines (100 loc) · 3.32 KB
/
manipulator.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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from manager import write_json
import sys
import os
import datetime
import json
"""
Should be called to manipulate files.
"""
def add_testcase(problem_path):
print("Enter TestCase Input: (Press Enter at Blank Line to Complete it)")
testcase_input = ""
number_of_empty_responses = 0
while(True):
line = input()
if line=="":
number_of_empty_responses+=1
if number_of_empty_responses == 2:
break
else:
testcase_input = testcase_input+"\n"+line
number_of_empty_responses=0
print("Enter TestCase Output: (Press Enter at Blank Line to Complete it)")
testcase_output = ""
number_of_empty_responses = 0
while(True):
line = input()
if line=="":
number_of_empty_responses+=1
if number_of_empty_responses == 2:
break
else:
testcase_output = testcase_output+"\n"+line
number_of_empty_responses=0
testcase_no = len([name for name in os.listdir(problem_path+"/Input") if os.path.isfile(os.path.join(problem_path+"/Input", name))])
print("Creating Testcase...")
testcase_in = open(problem_path+"/Input/"+"in"+str(testcase_no)+".txt","w+")
testcase_out = open(problem_path+"/Output/"+"out"+str(testcase_no)+".txt","w+")
testcase_in.write(testcase_input)
testcase_out.write(testcase_output)
testcase_in.close()
testcase_out.close()
return None
def view_testcase(problem_path, number):
"""
Just print testcase and expected output.
"""
return None
def run_testcase(problem_path, number):
"""
Just run test case of perticular number
"""
return None
def add_template(template_path, problem_path, line_no):
"""
Add template at line_no in problem code at problem_path
"""
return None
def backup_current(problem_path,problem_file_path):
if(problem_path[-1]!="/"):
problem_path = problem_path+"/"
backup_folder_path = problem_path+"Backup/"
if(not os.path.exists(backup_folder_path)):
os.mkdir(backup_folder_path)
title = input("Title of Backup: ")
comments = input("Comments: ")
backup_no = (len([name for name in os.listdir(backup_folder_path) if os.path.isfile(name)])/2)+1
file_name = backup_folder_path+"backup"+str(backup_no)
detail_name = backup_folder_path+"details"+str(backup_no)+".json"
code = open(problem_file_path,"r")
backup_code = open(file_name,"a")
code_txt = code.read().strip()
code.close()
backup_code.write(code_txt)
backup_code.close()
details = {"title": title,
"comments": comments,
"timestamp": str(datetime.datetime.now())}
write_json(details,detail_name)
print("\nBackup Created!")
return None
def get_backup(problem_path):
"""
Show backups and user should be able to retrive previous backup.
"""
return None
def handle_tc(command):
return None
def handle_template(command):
return None
def handle_backup(command):
return None
def main(command):
if(command[0]=="tc"):
handle_tc(command[1:])
elif(command[0]=="temp"):
handle_template(command[1:])
elif(command[0]=="save"):
handle_backup(command[1:])
if __name__=="__main__":
main(sys.argv[1:])