class ParticipantHandler(object):

    """ Participant class as defined by the SkyNET API """

    def __init__(self):
        self.obs = None
        self.oscrc = None

    def handle_wi_control(self, ctrl):
        """ job control thread """
        pass

    def handle_lifecycle_control(self, ctrl):
        """ participant control thread """
        if ctrl.message == "start":
            if ctrl.config.has_option("obs", "oscrc"):
                self.oscrc = ctrl.config.get("obs", "oscrc")

    def setup_obs(self, namespace):
        """ setup the Buildservice instance using the namespace as an alias
            to the apiurl """

        self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace)

    def get_request(self, wid, req_id, diff):
        # Copied from api.py
        req = core.get_request(self.obs.apiurl, req_id)
        return self.obs.req_to_dict(req, action_diff=diff)

    def handle_wi(self, wid):
        """ """

        self.setup_obs(wid.fields.ev.namespace)

        req_id = assertMandatoryParameter(wid, "req_id")
        field = assertMandatoryParameter(wid, "field")

        # the result, in unicode string
        diff = False if wid.params.no_diff else True
        wid.set_field(field, self.get_request(wid, req_id, diff))
class ParticipantHandler(object):
    """ Participant class as defined by the SkyNET API """
    def __init__(self):
        self.obs = None
        self.oscrc = None

    def handle_wi_control(self, ctrl):
        """ job control thread """
        pass

    def handle_lifecycle_control(self, ctrl):
        """ participant control thread """
        if ctrl.message == "start":
            if ctrl.config.has_option("obs", "oscrc"):
                self.oscrc = ctrl.config.get("obs", "oscrc")

    def setup_obs(self, namespace):
        """ setup the Buildservice instance using the namespace as an alias
            to the apiurl """

        self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace)

    def get_request(self, wid, req_id, diff):
        # Copied from api.py
        req = core.get_request(self.obs.apiurl, req_id)
        return self.obs.req_to_dict(req, action_diff=diff)

    def handle_wi(self, wid):
        """ """

        self.setup_obs(wid.fields.ev.namespace)

        req_id = assertMandatoryParameter(wid, "req_id")
        field = assertMandatoryParameter(wid, "field")

        # the result, in unicode string
        diff = False if wid.params.no_diff else True
        wid.set_field(field, self.get_request(wid, req_id, diff))
    def setup_obs(self, namespace):
        """ setup the Buildservice instance using the namespace as an alias
            to the apiurl """

        self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace)
    def setup_obs(self, namespace):
        """ setup the Buildservice instance using the namespace as an alias
            to the apiurl """

        self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace)