def run(cabinmode=False, script=None, execute=None, quiet=False): using_libedit = 'libedit' in readline.__doc__ if using_libedit: print colorize('\n'.join([ 'libedit version of readline detected.', 'readline will not be well behaved, which may cause all sorts', 'of problems for the psiTurk shell. We highly recommend installing', 'the gnu version of readline by running "sudo pip install gnureadline".', 'Note: "pip install readline" will NOT work because of how the OSX', 'pythonpath is structured.' ]), 'red', False) sys.argv = [sys.argv[0]] # Drop arguments which were already processed in command_line.py #opt = docopt(__doc__, sys.argv[1:]) config = PsiturkConfig() config.load_config() server = control.ExperimentServerController(config) if cabinmode: shell = PsiturkShell(config, server) shell.check_offline_configuration() else: shell = PsiturkNetworkShell( config, server, \ config.getboolean('Shell Parameters', 'launch_in_sandbox_mode'), quiet=quiet) if script: with open(script, 'r') as temp_file: for line in temp_file: shell.onecmd_plus_hooks(line) elif execute: shell.onecmd_plus_hooks(execute) else: shell.cmdloop()
def run(cabinmode=False, script=None, execute=None, quiet=False): using_libedit = 'libedit' in readline.__doc__ if using_libedit: print colorize('\n'.join([ 'libedit version of readline detected.', 'readline will not be well behaved, which may cause all sorts', 'of problems for the psiTurk shell. We highly recommend installing', 'the gnu version of readline by running "sudo pip install gnureadline".', 'Note: "pip install readline" will NOT work because of how the OSX', 'pythonpath is structured.' ]), 'red', False) sys.argv = [sys.argv[0]] # Drop arguments which were already processed in command_line.py #opt = docopt(__doc__, sys.argv[1:]) config = PsiturkConfig() config.load_config() server = control.ExperimentServerController(config) if cabinmode: shell = PsiturkShell(config, server) shell.check_offline_configuration() else: shell = PsiturkNetworkShell( config, server, \ config.getboolean('Shell Parameters', 'launch_in_sandbox_mode'), quiet=quiet) if script: with open(script, 'r') as temp_file: for line in temp_file: shell.onecmd_plus_hooks(line) elif execute: shell.onecmd_plus_hooks(execute) else: shell.cmdloop()
def __init__(self, config=None, web_services=None, tunnel=None, sandbox=None): if not config: config = PsiturkConfig() config.load_config() self.config = config if web_services: self._cached_web_services = web_services if not tunnel: tunnel = TunnelServices(config) self.tunnel = tunnel if not sandbox: sandbox = config.getboolean('Shell Parameters', 'launch_in_sandbox_mode') self.sandbox = sandbox
def __init__(self, config=None, web_services=None, tunnel=None, sandbox=None): if not config: config = PsiturkConfig() config.load_config() self.config = config if web_services: self._cached_web_services = web_services if not tunnel: tunnel = TunnelServices(config) self.tunnel = tunnel if not sandbox: sandbox = config.getboolean('Shell Parameters', 'launch_in_sandbox_mode') self.sandbox = sandbox
import datetime import io, csv, json from sqlalchemy import Column, Integer, String, DateTime, Float, Text from db import Base from psiturk_config import PsiturkConfig config = PsiturkConfig() config.load_config() TABLENAME = config.get('Database Parameters', 'table_name') CODE_VERSION = config.get('Task Parameters', 'experiment_code_version') class Participant(Base): """ Object representation of a participant in the database. """ __tablename__ = TABLENAME uniqueid =Column(String(128), primary_key=True) assignmentid =Column(String(128), nullable=False) workerid = Column(String(128), nullable=False) hitid = Column(String(128), nullable=False) ipaddress = Column(String(128)) browser = Column(String(128)) platform = Column(String(128)) language = Column(String(128)) cond = Column(Integer) counterbalance = Column(Integer) codeversion = Column(String(128))
from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker, scoped_session from sqlalchemy.ext.declarative import declarative_base from psiturk_config import PsiturkConfig import re, os config = PsiturkConfig() config.load_config() r = re.compile("OPENSHIFT_(.+)_DB_URL") # Might be MYSQL or POSTGRESQL matches = filter(r.match, os.environ) if matches: DATABASE = "{}{}".format(os.environ[matches[0]], os.environ['OPENSHIFT_APP_NAME']) else: DATABASE = config.get('Database Parameters', 'database_url') if 'mysql://' in DATABASE.lower(): try: __import__('imp').find_module('pymysql') except ImportError: print("To use a MySQL database you need to install " "the `pymysql` python package. Try `pip install " "pymysql`.") exit() # internally use `mysql+pymysql://` so sqlalchemy talks to # the pymysql package DATABASE = DATABASE.replace('mysql://', 'mysql+pymysql://') engine = create_engine(DATABASE, echo=False, pool_recycle=3600) db_session = scoped_session(
# Setup flask from flask import Flask, render_template, render_template_string, request, \ jsonify # Setup database from db import db_session, init_db from models import Participant from sqlalchemy import or_, exc from psiturk_config import PsiturkConfig from experiment_errors import ExperimentError from psiturk.user_utils import nocache # Setup config CONFIG = PsiturkConfig() CONFIG.load_config() # Setup logging LOG_FILE_PATH = os.path.join(os.getcwd(), CONFIG.get("Server Parameters", \ "logfile")) LOG_LEVELS = [logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL] LOG_LEVEL = LOG_LEVELS[CONFIG.getint('Server Parameters', 'loglevel')] logging.basicConfig(filename=LOG_FILE_PATH, format='%(asctime)s %(message)s', level=LOG_LEVEL) # Status codes NOT_ACCEPTED = 0 ALLOCATED = 1 STARTED = 2
# Setup flask from flask import Flask, render_template, render_template_string, request, \ jsonify # Setup database from db import db_session, init_db from models import Participant from sqlalchemy import or_, exc from psiturk_config import PsiturkConfig from experiment_errors import ExperimentError from psiturk.user_utils import nocache # Setup config CONFIG = PsiturkConfig() CONFIG.load_config() # Setup logging LOG_FILE_PATH = os.path.join(os.getcwd(), CONFIG.get("Server Parameters", \ "logfile")) LOG_LEVELS = [ logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL ] LOG_LEVEL = LOG_LEVELS[CONFIG.getint('Server Parameters', 'loglevel')] logging.basicConfig(filename=LOG_FILE_PATH, format='%(asctime)s %(message)s', level=LOG_LEVEL) # Status codes