# 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
    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)
    p.close()


def __FIXME_retrieve_report(remote, port, sessionid):
    url = REPORTBASE.format(host=remote, port=port, sessionid=sessionid)
    print("Fetching %s" % url)
    #statusdata = urllib2.urlopen(url).read()
    _statusfile = "/home/fdeutsch/dev/ovirt/igor/daemon/igor/data/st.xml"
    #_junitfile = "/home/fdeutsch/dev/ovirt/igor/daemon/igor/data/st.junit.xml"
    statusdata = open(_statusfile).read()

    xsltfile = reports.TRANSFORM_MAP["job-junit"]
    statusxml = etree.XML(statusdata)
    junitxml = reports.transform_xml(xsltfile, statusxml)

# 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

    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)
    p.close()


def __FIXME_retrieve_report(remote, port, sessionid):
    url = REPORTBASE.format(host=remote, port=port, sessionid=sessionid)
    print("Fetching %s" % url)
    #statusdata = urllib2.urlopen(url).read()
    _statusfile = "/home/fdeutsch/dev/ovirt/igor/daemon/igor/data/st.xml"
    #_junitfile = "/home/fdeutsch/dev/ovirt/igor/daemon/igor/data/st.junit.xml"
    statusdata = open(_statusfile).read()

    xsltfile = reports.TRANSFORM_MAP["job-junit"]
    statusxml = etree.XML(statusdata)
    junitxml = reports.transform_xml(xsltfile, statusxml)

    junitdata = reports.to_xml_str(junitxml)