# Path: clustertools/util.py
# @contextmanager
# def catch_logging():
#     # Memo
#     logger = logging.getLogger("clustertools")
#     handlers = logger.handlers
#     level = logger.level
#     # New stuff
#     logger.handlers = []
#     ch = logging.StreamHandler(sys.stdout)
#     ch.setLevel(logging.DEBUG)
#     formatter = logging.Formatter("%(asctime)s - %(name)s - "
#                                   "%(levelname)s - %(message)s")
#     ch.setFormatter(formatter)
#     logger.addHandler(ch)
#     logger.setLevel(logging.DEBUG)
# 
#     try:
#         yield
#     finally:
#         logger.handlers = handlers
#         logger.level = level
# 
# Path: clustertools/state.py
# class PendingState(State):
#     def get_name(self):
#         return __PENDING__
# 
#     def to_running(self):
#         return RunningState.from_(self)
# 
#     def is_not_up(self):
#         return LaunchableState.from_(self)
# 
# class AbortedState(State):
#     @classmethod
#     def from_(cls, state, exception):
#         return cls(state.comp_name, progress=state.progress,
#                    exception=exception)
# 
#     def __init__(self, comp_name, exception, progress=0.):
#         super().__init__(comp_name, progress)
#         self.exception = exception
# 
#     def get_name(self):
#         return __ABORTED__
# 
#     def __repr__(self):
#         return "{cls}(comp_name={comp_name}, progress={progress}, " \
#                "exception={exception})".format(cls=self.__class__.__name__,
#                                                comp_name=repr(self.comp_name),
#                                                progress=repr(self.progress),
#                                                exception=repr(self.exception))


import shutil
import sys
import os
import subprocess
import logging
import copy
import dill
            import socket
from time import time as epoch
from datetime import datetime
from abc import ABCMeta, abstractmethod
from shlex import quote as escape
from clustertools.util import catch_logging
from .state import PendingState, AbortedState
        self._customizers.append(customizer)

    def _customize(self, lazy_computation, env_params):
        env_params = copy.copy(env_params)
        for customizer in self._customizers:
            custom_param = customizer(lazy_computation)
            env_params.update(custom_param)
        return env_params


class DebugEnvironment(Environment):
    """
    `DebugEnvironment`
    ==================
    An `Environment` that do not run code. It only prints the messages.
    """

    @classmethod
    def is_usable(cls):
        return True

    def __init__(self, print_all_parameters=False, fail_fast=True):
        super().__init__(fail_fast)
        self.print_all_parameters = print_all_parameters

    def log(self, msg, *args, **kwargs):
        logger = logging.getLogger("clustertools")
        logger.debug(msg, *args, **kwargs)

    def run(self, experiment, start=0, capacity=None):

# Path: clustertools/util.py
# @contextmanager
# def catch_logging():
#     # Memo
#     logger = logging.getLogger("clustertools")
#     handlers = logger.handlers
#     level = logger.level
#     # New stuff
#     logger.handlers = []
#     ch = logging.StreamHandler(sys.stdout)
#     ch.setLevel(logging.DEBUG)
#     formatter = logging.Formatter("%(asctime)s - %(name)s - "
#                                   "%(levelname)s - %(message)s")
#     ch.setFormatter(formatter)
#     logger.addHandler(ch)
#     logger.setLevel(logging.DEBUG)
# 
#     try:
#         yield
#     finally:
#         logger.handlers = handlers
#         logger.level = level
# 
# Path: clustertools/state.py
# class PendingState(State):
#     def get_name(self):
#         return __PENDING__
# 
#     def to_running(self):
#         return RunningState.from_(self)
# 
#     def is_not_up(self):
#         return LaunchableState.from_(self)
# 
# class AbortedState(State):
#     @classmethod
#     def from_(cls, state, exception):
#         return cls(state.comp_name, progress=state.progress,
#                    exception=exception)
# 
#     def __init__(self, comp_name, exception, progress=0.):
#         super().__init__(comp_name, progress)
#         self.exception = exception
# 
#     def get_name(self):
#         return __ABORTED__
# 
#     def __repr__(self):
#         return "{cls}(comp_name={comp_name}, progress={progress}, " \
#                "exception={exception})".format(cls=self.__class__.__name__,
#                                                comp_name=repr(self.comp_name),
#                                                progress=repr(self.progress),
#                                                exception=repr(self.exception))


# Path: clustertools/environment.py
import shutil
import sys
import os
import subprocess
import logging
import copy
import dill
            import socket
from time import time as epoch
from datetime import datetime
from abc import ABCMeta, abstractmethod
from shlex import quote as escape
from clustertools.util import catch_logging
from .state import PendingState, AbortedState

        self._customizers.append(customizer)

    def _customize(self, lazy_computation, env_params):
        env_params = copy.copy(env_params)
        for customizer in self._customizers:
            custom_param = customizer(lazy_computation)
            env_params.update(custom_param)
        return env_params


class DebugEnvironment(Environment):
    """
    `DebugEnvironment`
    ==================
    An `Environment` that do not run code. It only prints the messages.
    """

    @classmethod
    def is_usable(cls):
        return True

    def __init__(self, print_all_parameters=False, fail_fast=True):
        super().__init__(fail_fast)
        self.print_all_parameters = print_all_parameters

    def log(self, msg, *args, **kwargs):
        logger = logging.getLogger("clustertools")
        logger.debug(msg, *args, **kwargs)

    def run(self, experiment, start=0, capacity=None):

        with catch_logging():