本文整理汇总了Python中psiturk.psiturk_config.PsiturkConfig.set方法的典型用法代码示例。如果您正苦于以下问题:Python PsiturkConfig.set方法的具体用法?Python PsiturkConfig.set怎么用?Python PsiturkConfig.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psiturk.psiturk_config.PsiturkConfig
的用法示例。
在下文中一共展示了PsiturkConfig.set方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: deploy
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import set [as 别名]
def deploy(verbose):
"""Deploy app using Heroku to MTurk."""
# Load psiTurk configuration.
config = PsiturkConfig()
config.load_config()
# Set the mode.
config.set("Experiment Configuration", "mode", "deploy")
config.set("Server Parameters", "logfile", "-")
# Ensure that psiTurk is not in sandbox mode.
config.set("Shell Parameters", "launch_in_sandbox_mode", "false")
# Do shared setup.
deploy_sandbox_shared_setup(verbose=verbose)
示例2: sandbox
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import set [as 别名]
def sandbox(verbose, app):
"""Deploy app using Heroku to the MTurk Sandbox."""
# Load psiTurk configuration.
config = PsiturkConfig()
config.load_config()
# Set the mode.
config.set("Experiment Configuration", "mode", "sandbox")
config.set("Server Parameters", "logfile", "-")
# Ensure that psiTurk is in sandbox mode.
config.set("Shell Parameters", "launch_in_sandbox_mode", "true")
# Do shared setup.
deploy_sandbox_shared_setup(verbose=verbose, app=app)
示例3: deploy_sandbox_shared_setup
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import set [as 别名]
def deploy_sandbox_shared_setup(verbose=True, web_procs=1):
"""Set up Git, push to Heroku, and launch the app."""
if verbose:
OUT = None
else:
OUT = open(os.devnull, 'w')
(id, tmp) = setup(debug=False, verbose=verbose)
# Log in to Heroku if we aren't already.
log("Making sure that you are logged in to Heroku.")
ensure_heroku_logged_in()
# Change to temporary directory.
cwd = os.getcwd()
os.chdir(tmp)
# Commit Heroku-specific files to tmp folder's git repo.
cmds = ["git init",
"git add --all",
'git commit -m "Experiment ' + id + '"']
for cmd in cmds:
subprocess.call(cmd, stdout=OUT, shell=True)
time.sleep(0.5)
# Load psiTurk configuration.
config = PsiturkConfig()
config.load_config()
# Initialize the app on Heroku.
log("Initializing app on Heroku...")
subprocess.call(
"heroku apps:create " + id +
" --buildpack https://github.com/thenovices/heroku-buildpack-scipy",
stdout=OUT,
shell=True)
database_size = config.get('Database Parameters', 'database_size')
# Set up postgres database and AWS/psiTurk environment variables.
cmds = [
"heroku addons:create heroku-postgresql:{}".format(database_size),
"heroku pg:wait",
"heroku addons:create redistogo:small",
"heroku addons:create papertrail",
"heroku config:set HOST=" +
id + ".herokuapp.com",
"heroku config:set aws_access_key_id=" +
config.get('AWS Access', 'aws_access_key_id'),
"heroku config:set aws_secret_access_key=" +
config.get('AWS Access', 'aws_secret_access_key'),
"heroku config:set aws_region=" +
config.get('AWS Access', 'aws_region'),
"heroku config:set psiturk_access_key_id=" +
config.get('psiTurk Access', 'psiturk_access_key_id'),
"heroku config:set psiturk_secret_access_id=" +
config.get('psiTurk Access', 'psiturk_secret_access_id'),
"heroku config:set auto_recruit=" +
config.get('Experiment Configuration', 'auto_recruit'),
]
for cmd in cmds:
subprocess.call(cmd + " --app " + id, stdout=OUT, shell=True)
# Set the notification URL in the cofig file to the notifications URL.
config.set(
"Server Parameters",
"notification_url",
"http://" + id + ".herokuapp.com/notifications")
# Set the database URL in the config file to the newly generated one.
log("Saving the URL of the postgres database...")
db_url = subprocess.check_output(
"heroku config:get DATABASE_URL --app " + id, shell=True)
config.set("Database Parameters", "database_url", db_url.rstrip())
subprocess.call("git add config.txt", stdout=OUT, shell=True),
time.sleep(0.25)
subprocess.call(
'git commit -m "Save URLs for database and notifications"',
stdout=OUT,
shell=True)
time.sleep(0.25)
# Launch the Heroku app.
log("Pushing code to Heroku...")
subprocess.call("git push heroku HEAD:master", stdout=OUT,
stderr=OUT, shell=True)
dyno_type = config.get('Server Parameters', 'dyno_type')
num_dynos_web = config.get('Server Parameters', 'num_dynos_web')
num_dynos_worker = config.get('Server Parameters', 'num_dynos_worker')
#.........这里部分代码省略.........
示例4: debug
# 需要导入模块: from psiturk.psiturk_config import PsiturkConfig [as 别名]
# 或者: from psiturk.psiturk_config.PsiturkConfig import set [as 别名]
def debug(verbose):
"""Run the experiment locally."""
(id, tmp) = setup(debug=True, verbose=verbose)
# Drop all the tables from the database.
db.init_db(drop_all=True)
# Switch to the temporary directory.
cwd = os.getcwd()
os.chdir(tmp)
# Load psiTurk configuration.
config = PsiturkConfig()
config.load_config()
# Set the mode to debug.
config.set("Experiment Configuration", "mode", "debug")
config.set("Shell Parameters", "launch_in_sandbox_mode", "true")
config.set(
"Server Parameters",
"logfile",
os.path.join(cwd, config.get("Server Parameters", "logfile")))
# Swap in the HotAirRecruiter
os.rename("wallace_experiment.py", "wallace_experiment_tmp.py")
with open("wallace_experiment_tmp.py", "r+") as f:
with open("wallace_experiment.py", "w+") as f2:
f2.write("from wallace.recruiters import HotAirRecruiter\n")
for idx, line in enumerate(f):
if re.search("\s*self.recruiter = (.*)", line):
p = line.partition("self.recruiter =")
f2.write(p[0] + p[1] + ' HotAirRecruiter\n')
else:
f2.write(line)
os.remove("wallace_experiment_tmp.py")
# Set environment variables.
aws_vars = ['aws_access_key_id', 'aws_secret_access_key', 'aws_region']
for var in aws_vars:
if var not in os.environ:
os.environ[var] = config.get('AWS Access', var)
pt_vars = ['psiturk_access_key_id', 'psiturk_secret_access_id']
for var in pt_vars:
if var not in os.environ:
os.environ[var] = config.get('psiTurk Access', var)
if "HOST" not in os.environ:
os.environ["HOST"] = config.get('Server Parameters', 'host')
# Start up the local server
log("Starting up the server...")
# Try opening the psiTurk shell.
try:
p = pexpect.spawn("psiturk")
p.expect_exact("]$")
p.sendline("server on")
p.expect_exact("Experiment server launching...")
# Launche the experiment.
time.sleep(4)
host = config.get("Server Parameters", "host")
port = config.get("Server Parameters", "port")
subprocess.call(
'curl --data "" http://{}:{}/launch'.format(host, port),
shell=True)
log("Here's the psiTurk shell...")
p.interact()
except Exception:
print "\nCouldn't open the psiTurk shell. Internet connection okay?"
log("Completed debugging of experiment " + id + ".")
os.chdir(cwd)