# Path: igor/reports.py
# BASE_PATH = os.path.dirname(os.path.abspath(__file__))
# REPORT_PATH = os.path.join(BASE_PATH, "data")
# TRANSFORM_MAP = {
#     "job-rst": os.path.join(REPORT_PATH, "job-report.rst.xsl"),
#     "job-junit": os.path.join(REPORT_PATH, "job-report.junit.xsl"),
#     "testplan-rst": os.path.join(REPORT_PATH, "testplan-report.rst.xsl"),
#     "testplan-junit-xml": os.path.join(REPORT_PATH,
#                                        "testplan-report.junit.xsl"),
# }
# def job_status_to_report_json(txt):
# def job_status_to_report(d):
# def job_status_to_junit(d):
# def testplan_status_to_report(d):
# def testplan_status_to_junit_report(d):
# def _map_transform(d, t, rootname="status"):
# def transform_dict(stylefile, d, rootname):
# def transform_xml(stylefile, xml):
# def to_xml_str(etree_obj):
# 
# Path: igor/common.py
# REDIS_EVENTS_PUBSUB_CHANNEL_NAME = "igor.daemon.events"
# class routes(object):


from igor import reports, common
from lxml import etree
import logging
import sys
import redis
# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Author: Fabian Deutsch <fabiand@fedoraproject.org>
#

#
# DESCRTIPTION
#


REPORTBASE = "http://{host}:{port}/jobs/{sessionid}/status?format=xml"


def follow_events(server, port):
    r = redis.Redis(host=server, port=int(port))
    p = r.pubsub()
    p.subscribe(common.REDIS_EVENTS_PUBSUB_CHANNEL_NAME)
    for obj in p.listen():
        event = None
        xmlstr = str(obj["data"]).strip()
        if not xmlstr.startswith("<"):
            # Sometimes just an int is sent ...
            continue
        try:
            event = etree.XML(xmlstr)
        except:
            logging.exception("Failed to parse: %s -> %s" % (obj, xmlstr))
        if event is not None and event.attrib:
            yield event.attrib

# Path: igor/reports.py
# BASE_PATH = os.path.dirname(os.path.abspath(__file__))
# REPORT_PATH = os.path.join(BASE_PATH, "data")
# TRANSFORM_MAP = {
#     "job-rst": os.path.join(REPORT_PATH, "job-report.rst.xsl"),
#     "job-junit": os.path.join(REPORT_PATH, "job-report.junit.xsl"),
#     "testplan-rst": os.path.join(REPORT_PATH, "testplan-report.rst.xsl"),
#     "testplan-junit-xml": os.path.join(REPORT_PATH,
#                                        "testplan-report.junit.xsl"),
# }
# def job_status_to_report_json(txt):
# def job_status_to_report(d):
# def job_status_to_junit(d):
# def testplan_status_to_report(d):
# def testplan_status_to_junit_report(d):
# def _map_transform(d, t, rootname="status"):
# def transform_dict(stylefile, d, rootname):
# def transform_xml(stylefile, xml):
# def to_xml_str(etree_obj):
# 
# Path: igor/common.py
# REDIS_EVENTS_PUBSUB_CHANNEL_NAME = "igor.daemon.events"
# class routes(object):


# Path: igor/client/event.py
from igor import reports, common
from lxml import etree
import logging
import sys
import redis

# You should have received a copy of the GNU Lesser General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Author: Fabian Deutsch <fabiand@fedoraproject.org>
#

#
# DESCRTIPTION
#


REPORTBASE = "http://{host}:{port}/jobs/{sessionid}/status?format=xml"


def follow_events(server, port):
    r = redis.Redis(host=server, port=int(port))
    p = r.pubsub()
    p.subscribe(common.REDIS_EVENTS_PUBSUB_CHANNEL_NAME)
    for obj in p.listen():
        event = None
        xmlstr = str(obj["data"]).strip()
        if not xmlstr.startswith("<"):
            # Sometimes just an int is sent ...
            continue
        try:
            event = etree.XML(xmlstr)
        except:
            logging.exception("Failed to parse: %s -> %s" % (obj, xmlstr))
        if event is not None and event.attrib:
            yield event.attrib

    p.unsubscribe(common.REDIS_EVENTS_PUBSUB_CHANNEL_NAME)