# Path: sen/util.py
# def humanize_bytes(bytesize, precision=2):
#     """
#     Humanize byte size figures
# 
#     https://gist.github.com/moird/3684595
#     """
#     abbrevs = (
#         (1 << 50, 'PB'),
#         (1 << 40, 'TB'),
#         (1 << 30, 'GB'),
#         (1 << 20, 'MB'),
#         (1 << 10, 'kB'),
#         (1, 'bytes')
#     )
#     if bytesize == 1:
#         return '1 byte'
#     for factor, suffix in abbrevs:
#         if bytesize >= factor:
#             break
#     if factor == 1:
#         precision = 0
#     return '%.*f %s' % (precision, bytesize / float(factor), suffix)
# 
# Path: sen/docker_backend.py
# class RootImage(DockerImage):
#     """
#     this is essentially "scratch" but you cannot inspect it anymore
#     """
#     def __init__(self, docker_backend):
#         self.image_name = "scratch"
#         super().__init__(None, docker_backend, object_id="")
# 
#     @property
#     def parent_id(self):
#         return None
# 
#     @property
#     def parent_image(self):
#         return None
# 
#     def get_next_sibling(self):
#         return None
# 
#     def get_prev_sibling(self):
#         return None
# 
#     @property
#     def names(self):
#         return [ImageNameStruct.parse(self.image_name)]
# 
#     def __str__(self):
#         return self.image_name
# 
# Path: sen/tui/widgets/list/util.py
# def get_time_attr_map(t):
#     """
#                                                        now -> |
#                             hour ago -> |
#         day ago -> |
#     |--------------|--------------------|---------------------|
#     """
#     now = datetime.datetime.now()
#     if t + datetime.timedelta(hours=3) > now:
#         return get_map("main_list_white")
#     if t + datetime.timedelta(days=3) > now:
#         return get_map("main_list_lg")
#     else:
#         return get_map("main_list_dg")
# 
# Path: sen/tui/widgets/util.py
# class SelectableText(ColorTextMixin, AdHocAttrMap):
#     def __init__(self, text, maps=None):
#         maps = maps or get_map()
#         super().__init__(urwid.Text(text, align="left", wrap="clip"), maps)
# 
# def get_map(defult="main_list_dg"):
#     return {"normal": defult, "focus": MAIN_LIST_FOCUS}


import logging
from sen.util import humanize_bytes
from sen.docker_backend import RootImage
from sen.tui.widgets.list.util import get_time_attr_map
from sen.tui.widgets.util import SelectableText, get_map
Image specific chunks.
"""





logger = logging.getLogger(__name__)


class LayerWidget(SelectableText):
    def __init__(self, ui, docker_image, index=None):
        self.ui = ui
        self.docker_image = docker_image
        label = []
        logger.debug("creating layer widget for %s", docker_image)
        if index is not None:
            separator = "└─"
            if index == 0:
                label = [separator]
            else:
                label = [2 * index * " " + separator]
        super().__init__(label + get_basic_image_markup(docker_image, with_size=True))


def get_detailed_image_row(docker_image):
    row = []
    image_id = SelectableText(docker_image.short_id, maps=get_map())
    row.append(image_id)


# Path: sen/util.py
# def humanize_bytes(bytesize, precision=2):
#     """
#     Humanize byte size figures
# 
#     https://gist.github.com/moird/3684595
#     """
#     abbrevs = (
#         (1 << 50, 'PB'),
#         (1 << 40, 'TB'),
#         (1 << 30, 'GB'),
#         (1 << 20, 'MB'),
#         (1 << 10, 'kB'),
#         (1, 'bytes')
#     )
#     if bytesize == 1:
#         return '1 byte'
#     for factor, suffix in abbrevs:
#         if bytesize >= factor:
#             break
#     if factor == 1:
#         precision = 0
#     return '%.*f %s' % (precision, bytesize / float(factor), suffix)
# 
# Path: sen/docker_backend.py
# class RootImage(DockerImage):
#     """
#     this is essentially "scratch" but you cannot inspect it anymore
#     """
#     def __init__(self, docker_backend):
#         self.image_name = "scratch"
#         super().__init__(None, docker_backend, object_id="")
# 
#     @property
#     def parent_id(self):
#         return None
# 
#     @property
#     def parent_image(self):
#         return None
# 
#     def get_next_sibling(self):
#         return None
# 
#     def get_prev_sibling(self):
#         return None
# 
#     @property
#     def names(self):
#         return [ImageNameStruct.parse(self.image_name)]
# 
#     def __str__(self):
#         return self.image_name
# 
# Path: sen/tui/widgets/list/util.py
# def get_time_attr_map(t):
#     """
#                                                        now -> |
#                             hour ago -> |
#         day ago -> |
#     |--------------|--------------------|---------------------|
#     """
#     now = datetime.datetime.now()
#     if t + datetime.timedelta(hours=3) > now:
#         return get_map("main_list_white")
#     if t + datetime.timedelta(days=3) > now:
#         return get_map("main_list_lg")
#     else:
#         return get_map("main_list_dg")
# 
# Path: sen/tui/widgets/util.py
# class SelectableText(ColorTextMixin, AdHocAttrMap):
#     def __init__(self, text, maps=None):
#         maps = maps or get_map()
#         super().__init__(urwid.Text(text, align="left", wrap="clip"), maps)
# 
# def get_map(defult="main_list_dg"):
#     return {"normal": defult, "focus": MAIN_LIST_FOCUS}


# Path: sen/tui/chunks/image.py
import logging
from sen.util import humanize_bytes
from sen.docker_backend import RootImage
from sen.tui.widgets.list.util import get_time_attr_map
from sen.tui.widgets.util import SelectableText, get_map

Image specific chunks.
"""





logger = logging.getLogger(__name__)


class LayerWidget(SelectableText):
    def __init__(self, ui, docker_image, index=None):
        self.ui = ui
        self.docker_image = docker_image
        label = []
        logger.debug("creating layer widget for %s", docker_image)
        if index is not None:
            separator = "└─"
            if index == 0:
                label = [separator]
            else:
                label = [2 * index * " " + separator]
        super().__init__(label + get_basic_image_markup(docker_image, with_size=True))


def get_detailed_image_row(docker_image):
    row = []
    image_id = SelectableText(docker_image.short_id, maps=get_map())
    row.append(image_id)


    command = SelectableText(docker_image.command, maps=get_map(defult="main_list_ddg"))