# Path: gocdapi/custom_exceptions.py
# class GoCdApiException(Exception):
#     """
#     Base class for all errors
#     """
#     pass
# 
# Path: gocdapi/go.py
# class Go(object):
#     """
#     Class that represents Go Server environment.
#     """
#     def __init__(self, baseurl, username=None, password=None):
#         """Inits Go objects.
# 
#         Args:
#             baseurl (str): The base url of Go Server
#             username (str): The username to login in the Go Server
#             password (str): The username's password
#         """
#         self.baseurl = baseurl
#         self.username = username
#         self.password = password
# 
#     @property
#     def agents(self):
#         """Return agents of the Go Server
#         """
#         return Agents(self)
# 
#     @property
#     def pipeline_groups(self):
#         """Return Pipeline Groups of the Go Server
#         """
#         return PipelineGroups(self)
# 
#     @property
#     def pipelines(self):
#         """Return Pipeline Groups of the Go Server
#         """
#         return dict(self._iter_through_pipelines())
# 
#     @property
#     def admin(self):
#         """Return an Admin object
#         """
#         return Admin(self)
# 
#     def pipeline_exist(self, name):
#         """ Check if pipeline exists.
# 
#         Args:
#             name (str): name of the pipeline to find
# 
#         Returns:
#             bool: True if pipeline with the given name exists
#         """
#         return name in self.pipelines
# 
#     def get_pipeline(self, name):
#         """ Return pipeline if exists.
# 
#         Args:
#             name (str): name of the pipeline to get
# 
#         Returns:
#             pipeline: Pipeline with the given name or None if it doesn't exist.
#         """
#         return self.pipelines.get(name, None)
# 
#     def _iter_through_pipelines(self):
#         """ Return a iterable containing every pair pipeline_name, pipeline
# 
#         Generator: Yields a pair pipeline_name, pipeline
#         """
#         for pipeline_group in self.pipeline_groups.values():
#             for pipeline_name, pipeline in pipeline_group.iteritems():
#                 yield pipeline_name, pipeline


import Queue
import datetime
import logging
import os
import subprocess
import sys
import threading
import time
import urllib
import zipfile
from gocdapi.custom_exceptions import GoCdApiException
from gocdapi.go import Go
                        log.warning("INFO %s " % line)
                        break
                else:
                    log.warn('Stream %s has terminated', streamName)

        self.block_until_is_ready(timeout)


class GoAgentLauncher(GoLauncher):
    """
    """

    def __init__(self, working_directory, version=None):
        """
        """
        GoLauncher.__init__(self, "agent", working_directory, version)
        self.http_port = 8153
        self.q = Queue.Queue()

    def block_until_is_ready(self, timeout):
        start_time = datetime.datetime.now()
        timeout_time = start_time + datetime.timedelta(seconds=timeout)

        go_server = Go('http://localhost:%s' % str(self.http_port))

        while True:
            try:
                if go_server.agents:
                    log.warning("INFO: Go Server have already an agent.")
                    return

# Path: gocdapi/custom_exceptions.py
# class GoCdApiException(Exception):
#     """
#     Base class for all errors
#     """
#     pass
# 
# Path: gocdapi/go.py
# class Go(object):
#     """
#     Class that represents Go Server environment.
#     """
#     def __init__(self, baseurl, username=None, password=None):
#         """Inits Go objects.
# 
#         Args:
#             baseurl (str): The base url of Go Server
#             username (str): The username to login in the Go Server
#             password (str): The username's password
#         """
#         self.baseurl = baseurl
#         self.username = username
#         self.password = password
# 
#     @property
#     def agents(self):
#         """Return agents of the Go Server
#         """
#         return Agents(self)
# 
#     @property
#     def pipeline_groups(self):
#         """Return Pipeline Groups of the Go Server
#         """
#         return PipelineGroups(self)
# 
#     @property
#     def pipelines(self):
#         """Return Pipeline Groups of the Go Server
#         """
#         return dict(self._iter_through_pipelines())
# 
#     @property
#     def admin(self):
#         """Return an Admin object
#         """
#         return Admin(self)
# 
#     def pipeline_exist(self, name):
#         """ Check if pipeline exists.
# 
#         Args:
#             name (str): name of the pipeline to find
# 
#         Returns:
#             bool: True if pipeline with the given name exists
#         """
#         return name in self.pipelines
# 
#     def get_pipeline(self, name):
#         """ Return pipeline if exists.
# 
#         Args:
#             name (str): name of the pipeline to get
# 
#         Returns:
#             pipeline: Pipeline with the given name or None if it doesn't exist.
#         """
#         return self.pipelines.get(name, None)
# 
#     def _iter_through_pipelines(self):
#         """ Return a iterable containing every pair pipeline_name, pipeline
# 
#         Generator: Yields a pair pipeline_name, pipeline
#         """
#         for pipeline_group in self.pipeline_groups.values():
#             for pipeline_name, pipeline in pipeline_group.iteritems():
#                 yield pipeline_name, pipeline


# Path: gocdapi_utils/go_launcher.py
import Queue
import datetime
import logging
import os
import subprocess
import sys
import threading
import time
import urllib
import zipfile
from gocdapi.custom_exceptions import GoCdApiException
from gocdapi.go import Go

                        log.warning("INFO %s " % line)
                        break
                else:
                    log.warn('Stream %s has terminated', streamName)

        self.block_until_is_ready(timeout)


class GoAgentLauncher(GoLauncher):
    """
    """

    def __init__(self, working_directory, version=None):
        """
        """
        GoLauncher.__init__(self, "agent", working_directory, version)
        self.http_port = 8153
        self.q = Queue.Queue()

    def block_until_is_ready(self, timeout):
        start_time = datetime.datetime.now()
        timeout_time = start_time + datetime.timedelta(seconds=timeout)

        go_server = Go('http://localhost:%s' % str(self.http_port))

        while True:
            try:
                if go_server.agents:
                    log.warning("INFO: Go Server have already an agent.")
                    return

            except GoCdApiException: