Skip to content

Commit 32dd794

Browse files
committed
Add method to handle keyboard interrupt
1 parent 78d1f62 commit 32dd794

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

ACedIt/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def main():
4444

4545
except KeyboardInterrupt:
4646
# Clean up files here
47-
print 'Interruped manually. Exiting gracefully.'
47+
util.Utilities.handle_kbd_interrupt(args)
4848

4949

5050
if __name__ == '__main__':

ACedIt/util.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def check_cache(site, contest, problem):
110110
"""
111111

112112
Utilities.create_workdir_structure(site, contest)
113-
113+
114114
if problem is None:
115115
if not os.path.isdir(os.path.join(Utilities.cache_dir, site, contest)):
116116
os.makedirs(os.path.join(Utilities.cache_dir, site,
@@ -203,6 +203,26 @@ def cleanup(num_cases):
203203
if os.path.isfile('temp_output' + str(i)):
204204
os.remove('temp_output' + str(i))
205205

206+
@staticmethod
207+
def handle_kbd_interrupt(args):
208+
"""
209+
Method to handle keyboard interrupt
210+
"""
211+
from shutil import rmtree
212+
print 'Interrupted manually. Cleaning up...'
213+
214+
if args['problem'] is not None:
215+
path = os.path.join(Utilities.cache_dir, args['site'], args['contest'], args['problem'])
216+
if os.path.isdir(path):
217+
rmtree(path)
218+
else:
219+
path = os.path.join(Utilities.cache_dir, args['site'], args['contest'])
220+
if os.path.isdir(path):
221+
rmtree(path)
222+
223+
print 'Done. Exiting gracefully.'
224+
225+
206226
@staticmethod
207227
def run_solution(problem):
208228
"""

0 commit comments

Comments
 (0)