-
Notifications
You must be signed in to change notification settings - Fork 1
/
start.py
89 lines (63 loc) · 2.53 KB
/
start.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
#!/bin/env python
'''
survey.py: plugin to work with expfactory package to generate survey
Copyright (C) 2017 Vanessa Sochat.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
'''
import argparse
from expfactory.logger import bot
import sys
import os
## MAIN ########################################################################
def get_parser():
parser = argparse.ArgumentParser(
description="expfactory: generate survey from config.json and question file")
parser.add_argument("--robot",'-r', dest='robot',
choices=['survey', 'jspsych'],
help="the survey robot to recruit!",
type=str, default="jspsych")
parser.add_argument("--port",'-p', dest='port',
help="port to run webserver",
type=int, default=3030)
parser.add_argument("--headless", dest='headless',
help="start a display before browser",
action="store_true", default=False)
parser.add_argument("--browser",'-b', dest='browser',
choices=['Firefox', 'Chrome'],
help="browser driver to use for the robot",
type=str, default="Chrome")
parser.add_argument('folders', nargs="+",
help='experiments for robot testing')
return parser
def main():
parser = get_parser()
try:
args = parser.parse_args()
except:
sys.exit(0)
print('Recruiting %s robot!' %args.robot)
folders = args.folders
if len(folders) == 0:
folders = [os.getcwd()]
# The drivers must be on path
here = os.path.abspath(os.path.dirname(__file__))
os.environ['PATH'] = "%s/drivers:%s" %(here,os.environ['PATH'])
# Load the robot!
if args.robot == 'jspsych':
from drivers.jspsych import JsPsychRobot as Robot
elif args.robot == 'survey':
from drivers.survey import SurveyRobot as Robot
robot = Robot(browser=args.browser, port=args.port, headless=args.headless)
for folder in folders:
folder = os.path.abspath(folder)
if not os.path.exists(folder):
bot.error("Cannot find %s, check that path exists." %folder)
else:
print('[folder] %s' %folder)
robot.validate(folder)
# Clean up shop!
robot.stop()
if __name__ == '__main__':
main()