# Path: src/myaas/settings.py
# DEBUG = config('MYAAS_DEBUG', default=False, cast=bool)
# 
# Path: src/myaas/utils/database.py
# def get_myaas_containers():
#     return filter(_is_database_container, list_containers())
# 
# def get_enabled_backend():
#     return importlib.import_module(settings.BACKEND)
# 
# Path: src/myaas/utils/container.py
# def find_container(name):
# def list_containers(all=True):
# def translate_host_basedir(path):
# def get_random_cpuset(cores_to_assign):
# def get_mapped_cpuset():


import signal
import logging
import click
from time import sleep
from datetime import datetime
from .settings import DEBUG
from .utils.database import get_myaas_containers, get_enabled_backend
from .utils.container import client
logger = logging.getLogger("myaas-reaper")


def get_container_name(container):
    return container['Names'][0].lstrip('/')


class SignalHandler:
    def __init__(self):
        self.__killed = False
        signal.signal(signal.SIGTERM, self.stop)
        signal.signal(signal.SIGINT, self.stop)

    @property
    def exit(self):
        return self.__killed

    def stop(self, signum, frame):
        self.__killed = True


class ContainerFilter(object):
    def __init__(self, expired=False, dead=False, unhealthy=False):
        self._expired = expired
        self._dead = dead
        self._unhealthy = unhealthy

    def filter(self, containers):
        if self._expired:
            logger.info('* Filtering expired')

# Path: src/myaas/settings.py
# DEBUG = config('MYAAS_DEBUG', default=False, cast=bool)
# 
# Path: src/myaas/utils/database.py
# def get_myaas_containers():
#     return filter(_is_database_container, list_containers())
# 
# def get_enabled_backend():
#     return importlib.import_module(settings.BACKEND)
# 
# Path: src/myaas/utils/container.py
# def find_container(name):
# def list_containers(all=True):
# def translate_host_basedir(path):
# def get_random_cpuset(cores_to_assign):
# def get_mapped_cpuset():


# Path: src/myaas/reaper.py
import signal
import logging
import click
from time import sleep
from datetime import datetime
from .settings import DEBUG
from .utils.database import get_myaas_containers, get_enabled_backend
from .utils.container import client

logger = logging.getLogger("myaas-reaper")


def get_container_name(container):
    return container['Names'][0].lstrip('/')


class SignalHandler:
    def __init__(self):
        self.__killed = False
        signal.signal(signal.SIGTERM, self.stop)
        signal.signal(signal.SIGINT, self.stop)

    @property
    def exit(self):
        return self.__killed

    def stop(self, signum, frame):
        self.__killed = True


class ContainerFilter(object):
    def __init__(self, expired=False, dead=False, unhealthy=False):
        self._expired = expired
        self._dead = dead
        self._unhealthy = unhealthy

    def filter(self, containers):
        if self._expired:
            logger.info('* Filtering expired')

        if self._dead: