Ejemplo n.º 1
0
def part1(inp: list[str]) -> None:
    tiles = parse_tiles(inp)
    img = Image()
    img.fit(tiles)

    edge_ids = map(lambda tile: tile.id, img.get_edge_tiles())
    print(reduce(operator.mul, edge_ids))
Ejemplo n.º 2
0
 def image(self):
     self.file.open()
     self.file.seek(0)
     try:
         return Image.open(self.file)
     except IOError:
         self.file.seek(0)
         cf = ContentFile(self.file.read())
         return Image.open(cf)
Ejemplo n.º 3
0
def part2(inp: list[str]) -> None:
    tiles = parse_tiles(inp)
    img = Image()
    img.fit(tiles)

    combined = img.get_combined()
    for i, variation in enumerate(get_variations(combined)):
        monster_count = count_monsters(variation)
        if monster_count > 1:
            total_count = sum(sum(row) for row in variation)
            print(total_count - monster_count * 15)
            return
Ejemplo n.º 4
0
class WinInfo(Stage):
    def __init__(self, id):
        if id == "a": self._background = Image("gfx/won_player_b.png")
        else: self._background = Image("gfx/won_player_a.png")

    #

    def on_draw(self, dt):
        self._background.draw(0, 0)

    def on_key_event(self, key, state):
        global current

        if key == K_RETURN and state == 0:
            current = MainMenu()
Ejemplo n.º 5
0
 def process(self, img, config, info):
     if self.key not in config:
         return img
     # convert bgcolor string to rgb value
     config = config[self.key]
     background_color = ImageColor.getrgb(
         config.get('background_color', self.background_color))
     # handle palleted images
     img = img.convert('RGB')
     # copy orignial image and flip the orientation
     reflection = img.copy().transpose(Image.FLIP_TOP_BOTTOM)
     # create a new image filled with the bgcolor the same size
     background = Image.new("RGB", img.size, background_color)
     # calculate our alpha mask
     start = int(
         255 -
         (255 *
          config.get('opacity', self.opacity)))  # The start of our gradient
     steps = int(
         255 *
         config.get('size', self.size))  # The number of intermedite values
     increment = (255 - start) / float(steps)
     mask = Image.new('L', (1, 255))
     for y in range(255):
         if y < steps:
             val = int(y * increment + start)
         else:
             val = 255
         mask.putpixel((0, y), val)
     alpha_mask = mask.resize(img.size)
     # merge the reflection onto our background color using the alpha mask
     reflection = Image.composite(background, reflection, alpha_mask)
     # crop the reflection
     reflection_height = int(img.size[1] * config.get('size', self.size))
     reflection = reflection.crop((0, 0, img.size[0], reflection_height))
     # create new image sized to hold both the original image and the reflection
     composite = Image.new("RGB",
                           (img.size[0], img.size[1] + reflection_height),
                           background_color)
     # paste the orignal image and the reflection into the composite image
     composite.paste(img, (0, 0))
     composite.paste(reflection, (0, img.size[1]))
     # Save the file as a JPEG
     info['format'] = 'JPEG'
     # return the image complete with reflection effect
     return composite
Ejemplo n.º 6
0
class TlCoffee(Tile):
    _sprite = Image("gfx/coffee.png")

    #

    def on_overlapped(self, tile):
        if isinstance(tile, TlPlayer):
            tile.bomb_cooldown *= 0.90

        return True
Ejemplo n.º 7
0
class TlRuPass(Tile):
    _sprite = Image("gfx/ru_pass.png")

    #

    def on_overlapped(self, tile):
        if isinstance(tile, TlPlayer):
            tile.bomb_strength += 1

        return True
Ejemplo n.º 8
0
 def process(self, img, config, info):
     if self.key not in config:
         return img
     bw = img.convert('1')
     bw = bw.filter(ImageFilter.MedianFilter)
     # White background.
     bg = Image.new('1', img.size, 255)
     diff = ImageChops.difference(bw, bg)
     bbox = diff.getbbox()
     if bbox:
         img = img.crop(bbox)
     return img
Ejemplo n.º 9
0
class TlCrate(BreakableTile):
    _sprite = Image("gfx/crate.png")

    #

    def on_overlapped(self, tile):
        super().on_overlapped(tile)

        if isinstance(tile, (TlPlayer, TlCrate)):
            return self.move(self.x - tile.x, self.y - tile.y)

        return False
Ejemplo n.º 10
0
 def process(self, img, config, info):
     if self.key not in config:
         return img
     bw = img.convert('1')
     bw = bw.filter(ImageFilter.MedianFilter)
     # White background.
     bg = Image.new('1', img.size, 255)
     diff = ImageChops.difference(bw, bg)
     bbox = diff.getbbox()
     if bbox:
         img = img.crop(bbox)
     return img
Ejemplo n.º 11
0
    def __init__(self, master, image, **kwargs):
        super().__init__(master, **kwargs)

        self.master = master
        self.rowconfigure(0, weight=1)
        self.rowconfigure(1, weight=1)
        self.columnconfigure(0, weight=1)

        self.options = {
            "Magnitude": Fourier.magnitude,
            "Phase": Fourier.phase,
            "Real": Fourier.real,
            "Imaginary": Fourier.imaginary
        }

        self.cbox = Combobox(
            self, values=["Magnitude", "Phase", "Real", "Imaginary"])
        self.cbox.set(self.cbox["values"][0])
        self.cbox.grid(row=0, column=0, sticky="ns", padx=4, pady=4)
        self.cbox.on_change(self.update_image)

        imgs_container = tk.Frame(self, bg="white")
        imgs_container.rowconfigure(0, weight=1)
        imgs_container.columnconfigure(0, weight=1)
        imgs_container.columnconfigure(1, weight=1)

        # buggy!!!!
        self.image = Image(imgs_container)
        self.image.open_image(image)
        self.image.show()

        self.gray_fourier = Fourier.fast2d(self.image.get_gray())

        self.image2 = Image(imgs_container)
        self.image2.size = self.image.size
        self.update_image(self.cbox.get())

        self.image.grid(row=0, column=0, sticky="nsew", padx=4, pady=4)
        self.image2.grid(row=0, column=1, sticky="nsew", padx=4, pady=4)
        imgs_container.grid(row=1, column=0, sticky="nsew", padx=4, pady=4)
Ejemplo n.º 12
0
class TlBush(BreakableTile):
    _sprite = Image("gfx/bush.png")

    #

    def on_overlapped(self, tile):
        super().on_overlapped(tile)

        if isinstance(tile, TlPlayer):
            tile.entering_bush.arm()
            return True

        return False
Ejemplo n.º 13
0
class MainMenu(Stage):
    _BACKGROUND = Image("gfx/main_menu.png")

    #

    def on_draw(self, dt):
        self._BACKGROUND.draw(0, 0)

    def on_key_event(self, key, state):
        global current

        if key == K_RETURN and state == 0:
            current = GrassArena()
Ejemplo n.º 14
0
 def process(self, img, config, info):
     if self.key not in config:
         return img
     # convert bgcolor string to rgb value
     config = config[self.key]
     background_color = ImageColor.getrgb(config.get('background_color', self.background_color))
     # handle palleted images
     img = img.convert('RGB')
     # copy orignial image and flip the orientation
     reflection = img.copy().transpose(Image.FLIP_TOP_BOTTOM)
     # create a new image filled with the bgcolor the same size
     background = Image.new("RGB", img.size, background_color)
     # calculate our alpha mask
     start = int(255 - (255 * config.get('opacity', self.opacity)))  # The start of our gradient
     steps = int(255 * config.get('size', self.size))  # The number of intermedite values
     increment = (255 - start) / float(steps)
     mask = Image.new('L', (1, 255))
     for y in range(255):
         if y < steps:
             val = int(y * increment + start)
         else:
             val = 255
         mask.putpixel((0, y), val)
     alpha_mask = mask.resize(img.size)
     # merge the reflection onto our background color using the alpha mask
     reflection = Image.composite(background, reflection, alpha_mask)
     # crop the reflection
     reflection_height = int(img.size[1] * config.get('size', self.size))
     reflection = reflection.crop((0, 0, img.size[0], reflection_height))
     # create new image sized to hold both the original image and the reflection
     composite = Image.new("RGB", (img.size[0], img.size[1]+reflection_height), background_color)
     # paste the orignal image and the reflection into the composite image
     composite.paste(img, (0, 0))
     composite.paste(reflection, (0, img.size[1]))
     # Save the file as a JPEG
     info['format'] = 'JPEG'
     # return the image complete with reflection effect
     return composite
Ejemplo n.º 15
0
class Tile:
    _sprite = Image("gfx/missing.png")
    x = y = z = 0

    #

    def __init__(self, x, y, z):
        self.x = x
        self.y = y
        self.z = z

    #

    def on_update(self, dt):
        pass

    def on_key_event(self, key, state):
        pass

    def on_overlapped(self, tile):
        return False

    def on_draw(self, dt):
        self._sprite.draw(self.x * lib.TILE_SIZE, self.y * lib.TILE_SIZE, dt)

    #

    def move(self, dx, dy):
        if dx == 0 and dy == 0:
            return False

        dx += self.x
        dy += self.y

        dest = stages.current.map.get(dx, dy, self.z)

        if dest is None or dest.on_overlapped(self):
            stages.current.map.remove(self)
            self.x = dx
            self.y = dy
            stages.current.map.place(self)

            return True

        return False
Ejemplo n.º 16
0
    def __init__(self, x, y, z, **params):
        super().__init__(x, y, z)

        self._strength = params.get("strength", 2)
        self._in_bush = params.get("in_bush", False)

        if self._in_bush:
            self._sprite = Image("gfx/bomb_bush.png")

        else:
            self._sprite = \
               Animation("gfx/bomb_%d.png", list(range(7))           +
                                            list(reversed(range(7))) +
                                            list(range(7))           +
                                            list(reversed(range(7))) +
                                            list(range(7))           )

        self._sprite.on_end = self.explode
Ejemplo n.º 17
0
    def test_containerIsOutOfSync_hosts(self):
        container_def = ContainerDefinition.parseFile(os.path.join(self.EXAMPLE_DIR, "00-hosts.yaml"))

        ## blalor/docker-hosts:latest
        img_info = Image.fromJson({
            "Size": 0,
            "Os": "linux",
            "Architecture": "amd64",
            "Id": "98e7ca605530c6ee637e175f08e692149a4d019b384e421e661bd35601b25975",
            "Parent": "15e3a43eb69d67df5a6ae1f3b3e87407f3b82157bf54fe8a5dc997cf2ce6528a",
            "Created": "2014-07-30T01:02:04.516066768Z",
            "Container": "5d7384258a7ac29d8eabe30b6b1d83dfe4a8925440f33982b439731906a087f2",
            "Docker_version": "1.1.1",
            "Author": "Brian Lalor <*****@*****.**>",
            "Config": {
                "OnBuild": [],
                "NetworkDisabled": False,
                "Entrypoint": [
                    "/usr/local/bin/docker-hosts"
                ],
                "WorkingDir": "",
                "Volumes": None,
                "Image": "15e3a43eb69d67df5a6ae1f3b3e87407f3b82157bf54fe8a5dc997cf2ce6528a",
                "Cmd": None,
                "AttachStdin": False,
                "Cpuset": "",
                "CpuShares": 0,
                "MemorySwap": 0,
                "Memory": 0,
                "User": "",
                "Domainname": "",
                "Hostname": "5ca9d941ba62",
                "AttachStdout": False,
                "AttachStderr": False,
                "PortSpecs": None,
                "ExposedPorts": None,
                "Tty": False,
                "OpenStdin": False,
                "StdinOnce": False,
                "Env": [
                    "HOME=/",
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
                ]
            }
        })

        container_info = Container.fromJson("hosts", {
            "HostConfig": {
                "NetworkMode": "",
                "VolumesFrom": None,
                "DnsSearch": None,
                "Binds": [
                    "/var/run/docker.sock:/var/run/docker.sock:rw",
                    "/var/lib/docker/hosts:/srv/hosts:rw"
                ],
                "ContainerIDFile": "",
                "LxcConf": None,
                "Privileged": False,
                "PortBindings": None,
                "Links": None,
                "PublishAllPorts": False,
                "Dns": None
            },
            "VolumesRW": {
                "/var/run/docker.sock": True,
                "/srv/hosts": True
            },
            "Volumes": {
                "/var/run/docker.sock": "/var/run/docker.sock",
                "/srv/hosts": "/var/lib/docker/hosts"
            },
            "NetworkSettings": {
                "Ports": {},
                "PortMapping": None,
                "Bridge": "docker0",
                "Gateway": "172.17.42.1",
                "IPPrefixLen": 16,
                "IPAddress": "172.17.0.17"
            },
            "Image": "98e7ca605530c6ee637e175f08e692149a4d019b384e421e661bd35601b25975",
            "State": {
                "FinishedAt": "0001-01-01T00:00:00Z",
                "StartedAt": "2014-10-28T18:22:51.492441086Z",
                "ExitCode": 0,
                "Pid": 27669,
                "Paused": False,
                "Running": True
            },
            "Config": {
                "OnBuild": None,
                "NetworkDisabled": False,
                "Entrypoint": [
                    "/usr/local/bin/docker-hosts"
                ],
                "WorkingDir": "",
                "Volumes": {
                    "/var/run/docker.sock": {},
                    "/srv/hosts": {}
                },
                "Image": "blalor/docker-hosts:latest",
                "Cmd": [
                    "--domain-name=dev.docker",
                    "/srv/hosts"
                ],
                "AttachStdin": False,
                "Cpuset": "",
                "CpuShares": 0,
                "MemorySwap": 0,
                "Memory": 0,
                "User": "",
                "Domainname": "",
                "Hostname": "04bf6ca07d2c",
                "AttachStdout": False,
                "AttachStderr": False,
                "PortSpecs": None,
                "ExposedPorts": None,
                "Tty": False,
                "OpenStdin": False,
                "StdinOnce": False,
                "Env": [
                    "HOME=/",
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
                ]
            },
            "Args": [
                "--domain-name=dev.docker",
                "/srv/hosts"
            ],
            "Path": "/usr/local/bin/docker-hosts",
            "Created": "2014-10-28T18:22:51.142918682Z",
            "Id": "04bf6ca07d2c610235f57b041e224c19b6fab51d400a599ee0f1b1c53e12201f",
            "ResolvConfPath": "/etc/resolv.conf",
            "HostnamePath": "/var/lib/docker/containers/04bf6ca07d2c610235f57b041e224c19b6fab51d400a599ee0f1b1c53e12201f/hostname",
            "HostsPath": "/var/lib/docker/containers/04bf6ca07d2c610235f57b041e224c19b6fab51d400a599ee0f1b1c53e12201f/hosts",
            "Name": "/hosts",
            "Driver": "devicemapper",
            "ExecDriver": "native-0.2",
            "MountLabel": "",
            "ProcessLabel": ""
        })

        eq_(Manager.containerIsOutOfSync(container_def, container_info, img_info), False)
Ejemplo n.º 18
0
    def test_containerIsOutOfSync(self):
        container_def = ContainerDefinition.parseFile(os.path.join(self.EXAMPLE_DIR, "00-private-registry.yaml"))

        img_info = Image.fromJson({
            "Id": "2e2d7133e4a578bd861e85e7195412201f765d050af78c7906841ea62eb6f7dd",
            "Parent": "c79dab5561020bda9ce1b1cbe76283fc95f824cfb26a8a21a384993ed7f392bd",
            "Created": "2014-10-21T08:50:44.448455269Z",
            "Container": "b756100785c797b9f43d36f249b0d5688d88a1ca68df56d915cb436c4bfc7286",
            "Config": {
                "OnBuild": [],
                "NetworkDisabled": False,
                "Entrypoint": None,
                "WorkingDir": "",
                "Volumes": None,
                "Image": "c79dab5561020bda9ce1b1cbe76283fc95f824cfb26a8a21a384993ed7f392bd",
                "Cmd": [
                    "/bin/sh",
                    "-c",
                    "exec docker-registry"
                ],
                "AttachStdin": False,
                "Cpuset": "",
                "CpuShares": 0,
                "MemorySwap": 0,
                "Memory": 0,
                "User": "",
                "Domainname": "",
                "Hostname": "965c252e48c3",
                "AttachStdout": False,
                "AttachStderr": False,
                "PortSpecs": None,
                "ExposedPorts": {
                    "5000/tcp": {}
                },
                "Tty": False,
                "OpenStdin": False,
                "StdinOnce": False,
                "Env": [
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                    "DOCKER_REGISTRY_CONFIG=/docker-registry/config/config_sample.yml",
                    "SETTINGS_FLAVOR=dev"
                ]
            },
        })

        container_info = Container.fromJson("private-registry", {
            "HostConfig": {
                "NetworkMode": "",
                "VolumesFrom": None,
                "DnsSearch": None,
                "Binds": [
                    "/tmp:/var/lib/docker/registry",
                ],
                "ContainerIDFile": "",
                "LxcConf": None,
                "Privileged": False,
                "PortBindings": {
                    "5000/tcp": [
                        {
                            "HostPort": "11003",
                            "HostIp": "0.0.0.0"
                        }
                    ]
                },
                "Links": None,
                "PublishAllPorts": False,
                "Dns": None
            },
            "VolumesRW": {
                "/var/lib/docker/registry": True,
            },
            "Volumes": {
                "/var/lib/docker/registry": "/tmp",
            },
            "NetworkSettings": {
                "Ports": {
                    "5000/tcp": [
                        {
                            "HostPort": "11003",
                            "HostIp": "0.0.0.0"
                        }
                    ]
                },
                "PortMapping": None,
                "Bridge": "docker0",
                "Gateway": "172.17.42.1",
                "IPPrefixLen": 16,
                "IPAddress": "172.17.0.31"
            },
            "Image": "2e2d7133e4a578bd861e85e7195412201f765d050af78c7906841ea62eb6f7dd",
            "State": {
                "FinishedAt": "0001-01-01T00:00:00Z",
                "StartedAt": "2014-10-28T16:38:31.491949274Z",
                "ExitCode": 0,
                "Pid": 18785,
                "Paused": False,
                "Running": True
            },
            "Config": {
                "OnBuild": None,
                "NetworkDisabled": False,
                "Entrypoint": None,
                "WorkingDir": "",
                "Volumes": {
                    "/var/lib/docker/registry": {},
                },
                "Image": "registry:0.8.1",
                "Cmd": [
                    "/bin/sh",
                    "-c",
                    "exec docker-registry"
                ],
                "AttachStdin": False,
                "Cpuset": "",
                "CpuShares": 0,
                "MemorySwap": 0,
                "Memory": 0,
                "User": "",
                "Domainname": "",
                "Hostname": "private-registry",
                "AttachStdout": False,
                "AttachStderr": False,
                "PortSpecs": None,
                "ExposedPorts": {
                    "5000/tcp": {}
                },
                "Tty": False,
                "OpenStdin": False,
                "StdinOnce": False,
                "Env": [
                    "SETTINGS_FLAVOR=local",
                    "STORAGE_PATH=/var/lib/docker/registry",
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                    "DOCKER_REGISTRY_CONFIG=/docker-registry/config/config_sample.yml"
                ]
            },
            "Args": [
                "-c",
                "exec docker-registry"
            ],
            "Path": "/bin/sh",
            "Created": "2014-10-28T16:38:31.20825271Z",
            "Id": "758a155a0374fa7e163e4fc71e96cd1bd7de37674dd5f552b9183789366e91f7",
            "ResolvConfPath": "/etc/resolv.conf",
            "HostnamePath": "/var/lib/docker/containers/758a155a0374fa7e163e4fc71e96cd1bd7de37674dd5f552b9183789366e91f7/hostname",
            "HostsPath": "/var/lib/docker/containers/758a155a0374fa7e163e4fc71e96cd1bd7de37674dd5f552b9183789366e91f7/hosts",
            "Name": "/private-registry",
            "Driver": "devicemapper",
            "ExecDriver": "native-0.2",
            "MountLabel": "",
            "ProcessLabel": ""
        })

        eq_(Manager.containerIsOutOfSync(container_def, container_info, img_info), False)
Ejemplo n.º 19
0
 def __init__(self, id):
     if id == "a": self._background = Image("gfx/won_player_b.png")
     else: self._background = Image("gfx/won_player_a.png")
Ejemplo n.º 20
0
class TlGrass(Tile):
    _sprite = Image("gfx/grass.png")
Ejemplo n.º 21
0
class TlPlayer(Tile):
    _SPRITES = {
        "a": {
            "normal": Animation("gfx/player_a_%d.png", (0, 1), 0.1),
            "nobomb": Animation("gfx/player_a_nobomb_%d.png", (0, 1), 0.1),
            "bush": Image("gfx/player_bush.png"),
        },
        "b": {
            "normal": Animation("gfx/player_b_%d.png", (0, 1), 0.1),
            "nobomb": Animation("gfx/player_b_nobomb_%d.png", (0, 1), 0.1),
            "bush": Image("gfx/player_bush.png"),
        }
    }
    _SLOWNESS = 0.19

    #

    def __init__(self, x, y, z, id, axis, bomb_key):
        super().__init__(x, y, z)

        self.bomb_strength = 2
        self.bomb_cooldown = 1.75
        self.entering_bush = Trigger(False)

        self._axis = axis
        self._bomb_key = bomb_key
        self._id = id

        self._time_not_moving = self._SLOWNESS
        self._time_not_bombing = self.bomb_cooldown
        self._to_put_bomb = Trigger(False)
        self._in_bush = Trigger(False)

    #

    def on_overlapped(self, tile):
        if isinstance(tile, TlExplosion):
            tile.leftover = TlDeadPlayer(self.x, self.y, self.z, self._id)
            return True

        return False

    def on_update(self, dt):
        self._time_not_moving += dt
        self._time_not_bombing += dt

        if  self._time_not_moving >= self._SLOWNESS \
        and self.move(self._axis.x, self._axis.y):
            self._time_not_moving = 0

            if  self._to_put_bomb.trigger()                 \
            and self._time_not_bombing >= self.bomb_cooldown:
                self._time_not_bombing = 0

                stages.current.map.place(
                    TlBomb(self.x - self._axis.x,
                           self.y - self._axis.y,
                           self.z,
                           strength=self.bomb_strength,
                           in_bush=self._in_bush.trigger()))

            elif self._in_bush.trigger():
                stages.current.map.place(
                    TlBush(self.x - self._axis.x, self.y - self._axis.y,
                           self.z))

            if self.entering_bush.trigger():
                self._in_bush.arm()

    def on_draw(self, dt):
        sprite = self._SPRITES[self._id]["normal"]

        if self._in_bush:
            sprite = self._SPRITES[self._id]["bush"]

        elif self._time_not_bombing < self.bomb_cooldown:
            sprite = self._SPRITES[self._id]["nobomb"]

        sprite.draw(self.x * lib.TILE_SIZE, self.y * lib.TILE_SIZE, dt)

    def on_key_event(self, key, state):
        self._axis.react_to_key(key, state)

        if key == self._bomb_key and state:
            self._to_put_bomb.arm()
Ejemplo n.º 22
0
class TlConcrete(Tile):
    _sprite = Image("gfx/concrete.png")
Ejemplo n.º 23
0
    def test_containerIsOutOfSync_hosts(self):
        container_def = ContainerDefinition.parseFile(
            os.path.join(self.EXAMPLE_DIR, "00-hosts.yaml"))

        ## blalor/docker-hosts:latest
        img_info = Image.fromJson({
            "Size": 0,
            "Os": "linux",
            "Architecture": "amd64",
            "Id":
            "98e7ca605530c6ee637e175f08e692149a4d019b384e421e661bd35601b25975",
            "Parent":
            "15e3a43eb69d67df5a6ae1f3b3e87407f3b82157bf54fe8a5dc997cf2ce6528a",
            "Created": "2014-07-30T01:02:04.516066768Z",
            "Container":
            "5d7384258a7ac29d8eabe30b6b1d83dfe4a8925440f33982b439731906a087f2",
            "Docker_version": "1.1.1",
            "Author": "Brian Lalor <*****@*****.**>",
            "Config": {
                "OnBuild": [],
                "NetworkDisabled":
                False,
                "Entrypoint": ["/usr/local/bin/docker-hosts"],
                "WorkingDir":
                "",
                "Volumes":
                None,
                "Image":
                "15e3a43eb69d67df5a6ae1f3b3e87407f3b82157bf54fe8a5dc997cf2ce6528a",
                "Cmd":
                None,
                "AttachStdin":
                False,
                "Cpuset":
                "",
                "CpuShares":
                0,
                "MemorySwap":
                0,
                "Memory":
                0,
                "User":
                "",
                "Domainname":
                "",
                "Hostname":
                "5ca9d941ba62",
                "AttachStdout":
                False,
                "AttachStderr":
                False,
                "PortSpecs":
                None,
                "ExposedPorts":
                None,
                "Tty":
                False,
                "OpenStdin":
                False,
                "StdinOnce":
                False,
                "Env": [
                    "HOME=/",
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
                ]
            }
        })

        container_info = Container.fromJson(
            "hosts", {
                "HostConfig": {
                    "NetworkMode":
                    "",
                    "VolumesFrom":
                    None,
                    "DnsSearch":
                    None,
                    "Binds": [
                        "/var/run/docker.sock:/var/run/docker.sock:rw",
                        "/var/lib/docker/hosts:/srv/hosts:rw"
                    ],
                    "ContainerIDFile":
                    "",
                    "LxcConf":
                    None,
                    "Privileged":
                    False,
                    "PortBindings":
                    None,
                    "Links":
                    None,
                    "PublishAllPorts":
                    False,
                    "Dns":
                    None
                },
                "VolumesRW": {
                    "/var/run/docker.sock": True,
                    "/srv/hosts": True
                },
                "Volumes": {
                    "/var/run/docker.sock": "/var/run/docker.sock",
                    "/srv/hosts": "/var/lib/docker/hosts"
                },
                "NetworkSettings": {
                    "Ports": {},
                    "PortMapping": None,
                    "Bridge": "docker0",
                    "Gateway": "172.17.42.1",
                    "IPPrefixLen": 16,
                    "IPAddress": "172.17.0.17"
                },
                "Image":
                "98e7ca605530c6ee637e175f08e692149a4d019b384e421e661bd35601b25975",
                "State": {
                    "FinishedAt": "0001-01-01T00:00:00Z",
                    "StartedAt": "2014-10-28T18:22:51.492441086Z",
                    "ExitCode": 0,
                    "Pid": 27669,
                    "Paused": False,
                    "Running": True
                },
                "Config": {
                    "OnBuild":
                    None,
                    "NetworkDisabled":
                    False,
                    "Entrypoint": ["/usr/local/bin/docker-hosts"],
                    "WorkingDir":
                    "",
                    "Volumes": {
                        "/var/run/docker.sock": {},
                        "/srv/hosts": {}
                    },
                    "Image":
                    "blalor/docker-hosts:latest",
                    "Cmd": ["--domain-name=dev.docker", "/srv/hosts"],
                    "AttachStdin":
                    False,
                    "Cpuset":
                    "",
                    "CpuShares":
                    0,
                    "MemorySwap":
                    0,
                    "Memory":
                    0,
                    "User":
                    "",
                    "Domainname":
                    "",
                    "Hostname":
                    "04bf6ca07d2c",
                    "AttachStdout":
                    False,
                    "AttachStderr":
                    False,
                    "PortSpecs":
                    None,
                    "ExposedPorts":
                    None,
                    "Tty":
                    False,
                    "OpenStdin":
                    False,
                    "StdinOnce":
                    False,
                    "Env": [
                        "HOME=/",
                        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
                    ]
                },
                "Args": ["--domain-name=dev.docker", "/srv/hosts"],
                "Path": "/usr/local/bin/docker-hosts",
                "Created": "2014-10-28T18:22:51.142918682Z",
                "Id":
                "04bf6ca07d2c610235f57b041e224c19b6fab51d400a599ee0f1b1c53e12201f",
                "ResolvConfPath": "/etc/resolv.conf",
                "HostnamePath":
                "/var/lib/docker/containers/04bf6ca07d2c610235f57b041e224c19b6fab51d400a599ee0f1b1c53e12201f/hostname",
                "HostsPath":
                "/var/lib/docker/containers/04bf6ca07d2c610235f57b041e224c19b6fab51d400a599ee0f1b1c53e12201f/hosts",
                "Name": "/hosts",
                "Driver": "devicemapper",
                "ExecDriver": "native-0.2",
                "MountLabel": "",
                "ProcessLabel": ""
            })

        eq_(
            Manager.containerIsOutOfSync(container_def, container_info,
                                         img_info), False)
Ejemplo n.º 24
0
    def test_containerIsOutOfSync(self):
        container_def = ContainerDefinition.parseFile(
            os.path.join(self.EXAMPLE_DIR, "00-private-registry.yaml"))

        img_info = Image.fromJson({
            "Id":
            "2e2d7133e4a578bd861e85e7195412201f765d050af78c7906841ea62eb6f7dd",
            "Parent":
            "c79dab5561020bda9ce1b1cbe76283fc95f824cfb26a8a21a384993ed7f392bd",
            "Created": "2014-10-21T08:50:44.448455269Z",
            "Container":
            "b756100785c797b9f43d36f249b0d5688d88a1ca68df56d915cb436c4bfc7286",
            "Config": {
                "OnBuild": [],
                "NetworkDisabled":
                False,
                "Entrypoint":
                None,
                "WorkingDir":
                "",
                "Volumes":
                None,
                "Image":
                "c79dab5561020bda9ce1b1cbe76283fc95f824cfb26a8a21a384993ed7f392bd",
                "Cmd": ["/bin/sh", "-c", "exec docker-registry"],
                "AttachStdin":
                False,
                "Cpuset":
                "",
                "CpuShares":
                0,
                "MemorySwap":
                0,
                "Memory":
                0,
                "User":
                "",
                "Domainname":
                "",
                "Hostname":
                "965c252e48c3",
                "AttachStdout":
                False,
                "AttachStderr":
                False,
                "PortSpecs":
                None,
                "ExposedPorts": {
                    "5000/tcp": {}
                },
                "Tty":
                False,
                "OpenStdin":
                False,
                "StdinOnce":
                False,
                "Env": [
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                    "DOCKER_REGISTRY_CONFIG=/docker-registry/config/config_sample.yml",
                    "SETTINGS_FLAVOR=dev"
                ]
            },
        })

        container_info = Container.fromJson(
            "private-registry", {
                "HostConfig": {
                    "NetworkMode": "",
                    "VolumesFrom": None,
                    "DnsSearch": None,
                    "Binds": [
                        "/tmp:/var/lib/docker/registry",
                    ],
                    "ContainerIDFile": "",
                    "LxcConf": None,
                    "Privileged": False,
                    "PortBindings": {
                        "5000/tcp": [{
                            "HostPort": "11003",
                            "HostIp": "0.0.0.0"
                        }]
                    },
                    "Links": None,
                    "PublishAllPorts": False,
                    "Dns": None
                },
                "VolumesRW": {
                    "/var/lib/docker/registry": True,
                },
                "Volumes": {
                    "/var/lib/docker/registry": "/tmp",
                },
                "NetworkSettings": {
                    "Ports": {
                        "5000/tcp": [{
                            "HostPort": "11003",
                            "HostIp": "0.0.0.0"
                        }]
                    },
                    "PortMapping": None,
                    "Bridge": "docker0",
                    "Gateway": "172.17.42.1",
                    "IPPrefixLen": 16,
                    "IPAddress": "172.17.0.31"
                },
                "Image":
                "2e2d7133e4a578bd861e85e7195412201f765d050af78c7906841ea62eb6f7dd",
                "State": {
                    "FinishedAt": "0001-01-01T00:00:00Z",
                    "StartedAt": "2014-10-28T16:38:31.491949274Z",
                    "ExitCode": 0,
                    "Pid": 18785,
                    "Paused": False,
                    "Running": True
                },
                "Config": {
                    "OnBuild":
                    None,
                    "NetworkDisabled":
                    False,
                    "Entrypoint":
                    None,
                    "WorkingDir":
                    "",
                    "Volumes": {
                        "/var/lib/docker/registry": {},
                    },
                    "Image":
                    "registry:0.8.1",
                    "Cmd": ["/bin/sh", "-c", "exec docker-registry"],
                    "AttachStdin":
                    False,
                    "Cpuset":
                    "",
                    "CpuShares":
                    0,
                    "MemorySwap":
                    0,
                    "Memory":
                    0,
                    "User":
                    "",
                    "Domainname":
                    "",
                    "Hostname":
                    "private-registry",
                    "AttachStdout":
                    False,
                    "AttachStderr":
                    False,
                    "PortSpecs":
                    None,
                    "ExposedPorts": {
                        "5000/tcp": {}
                    },
                    "Tty":
                    False,
                    "OpenStdin":
                    False,
                    "StdinOnce":
                    False,
                    "Env": [
                        "SETTINGS_FLAVOR=local",
                        "STORAGE_PATH=/var/lib/docker/registry",
                        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                        "DOCKER_REGISTRY_CONFIG=/docker-registry/config/config_sample.yml"
                    ]
                },
                "Args": ["-c", "exec docker-registry"],
                "Path": "/bin/sh",
                "Created": "2014-10-28T16:38:31.20825271Z",
                "Id":
                "758a155a0374fa7e163e4fc71e96cd1bd7de37674dd5f552b9183789366e91f7",
                "ResolvConfPath": "/etc/resolv.conf",
                "HostnamePath":
                "/var/lib/docker/containers/758a155a0374fa7e163e4fc71e96cd1bd7de37674dd5f552b9183789366e91f7/hostname",
                "HostsPath":
                "/var/lib/docker/containers/758a155a0374fa7e163e4fc71e96cd1bd7de37674dd5f552b9183789366e91f7/hosts",
                "Name": "/private-registry",
                "Driver": "devicemapper",
                "ExecDriver": "native-0.2",
                "MountLabel": "",
                "ProcessLabel": ""
            })

        eq_(
            Manager.containerIsOutOfSync(container_def, container_info,
                                         img_info), False)
Ejemplo n.º 25
0
class TlBrick(BreakableTile):
    _sprite = Image("gfx/brick.png")
Ejemplo n.º 26
0
class Input_Panel(tk.Frame):
    def __init__(self, master, image, **kwargs):
        super().__init__(master, **kwargs)

        self.master = master
        self.rowconfigure(0, weight=1)
        self.rowconfigure(1, weight=1)
        self.columnconfigure(0, weight=1)

        self.options = {
            "Magnitude": Fourier.magnitude,
            "Phase": Fourier.phase,
            "Real": Fourier.real,
            "Imaginary": Fourier.imaginary
        }

        self.cbox = Combobox(
            self, values=["Magnitude", "Phase", "Real", "Imaginary"])
        self.cbox.set(self.cbox["values"][0])
        self.cbox.grid(row=0, column=0, sticky="ns", padx=4, pady=4)
        self.cbox.on_change(self.update_image)

        imgs_container = tk.Frame(self, bg="white")
        imgs_container.rowconfigure(0, weight=1)
        imgs_container.columnconfigure(0, weight=1)
        imgs_container.columnconfigure(1, weight=1)

        # buggy!!!!
        self.image = Image(imgs_container)
        self.image.open_image(image)
        self.image.show()

        self.gray_fourier = Fourier.fast2d(self.image.get_gray())

        self.image2 = Image(imgs_container)
        self.image2.size = self.image.size
        self.update_image(self.cbox.get())

        self.image.grid(row=0, column=0, sticky="nsew", padx=4, pady=4)
        self.image2.grid(row=0, column=1, sticky="nsew", padx=4, pady=4)
        imgs_container.grid(row=1, column=0, sticky="nsew", padx=4, pady=4)

    def update_image(self, label):
        # shift the fourier transform to the center
        # Without shifting the edges will illuminate instead
        # of the center
        if label == "Phase" or label == "Magnitude":
            shifted_fourier = np.fft.fftshift(self.gray_fourier)
            result = self.options.get(label)(shifted_fourier)
        else:
            result = self.options.get(label)(self.gray_fourier)

        if label == "Real":
            result = np.nan_to_num(
                20 * np.log(result)) + 20 * np.log(np.abs(np.min(result)))

        if label == "Magnitude":
            result = 20 * np.log(result)

        self.image2.set_image(result)
        self.image2.show()