# Path: igor/client/junitless.py
# def clearscreen():
#     def __init__(self, txt, with_markup=True):
#     def plain(self):
#     def bold(self):
#     def italic(self):
#     def underline(self):
#     def inverse(self):
#     def markup(self):
#     def black(self):
#     def red(self):
#     def green(self):
#     def yellow(self):
#     def blue(self):
#     def magenta(self):
#     def cyan(self):
#     def white(self):
#     def write(self, msg):
#     def writeln(self, msg):
#     def indented(self, size=1):
#             def __enter__(self):
#             def __exit__(self, exc_type, exc_value, traceback):
#     def _indented(self, msg):
#     def warn(self, msg=None):
#     def error(self, msg):
#     def ok(self, msg=None):
#     def success(self, msg):
#     def fail(self, msg):
#     def header(self, msg):
#     def subhead(self, msg):
#     def debug(self, msg):
#     def __init__(self, log=None):
#     def from_file(self, filename):
#     def from_txt(self, txt):
#     def from_xml(self, xml):
#     def build(self, node):
#     def _build_testsuites(self, node):
#     def _build_testsuite(self, node):
#     def _build_testcase(self, node):
#         def sanitize_name(name):
#     def pp(tree):
# class ansi(unicode):
# class Log(object):
#         class IndentedLog(Log):
# class LogBuilder(object):
# 
# Path: igor/client/event.py
# REPORTBASE = "http://{host}:{port}/jobs/{sessionid}/status?format=xml"
# def follow_events(server, port):
# def __FIXME_retrieve_report(remote, port, sessionid):
# 
# Path: igor/client/main.py
# class IgordAPI(object):
#     """An interface to the basic REST-API of igor
#     """
#     _http = None
#     _logger = None
#     host = None
#     port = None
# 
#     def __init__(self, host="127.0.0.1", port=8080):
#         self.host = host
#         self.port = port
#         self._http = HTTPHelper()
#         self._logger = logging.getLogger(self.__module__)
# 
#     @property
#     def logger(self):
#         return self._logger
# 
#     def url(self, route="/", query={}, **route_args):
#         """Returns the URL of the remote Igord server with the given route
#         """
#         _route = route
#         if route_args:
#             _route = re.sub("<([^>:]*)(:[^>]*)?>", "{\\1}", _route)
#             _route = _route.format(**route_args)
#         _query = "?" + urllib.urlencode(query.items()) if query else ""
#         if "<" in _route:
#             self.logger.debug("Route: %s" % route)
#             self.logger.debug("RouteArgs: %s" % route_args)
#             self.logger.debug("Query: %s" % query)
#             self.logger.debug("New Route: %s" % _route)
#             self.logger.debug("New Query: %s" % _query)
#             raise RuntimeError("Some placeholders weren't filled in route.")
#         return "http://{host}:{port}{route}{query}".format(host=self.host,
#                                                            port=self.port,
#                                                            route=_route,
#                                                            query=_query)
# 
#     def route_request(self, route, **route_args):
#         """Request a route and return an XML tree
#         """
#         url = self.url(route, {"format": "xml"}, **route_args)
#         pagedata = self._http.request(url)
#         tree = etree.XML(pagedata) if pagedata else None
#         return tree
# 
#     def jobs(self):
#         return self.route_request(routes.jobs)
# 
#     def testsuites(self):
#         return self.route_request(routes.testsuites)
# 
#     def hosts(self):
#         return self.route_request(routes.hosts)
# 
#     def profiles(self):
#         return self.route_request(routes.profiles)
# 
#     def testplans(self):
#         return self.route_request(routes.testplans)
# 
#     def testsuite(self, name):
#         return TestsuiteAPI(self.host, self.port, name)
# 
#     def job(self, sessionid):
#         return JobAPI(self.host, self.port, sessionid)
# 
#     def profile(self, name):
#         return ProfileAPI(self.host, self.port, name)
# 
#     def testplan(self, name):
#         return TestplanAPI(self.host, self.port, name)
# 
#     def datastore(self):
#         return DatastoreAPI(self.host, self.port)


from igor.client import junitless, event
from igor.client.main import IgordAPI
from lxml import etree
import argparse
import cmd
import logging
import os
import shlex
import subprocess
import urlparse
        _args = self._parse_do_args("watch_testplan", line, pargs)

        testplan = self.__igorapi().testplan(_args.testplanname)

        def job_reportxml_cb(updated_sessiondid):
            return testplan.report_junit()

        return self.watch_events(job_reportxml_cb)

    def watch_events(self, reportxml_cb):
        is_passed = False

        remote = self.ctx.remote
        event_port = self.ctx.event_port

        builder = junitless.LogBuilder()

        def parse_state(reportxml):
            gp = lambda p: reportxml.xpath("//property[@name='%s']/@value" % p)
            states = gp("status")
            is_endstates = gp("is_endstate")
            is_endstate = all(n == "True" for n in is_endstates)
            return states, is_endstate

        try:
            reportxml = reportxml_cb(None)
            junitless.clearscreen()
            builder.from_xml(reportxml)

            builder.log.writeln("Waiting for event ...")

# Path: igor/client/junitless.py
# def clearscreen():
#     def __init__(self, txt, with_markup=True):
#     def plain(self):
#     def bold(self):
#     def italic(self):
#     def underline(self):
#     def inverse(self):
#     def markup(self):
#     def black(self):
#     def red(self):
#     def green(self):
#     def yellow(self):
#     def blue(self):
#     def magenta(self):
#     def cyan(self):
#     def white(self):
#     def write(self, msg):
#     def writeln(self, msg):
#     def indented(self, size=1):
#             def __enter__(self):
#             def __exit__(self, exc_type, exc_value, traceback):
#     def _indented(self, msg):
#     def warn(self, msg=None):
#     def error(self, msg):
#     def ok(self, msg=None):
#     def success(self, msg):
#     def fail(self, msg):
#     def header(self, msg):
#     def subhead(self, msg):
#     def debug(self, msg):
#     def __init__(self, log=None):
#     def from_file(self, filename):
#     def from_txt(self, txt):
#     def from_xml(self, xml):
#     def build(self, node):
#     def _build_testsuites(self, node):
#     def _build_testsuite(self, node):
#     def _build_testcase(self, node):
#         def sanitize_name(name):
#     def pp(tree):
# class ansi(unicode):
# class Log(object):
#         class IndentedLog(Log):
# class LogBuilder(object):
# 
# Path: igor/client/event.py
# REPORTBASE = "http://{host}:{port}/jobs/{sessionid}/status?format=xml"
# def follow_events(server, port):
# def __FIXME_retrieve_report(remote, port, sessionid):
# 
# Path: igor/client/main.py
# class IgordAPI(object):
#     """An interface to the basic REST-API of igor
#     """
#     _http = None
#     _logger = None
#     host = None
#     port = None
# 
#     def __init__(self, host="127.0.0.1", port=8080):
#         self.host = host
#         self.port = port
#         self._http = HTTPHelper()
#         self._logger = logging.getLogger(self.__module__)
# 
#     @property
#     def logger(self):
#         return self._logger
# 
#     def url(self, route="/", query={}, **route_args):
#         """Returns the URL of the remote Igord server with the given route
#         """
#         _route = route
#         if route_args:
#             _route = re.sub("<([^>:]*)(:[^>]*)?>", "{\\1}", _route)
#             _route = _route.format(**route_args)
#         _query = "?" + urllib.urlencode(query.items()) if query else ""
#         if "<" in _route:
#             self.logger.debug("Route: %s" % route)
#             self.logger.debug("RouteArgs: %s" % route_args)
#             self.logger.debug("Query: %s" % query)
#             self.logger.debug("New Route: %s" % _route)
#             self.logger.debug("New Query: %s" % _query)
#             raise RuntimeError("Some placeholders weren't filled in route.")
#         return "http://{host}:{port}{route}{query}".format(host=self.host,
#                                                            port=self.port,
#                                                            route=_route,
#                                                            query=_query)
# 
#     def route_request(self, route, **route_args):
#         """Request a route and return an XML tree
#         """
#         url = self.url(route, {"format": "xml"}, **route_args)
#         pagedata = self._http.request(url)
#         tree = etree.XML(pagedata) if pagedata else None
#         return tree
# 
#     def jobs(self):
#         return self.route_request(routes.jobs)
# 
#     def testsuites(self):
#         return self.route_request(routes.testsuites)
# 
#     def hosts(self):
#         return self.route_request(routes.hosts)
# 
#     def profiles(self):
#         return self.route_request(routes.profiles)
# 
#     def testplans(self):
#         return self.route_request(routes.testplans)
# 
#     def testsuite(self, name):
#         return TestsuiteAPI(self.host, self.port, name)
# 
#     def job(self, sessionid):
#         return JobAPI(self.host, self.port, sessionid)
# 
#     def profile(self, name):
#         return ProfileAPI(self.host, self.port, name)
# 
#     def testplan(self, name):
#         return TestplanAPI(self.host, self.port, name)
# 
#     def datastore(self):
#         return DatastoreAPI(self.host, self.port)


# Path: igor/client/__main__.py
from igor.client import junitless, event
from igor.client.main import IgordAPI
from lxml import etree
import argparse
import cmd
import logging
import os
import shlex
import subprocess
import urlparse

        _args = self._parse_do_args("watch_testplan", line, pargs)

        testplan = self.__igorapi().testplan(_args.testplanname)

        def job_reportxml_cb(updated_sessiondid):
            return testplan.report_junit()

        return self.watch_events(job_reportxml_cb)

    def watch_events(self, reportxml_cb):
        is_passed = False

        remote = self.ctx.remote
        event_port = self.ctx.event_port

        builder = junitless.LogBuilder()

        def parse_state(reportxml):
            gp = lambda p: reportxml.xpath("//property[@name='%s']/@value" % p)
            states = gp("status")
            is_endstates = gp("is_endstate")
            is_endstate = all(n == "True" for n in is_endstates)
            return states, is_endstate

        try:
            reportxml = reportxml_cb(None)
            junitless.clearscreen()
            builder.from_xml(reportxml)

            builder.log.writeln("Waiting for event ...")

            for ev in event.follow_events(remote, event_port):