-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.py
72 lines (56 loc) · 1.94 KB
/
init.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
#!/usr/bin/env python
import os, sys
nlab, nhw = 15, 10
# add proj names you want
proj_list = ['hog', 'cats', 'ants', 'lambdaing',
'scheme', 'scheme_stubbed'
]
def bash_shell(bash_command):
try:
return os.popen(bash_command).read().strip()
except:
return None
def delete_all():
if input("Please enter 'Yes': ") == 'Yes':
bash_shell('rm -rf Lab')
bash_shell('rm -rf zipfile')
bash_shell('rm -rf Homework')
bash_shell('rm -rf Project')
def download():
if not os.path.exists('zipfile'):
os.mkdir('zipfile')
os.chdir('zipfile')
for i in range(nlab):
if not os.path.exists('lab%02d.zip'%(i)):
bash_shell("wget --no-check-certificate https://www-inst.eecs.berkeley.edu/~cs61a/sp22/lab/lab%02d/lab%02d.zip"%(i,i))
for i in range(nhw):
if not os.path.exists('hw%02d.zip'%(i)):
bash_shell("wget --no-check-certificate https://www-inst.eecs.berkeley.edu/~cs61a/sp22/hw/hw%02d/hw%02d.zip"%(i,i))
for i in proj_list:
if not os.path.exists('%s.zip' % (i)):
bash_shell(
"wget --no-check-certificate https://www-inst.eecs.berkeley.edu/~cs61a/sp22/proj/%s/%s.zip"
% (i, i))
os.chdir('..')
def unzip():
outpath = 'Homework'
if not os.path.exists(outpath): os.mkdir(outpath)
for i in range(nhw):
bash_shell("unzip -n zipfile/hw%02d -d "%(i) + outpath)
outpath = 'Lab'
if not os.path.exists(outpath): os.mkdir(outpath)
for i in range(nlab):
bash_shell("unzip -n zipfile/lab%02d -d "%(i) + outpath)
outpath = 'Project'
if not os.path.exists(outpath):
os.mkdir(outpath)
for i in proj_list:
bash_shell("unzip -n zipfile/%s -d " % (i) + outpath)
def remove_zipfile():
bash_shell("rm -rf zipfile")
if __name__ == '__main__':
# download *.zip
print('-' * 20 + 'start' + '-' * 20)
download()
unzip()
remove_zipfile()