-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadd_code.py
More file actions
66 lines (53 loc) · 1.87 KB
/
add_code.py
File metadata and controls
66 lines (53 loc) · 1.87 KB
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
from optparse import OptionParser
from pymongo import Connection
from bson.objectid import ObjectId
from bson.binary import Binary
def main():
# Setup CLI
parser = OptionParser()
parser.add_option('-i', '--input', help="Get input from this file.")
parser.add_option('-a', '--input2', help="Get input from this file.")
parser.add_option('-c', '--cmake', help="Get cmake from this file.")
# Parse CLI
(options, args) = parser.parse_args()
options = vars(options)
name = args[0]
code_name = args[1]
print options
connection = Connection()
database = connection.codingbooth
collection = database.codes
cur_object = collection.find_one({'name': name})
if cur_object:
object_id = cur_object['_id']
print "get document"
else:
print "create document"
object_id = collection.insert({'name': name})
with open(code_name, 'r') as infile:
print "insert code"
code = infile.read()
collection.update({'_id': ObjectId(object_id)},
{'$set': {'code': code}})
cmake = options['cmake']
if cmake:
print "insert cmake"
with open(cmake, 'r') as infile:
blob = infile.read()
collection.update({'_id': ObjectId(object_id)},
{'$set': {'cmake': blob}})
input_image = options['input']
print input_image
if input_image:
print "insert input"
with open(input_image, 'r') as infile:
blob = infile.read()
collection.update({'_id': ObjectId(object_id)},
{'$set':
{'inputs': [{'name': input_image, 'contents':Binary(blob)}]}})
run_parameters = raw_input('Enter the run parameters: ')
collection.update({'_id': ObjectId(object_id)},
{'$set': {'run_parameters': run_parameters}})
print "complete"
if __name__ == '__main__':
main()