Beispiel #1
0
def list_requesters():
    """Lists all registered requesters"""
    from mephisto.core.local_database import LocalMephistoDB
    from tabulate import tabulate

    db = LocalMephistoDB()
    requesters = db.find_requesters()
    dict_requesters = [r.to_dict() for r in requesters]
    click.echo(tabulate(dict_requesters, headers="keys"))
Beispiel #2
0
def register_provider(args):
    """Register a requester with a crowd provider"""
    if len(args) == 0:
        click.echo(
            "Usage: mephisto register <provider_type> --arg1:value --arg2:value"
        )
        return

    from mephisto.core.local_database import LocalMephistoDB
    from mephisto.core.registry import get_crowd_provider_from_type
    from mephisto.core.argparse_parser import parse_arg_dict, get_extra_argument_dicts

    provider_type, requester_args = args[0], args[1:]
    args_dict = dict(arg.split(":") for arg in requester_args)
    transformed = dict((key, {
        "option_string": key,
        "value": value
    }) for (key, value) in args_dict.items())

    crowd_provider = get_crowd_provider_from_type(provider_type)
    RequesterClass = crowd_provider.RequesterClass

    if len(requester_args) == 0:
        from tabulate import tabulate

        params = get_extra_argument_dicts(RequesterClass)
        for param in params:
            click.echo(param["desc"])
            click.echo(tabulate(param["args"].values(), headers="keys"))
        return

    try:
        parsed_options = parse_arg_dict(RequesterClass, transformed)
    except Exception as e:
        click.echo(str(e))

    if "name" not in parsed_options:
        click.echo("No name was specified for the requester.")

    db = LocalMephistoDB()
    requesters = db.find_requesters(requester_name=parsed_options["name"])
    if len(requesters) == 0:
        requester = RequesterClass.new(db, parsed_options["name"])
    else:
        requester = requesters[0]
    try:
        requester.register(parsed_options)
        click.echo("Registered successfully.")
    except Exception as e:
        click.echo(str(e))
Beispiel #3
0
    def parse_launch_arguments(
            self, args=None) -> Tuple[str, str, "MephistoDB", Dict[str, Any]]:
        """
        Parse common arguments out from the command line, returns a 
        tuple of the architect type, the requester name to use, the
        MephistoDB to run with, and any  additional arguments parsed 
        out by the argument parser

        Defaults to a mock architect with a mock requester with no arguments
        """
        args, _unknown = self.parse_known_args(args=args)
        arg_dict = vars(args)
        requester_name = arg_dict["requester_name"]
        provider_type = arg_dict["provider_type"]
        architect_type = arg_dict["architect_type"]
        datapath = arg_dict["datapath"]

        if datapath is None:
            datapath = get_root_data_dir()

        database_path = os.path.join(datapath, "database.db")
        db = LocalMephistoDB(database_path=database_path)

        if requester_name is None:
            if provider_type is None:
                print("No requester specified, defaulting to mock")
                provider_type = "mock"
            if provider_type == "mock":
                req = get_mock_requester(db)
                requester_name = req.requester_name
            else:
                reqs = db.find_requesters(provider_type=provider_type)
                # TODO (#93) proper logging
                if len(reqs) == 0:
                    print(
                        f"No requesters found for provider type {provider_type}, please "
                        f"register one. You can register with `mephisto register {provider_type}`, "
                        f"or `python mephisto/client/cli.py register {provider_type}` if you haven't "
                        "installed Mephisto using poetry.")
                    exit(1)
                elif len(reqs) == 1:
                    req = reqs[0]
                    requester_name = req.requester_name
                    print(
                        f"Found one `{provider_type}` requester to launch with: {requester_name}"
                    )
                else:
                    req = reqs[-1]
                    requester_name = req.requester_name
                    print(
                        f"Found many `{provider_type}` requesters to launch with, "
                        f"choosing the most recent: {requester_name}")
        else:
            # Ensure provided requester exists
            reqs = db.find_requesters(requester_name=requester_name)
            if len(reqs) == 0:
                print(f"No requesters found under name {requester_name}, "
                      "have you registered with `mephisto register`?")
                exit(1)
            provider_type = reqs[0].provider_type

        # provider type and requester name now set, ensure architect
        if architect_type is None:
            if provider_type == "mock":
                architect_type = "local"
            elif provider_type == "mturk_sandbox":
                architect_type = "heroku"
            elif provider_type == "mturk":
                architect_type = "heroku"
            else:
                architect_type = "local"

            # TODO (#93) proper logging
            print(f"No architect specified, defaulting to architect "
                  f"`{architect_type}` for provider `{provider_type}`")

        if provider_type in ["mturk"]:
            input(
                f"This task is going to launch live on {provider_type}, press enter to continue: "
            )

        return architect_type, requester_name, db, arg_dict
Beispiel #4
0
#!/usr/bin/env python3

# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

from mephisto.providers.mturk.utils.script_utils import direct_soft_block_mturk_workers

from mephisto.core.local_database import LocalMephistoDB

db = LocalMephistoDB()
reqs = db.find_requesters(provider_type="mturk")
names = [r.requester_name for r in reqs]
print("Available Requesters: ", names)

requester_name = input("Select a requester to soft block from: ")
soft_block_qual_name = input("Provide a soft blocking qualification name: ")

workers_to_block = []
while True:
    new_id = input(
        "MTurk Worker Id to soft block (blank to block all entered): ")
    if len(new_id.strip()) == 0:
        break
    workers_to_block.append(new_id)

direct_soft_block_mturk_workers(db, workers_to_block, soft_block_qual_name,
                                requester_name)
Beispiel #5
0
# Copyright (c) Facebook, Inc. and its affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
"""
Utility script that finds, expires, and disposes HITs that may not
have been taking down during a run that exited improperly.
"""
from mephisto.providers.mturk.mturk_utils import (
    get_outstanding_hits,
    expire_and_dispose_hits,
)
from mephisto.core.local_database import LocalMephistoDB

db = LocalMephistoDB()

all_requesters = db.find_requesters(provider_type="mturk")
all_requesters += db.find_requesters(provider_type="mturk_sandbox")

print(
    "You have the following requesters available for mturk and mturk sandbox:")
r_names = [r.requester_name for r in all_requesters]
print(sorted(r_names))

use_name = input("Enter the name of the requester to clear HITs from:\n>> ")
while use_name not in r_names:
    use_name = input(f"Sorry, {use_name} is not in the requester list. "
                     f"The following are valid: {r_names}\n"
                     f"Select one:\n>> ")

requester = db.find_requesters(requester_name=use_name)[0]
client = requester._get_client(requester._requester_name)