Exemplo n.º 1
0
def __create_sg_connection(shotgun_cfg_path,
                           evaluate_script_user,
                           user="******"):
    """
    Creates a standard toolkit shotgun connection.

    :param shotgun_cfg_path: path to a configuration file to read settings from
    :param evaluate_script_user: if True, the id of the script user will be 
                                 looked up and returned.
    :param user: If a multi-user config is used, this is the user to create the connection for.
    
    :returns: tuple with (sg_api_instance, script_user_dict) where script_user_dict is None if
              evaluate_script_user is False else a dictionary with type and id keys. 
    """

    # get connection parameters
    config_data = __get_sg_config_data(shotgun_cfg_path, user)

    # create API
    sg = Shotgun(config_data["host"],
                 config_data["api_script"],
                 config_data["api_key"],
                 http_proxy=config_data.get("http_proxy", None))

    # bolt on our custom user agent manager
    sg.tk_user_agent_handler = ToolkitUserAgentHandler(sg)

    script_user = None

    if evaluate_script_user:
        # determine the script user running currently
        # get the API script user ID from shotgun
        script_user = sg.find_one(
            "ApiUser", [["firstname", "is", config_data["api_script"]]],
            fields=["type", "id"])
        if script_user is None:
            raise TankError(
                "Could not evaluate the current App Store User! Please contact support."
            )

    return (sg, script_user)
Exemplo n.º 2
0
def __create_sg_connection(shotgun_cfg_path, evaluate_script_user, user="******"):
    """
    Creates a standard toolkit shotgun connection.

    :param shotgun_cfg_path: path to a configuration file to read settings from
    :param evaluate_script_user: if True, the id of the script user will be 
                                 looked up and returned.
    :param user: If a multi-user config is used, this is the user to create the connection for.
    
    :returns: tuple with (sg_api_instance, script_user_dict) where script_user_dict is None if
              evaluate_script_user is False else a dictionary with type and id keys. 
    """

    # get connection parameters
    config_data = __get_sg_config_data(shotgun_cfg_path, user)

    # create API
    sg = Shotgun(config_data["host"],
                 config_data["api_script"],
                 config_data["api_key"],
                 http_proxy=config_data.get("http_proxy", None))

    # bolt on our custom user agent manager
    sg.tk_user_agent_handler = ToolkitUserAgentHandler(sg)

    script_user = None

    if evaluate_script_user:
        # determine the script user running currently
        # get the API script user ID from shotgun
        script_user = sg.find_one("ApiUser",
                                          [["firstname", "is", config_data["api_script"]]],
                                          fields=["type", "id"])
        if script_user is None:
            raise TankError("Could not evaluate the current App Store User! Please contact support.")

    return (sg, script_user)
Exemplo n.º 3
0
    # validate the config data to ensure all fields are present
    if "host" not in config_data:
        raise TankError("Missing required field 'host' in config '%s'" % shotgun_cfg_path)
    if "api_script" not in config_data:
        raise TankError("Missing required field 'api_script' in config '%s'" % shotgun_cfg_path)
    if "api_key" not in config_data:
        raise TankError("Missing required field 'api_key' in config '%s'" % shotgun_cfg_path)

    # create API
    sg = Shotgun(config_data["host"],
                 config_data["api_script"],
                 config_data["api_key"],
                 http_proxy=config_data.get("http_proxy", None))

    # bolt on our custom user agent manager
    sg.tk_user_agent_handler = ToolkitUserAgentHandler(sg)

    script_user = None

    if evaluate_script_user:
        # determine the script user running currently
        # get the API script user ID from shotgun
        script_user = sg.find_one("ApiUser",
                                          [["firstname", "is", config_data["api_script"]]],
                                          fields=["type", "id"])
        if script_user is None:
            raise TankError("Could not evaluate the current App Store User! Please contact support.")

    return (sg, script_user)

    
Exemplo n.º 4
0
                        shotgun_cfg_path)
    if "api_script" not in config_data:
        raise TankError("Missing required field 'api_script' in config '%s'" %
                        shotgun_cfg_path)
    if "api_key" not in config_data:
        raise TankError("Missing required field 'api_key' in config '%s'" %
                        shotgun_cfg_path)

    # create API
    sg = Shotgun(config_data["host"],
                 config_data["api_script"],
                 config_data["api_key"],
                 http_proxy=config_data.get("http_proxy", None))

    # bolt on our custom user agent manager
    sg.tk_user_agent_handler = ToolkitUserAgentHandler(sg)

    script_user = None

    if evaluate_script_user:
        # determine the script user running currently
        # get the API script user ID from shotgun
        script_user = sg.find_one(
            "ApiUser", [["firstname", "is", config_data["api_script"]]],
            fields=["type", "id"])
        if script_user is None:
            raise TankError(
                "Could not evaluate the current App Store User! Please contact support."
            )

    return (sg, script_user)