Skip to content

Commit 74b42c9

Browse files
committed
Add feature clear cache for a given site
1 parent 9142a6f commit 74b42c9

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ optional arguments:
5151
--set-default-contest DEFAULT_CONTEST
5252
Name of default contest to be used when -c flag is not
5353
specified
54+
--clear-cache Clear cached test cases for a given site. Takes
55+
default site if -s flag is omitted
5456
5557
```
5658
During installation, the default site is set to `codeforces`. You can change it anytime using the above mentioned flags.

README.rst

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Usage
7373
--set-default-contest DEFAULT_CONTEST
7474
Name of default contest to be used when -c flag is not
7575
specified
76+
--clear-cache Clear cached test cases for a given site. Takes
77+
default site if -s flag is omitted
7678

7779
During installation, the default site is set to ``codeforces``. You
7880
can change it anytime using the above mentioned flags.

acedit/main.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66

77

88
def validate_args(args):
9+
"""
10+
Method to check valid combination of flags
11+
"""
912

1013
if args['default_site'] is not None or args['default_contest'] is not None:
1114
return
1215

16+
if args['clear_cache']:
17+
return
18+
1319
if not args['site'] == 'spoj' and args['contest'] is None:
1420
print 'Please specify contest code or set a default contest.'
1521
sys.exit(0)
@@ -31,10 +37,14 @@ def main():
3137
# set default site
3238
util.Utilities.set_constants('default_site', args['default_site'])
3339

34-
if args['default_contest']:
40+
elif args['default_contest']:
3541
# set default contest
3642
util.Utilities.set_constants('default_contest', args['default_contest'])
3743

44+
elif args['clear_cache']:
45+
# clear cached test cases
46+
util.Utilities.clear_cache(args['site'])
47+
3848
elif args['source']:
3949
# run code
4050
util.Utilities.run_solution(args)

acedit/util.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ def parse_flags(supported_sites):
6666
dest='default_contest',
6767
help='Name of default contest to be used when -c flag is not specified')
6868

69-
parser.set_defaults(force=False)
69+
parser.add_argument('--clear-cache',
70+
dest='clear_cache',
71+
action='store_true',
72+
help='Clear cached test cases for a given site. Takes default site if -s flag is omitted')
73+
74+
parser.set_defaults(force=False, clear_cache=False)
7075

7176
args = parser.parse_args()
7277

@@ -94,6 +99,7 @@ def parse_flags(supported_sites):
9499

95100
flags['problem'] = args.problem
96101
flags['force'] = args.force
102+
flags['clear_cache'] = args.clear_cache
97103
flags['source'] = args.source_file
98104
flags['default_site'] = args.default_site
99105
flags['default_contest'] = args.default_contest
@@ -138,6 +144,24 @@ def check_cache(site, contest, problem):
138144
contest, problem))
139145
return False
140146

147+
@staticmethod
148+
def clear_cache(site):
149+
"""
150+
Method to clear cached test cases
151+
"""
152+
153+
confirm = raw_input(
154+
'Remove entire cache for site %s? (y/N) : ' % (site))
155+
if confirm == 'y':
156+
from shutil import rmtree
157+
try:
158+
rmtree(os.path.join(Utilities.cache_dir, site))
159+
except:
160+
print 'Some error occured. Try again.'
161+
return
162+
os.makedirs(os.path.join(Utilities.cache_dir, site))
163+
print 'Done.'
164+
141165
@staticmethod
142166
def store_files(site, contest, problem, inputs, outputs):
143167
"""

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
packages=['acedit'],
2424

25-
version='1.0.4',
25+
version='1.0.5',
2626

2727
description='Download and test against sample test cases from any competitive programming website',
2828

0 commit comments

Comments
 (0)