Beispiel #1
0
def check_modules(ctx, fname, expected):
    with open(ctx.get_out_path(os.path.join(BOM_DIR, fname)), 'rt') as f:
        text = f.read()
    m = re.search(r'var pcbdata = JSON.parse\(LZString.decompressFromBase64\("(.*)"\)\)', text, re.MULTILINE)
    assert m, text
    lz = LZString()
    js = lz.decompressFromBase64(m.group(1))
    data = json.loads(js)
    skipped = data['bom']['skipped']
    modules = [m['ref'] for m in data['modules']]
    assert len(modules)-len(skipped) == len(expected)
    logging.debug("{} components OK".format(len(expected)))
    for m in expected:
        assert m in modules
        assert modules.index(m) not in skipped
    logging.debug("List of components OK")
Beispiel #2
0
async def fetch_pixelzone(x, y, dx, dy):
    x = x + 4096
    y = y + 4096
    ext = Coords((x + dx) // 512 - x // 512 + 1,
                 (y + dy) // 512 - y // 512 + 1)
    chk = Coords(x // 512, y // 512)
    fetched = Image.new('RGB', (512 * ext.x, 512 * ext.y))

    url = "{0}://pixelzone.io/socket.io/?EIO=3&transport={1}"
    pkts_expected = 0
    async with aiohttp.ClientSession() as session:
        async with session.get(url.format("http", "polling")) as r:
            sid = json.loads(str((await r.read())[5:], "utf-8"))['sid']
    async with websockets.connect(url.format("ws", "websocket&sid=") +
                                  sid) as ws:
        await ws.send("2probe")
        await ws.recv()
        await ws.send("5")
        await ws.recv()
        for iy in range(ext.y):
            for ix in range(ext.x):
                if 0 <= chk.x + ix < 16 and 0 <= chk.y + iy < 16:
                    await ws.send(
                        "42[\"getChunkData\", {{\"cx\": {0}, \"cy\": {1}}}]".
                        format(chk.x + ix, chk.y + iy))
                    pkts_expected = pkts_expected + 1
        chunks = []
        if pkts_expected > 0:
            async for msg in ws:
                d = json.loads(msg[msg.find('['):])
                if d[0] == "chunkData":
                    chunks.append(d[1])
                if len(chunks) == pkts_expected:
                    break

    for data in chunks:
        chk_abs = Coords(data['cx'], data['cy'])
        chk_rel = Coords(chk_abs.x - chk.x, chk_abs.y - chk.y)
        tmp = LZString().decompressFromBase64(data['data'])
        tmp = json.loads("[" + tmp + "]")
        tmp = lz4.frame.decompress(bytes(tmp))
        chunk = Image.new('RGB', (512, 512), (255, 255, 255, 255))
        for py in range(chunk.height):
            for px in range(chunk.width):
                i = (py * 512 + px) / 2
                color_id = tmp[int(i)] & 15 if i % 1 == 0 else tmp[int(i)] >> 4
                color = colors.pixelzone[color_id]
                chunk.putpixel((px, py), color)
        fetched.paste(chunk, (chk_rel.x * 512, chk_rel.y * 512,
                              (chk_rel.x + 1) * 512, (chk_rel.y + 1) * 512))

    return fetched.crop((x % 512, y % 512, (x % 512) + dx, (y % 512) + dy))
Beispiel #3
0
 def load(self, data):
     tmp = LZString().decompressFromBase64(data)
     tmp = json.loads("[" + tmp + "]")
     tmp = lz4.frame.decompress(bytes(tmp))
     self._image = Image.frombytes('P', (512, 512), tmp, 'raw', 'P;4')
     self._image.putpalette(self.palette)