-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit.py
113 lines (94 loc) · 3.08 KB
/
submit.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
https://powcoder.com
代写代考加微信 powcoder
Assignment Project Exam Help
Add WeChat powcoder
#!/usr/bin/python
import time
import os
import sys
import argparse
import json
import datetime
import hashlib
import glob
from nelson.gtomscs import submit
CKSUM_FILE_NAME = "spr19-cksum.txt"
def cleanup_cksum():
try:
os.remove(CKSUM_FILE_NAME)
except OSError:
pass
def cleanup_student_zip():
try:
os.remove('student.zip')
except OSError:
pass
# from https://stackoverflow.com/questions/3431825/generating-an-md5-checksum-of-a-file
def hash_bytestr_iter(bytesiter, hasher, ashexstr=False):
for block in bytesiter:
hasher.update(block)
return (hasher.hexdigest() if ashexstr else hasher.digest())
def file_as_blockiter(afile, blocksize=65536):
with afile:
block = afile.read(blocksize)
while len(block) > 0:
yield block
block = afile.read(blocksize)
def compute_cksum(file_list):
cksum = {}
for file in file_list:
if os.path.isdir(file): continue # skip directories
try:
stat = os.stat(file)
except OSError:
continue
if (stat.st_size > 1024 * 1024): continue
cksum[file] = hash_bytestr_iter(file_as_blockiter(open(file, 'rb')), hashlib.sha256(), True)
return cksum
def get_submit_cksum(quiz=""):
file_list = glob.glob("*")
if quiz != "": file_list += glob.glob("../*")
cksum = compute_cksum(file_list)
with open(CKSUM_FILE_NAME, 'w+') as f:
for key, value in cksum.items():
f.write('%64.64s %s\n' % (key, value))
def compute_readme_list():
readme_list = []
readme_candidates = ['readme-student.md', 'readme-student.pdf']
for candidate in readme_candidates:
if os.path.isfile(candidate):
readme_list.append(candidate)
if len(readme_list) is 0:
raise Exception("There is no valid student readme file to submit")
return readme_list
def main():
parser = argparse.ArgumentParser(description='Submits code to the Udacity site.')
parser.add_argument('quiz', choices = ['rpc', 'rpc_mt', 'readme'])
args = parser.parse_args()
path_map = {'rpc': 'rpc',
'rpc_mt': 'rpc_mt',
'readme': '.'}
quiz_map = {'rpc': 'pr4_rpc',
'rpc_mt': 'pr4_mt_rpc',
'readme': 'pr4_readme' }
files_map = {
'pr4_rpc': ['minify_via_rpc.c', 'minifyjpeg.h', 'minifyjpeg.c',
'minifyjpeg.x', 'minifyjpeg_clnt.c', 'minifyjpeg_xdr.c',
'minifyjpeg_svc.c'],
'pr4_mt_rpc': ['minify_via_rpc.c', 'minifyjpeg.h', 'minifyjpeg.c',
'minifyjpeg.x', 'minifyjpeg_clnt.c', 'minifyjpeg_xdr.c',
'minifyjpeg_svc.c'],
'pr4_readme': compute_readme_list()}
quiz = quiz_map[args.quiz]
cleanup_cksum()
os.chdir(path_map[args.quiz])
try:
get_submit_cksum(quiz)
except:
pass # ignore errors
if (os.path.exists(CKSUM_FILE_NAME)): files_map[quiz].append(CKSUM_FILE_NAME)
submit('cs6200', quiz, files_map[quiz])
cleanup_cksum()
cleanup_student_zip()
if __name__ == '__main__':
main()