# 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/utils/database.py
# def get_enabled_backend():
#     return importlib.import_module(settings.BACKEND)
# 
# Path: src/myaas/utils/filesystem.py
# def is_empty(path):
#     return not getsize(path) > 100
# 
# Path: src/myaas/utils/retry.py
# class RetryPolicy(object):
#     def __init__(self, maxtries, delay=None, exceptions=(Exception,)):
#         if delay is None:
#             # 100ms +/- 50ms of randomized jitter
#             self.delay = lambda i: 0.1 + ((random.random() - 0.5) / 10)
#         else:
#             self.delay = lambda i: delay
# 
#         self.maxtries = maxtries
#         self.exceptions = exceptions
# 
#     def __call__(self, function):
#         for i in range(0, self.maxtries):
#             try:
#                 return function()
#             except self.exceptions as error:
#                 last_exception = error
#                 time.sleep(self.delay(i))
#         raise last_exception
# 
# Path: src/myaas/backends/exceptions.py
# class NonExistentTemplate(NonExistentDatabase):
#     pass
# 
# class ImportDataError(Exception):
#     pass


import os
import sys
import traceback
import functools
        import sys
from docker.errors import NotFound as ImageNotFound
from sentry_sdk import init, capture_message, configure_scope
from . import settings
from .utils.container import client
from .utils.database import get_enabled_backend
from .utils.filesystem import is_empty
from .utils.retry import RetryPolicy
from .backends.exceptions import NonExistentTemplate, ImportDataError
        return db
    except Exception as e:
        print(indent(
            f"* Max time waiting for database exceeded"
            ", retrying..."
        ))
        db.stop()
        db.restore_backup()
        print_exception()
        raise e


def main():
    dumps = list_dump_files()
    for dump in dumps:
        db_name,_ = os.path.splitext(dump)
        sql_file = os.path.join(settings.DUMP_DIR, dump)

        if is_empty(sql_file):
            print(f"- Skipping: {sql_file} is empty")
            continue

        start_db_func = functools.partial(start_template_database, db_name)
        db = RetryPolicy(5, delay=2)(start_db_func)
        if not db:
            continue  # skip to next database to import

        print(indent("* Importing data..."))
        try:
            db.import_data(sql_file)

# 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/utils/database.py
# def get_enabled_backend():
#     return importlib.import_module(settings.BACKEND)
# 
# Path: src/myaas/utils/filesystem.py
# def is_empty(path):
#     return not getsize(path) > 100
# 
# Path: src/myaas/utils/retry.py
# class RetryPolicy(object):
#     def __init__(self, maxtries, delay=None, exceptions=(Exception,)):
#         if delay is None:
#             # 100ms +/- 50ms of randomized jitter
#             self.delay = lambda i: 0.1 + ((random.random() - 0.5) / 10)
#         else:
#             self.delay = lambda i: delay
# 
#         self.maxtries = maxtries
#         self.exceptions = exceptions
# 
#     def __call__(self, function):
#         for i in range(0, self.maxtries):
#             try:
#                 return function()
#             except self.exceptions as error:
#                 last_exception = error
#                 time.sleep(self.delay(i))
#         raise last_exception
# 
# Path: src/myaas/backends/exceptions.py
# class NonExistentTemplate(NonExistentDatabase):
#     pass
# 
# class ImportDataError(Exception):
#     pass


# Path: src/myaas/update.py
import os
import sys
import traceback
import functools
        import sys
from docker.errors import NotFound as ImageNotFound
from sentry_sdk import init, capture_message, configure_scope
from . import settings
from .utils.container import client
from .utils.database import get_enabled_backend
from .utils.filesystem import is_empty
from .utils.retry import RetryPolicy
from .backends.exceptions import NonExistentTemplate, ImportDataError

        return db
    except Exception as e:
        print(indent(
            f"* Max time waiting for database exceeded"
            ", retrying..."
        ))
        db.stop()
        db.restore_backup()
        print_exception()
        raise e


def main():
    dumps = list_dump_files()
    for dump in dumps:
        db_name,_ = os.path.splitext(dump)
        sql_file = os.path.join(settings.DUMP_DIR, dump)

        if is_empty(sql_file):
            print(f"- Skipping: {sql_file} is empty")
            continue

        start_db_func = functools.partial(start_template_database, db_name)
        db = RetryPolicy(5, delay=2)(start_db_func)
        if not db:
            continue  # skip to next database to import

        print(indent("* Importing data..."))
        try:
            db.import_data(sql_file)

        except (ImportDataError, Exception) as e: