def __init__(self, name, loader=None): """Initialize, but do not start the WSGI server. :param name: The name of the WSGI server given to the loader. :param loader: Loads the WSGI application using the given name. :returns: None """ self.name = name self.manager = self._get_manager() self.loader = loader or wsgi_common.Loader() self.app = self.loader.load_app(name) self.host = getattr(CONF, '%s_listen' % name, "0.0.0.0") self.port = getattr(CONF, '%s_listen_port' % name, 0) self.workers = (getattr(CONF, '%s_workers' % name, None) or processutils.get_worker_count()) if self.workers and self.workers < 1: worker_name = '%s_workers' % name msg = (_("%(worker_name)s value of %(workers)d is invalid, " "must be greater than 0.") % {'worker_name': worker_name, 'workers': self.workers}) raise exception.InvalidInput(msg) setup_profiler(name, self.host) self.server = wsgi.Server(name, self.app, host=self.host, port=self.port)
def setUp(self): super(TestLoaderNormalFilesystem, self).setUp() self.config = tempfile.NamedTemporaryFile(mode="w+t") self.config.write(self._paste_config.lstrip()) self.config.seek(0) self.config.flush() self.loader = wsgi_common.Loader(self.config.name) self.addCleanup(self.config.close)
def load(self): gd = self.gd Mloc = 0 if gd.rd32(Mloc) != self.version: ld = common.Loader(gd) ld.add(struct.pack("4I", self.version, 0, 0, 0)) self.subload(ld)
def _application(): objects.register_all() CONF(sys.argv[1:], project='<project_name>', version=version.version_string()) logging.setup(CONF, "<project_name>") rpc.init(CONF) return wsgi_common.Loader().load_app(name='osapi_<project_name>')
def load(self): eve = self.eve ld = common.Loader(self.eve) # ld.add(struct.pack("4I", self.version, 0, 0, 0)) self.subload(ld) self.wave = wave.open("track4.wav", "rb") NF = 700 self.wave.readframes(NF * 44100 // 30)
def load(self): gd = self.gd # gd.ClearColorRGB(0, 255, 0) # gd.Clear() # gd.swap() ld = common.Loader(gd) gd.BitmapHandle(0) ld.L8(Image.open("assets/caustics.png")) self.gd.cmd_setbitmap(0, gd3.L8, 128, 128) gd.BitmapSize(gd3.NEAREST, gd3.REPEAT, gd3.REPEAT, 0, 0)
def load(self): gd = self.gd Mloc = 0 if gd.rd32(Mloc) != self.version: ld = common.Loader(gd) ld.add(struct.pack("4I", self.version, 0, 0, 0)) gd.BitmapHandle(0) ld.Lastc("assets/celestial-day.astc") gd.BitmapHandle(1) ld.Lastc("assets/celestial-night.astc") print(hex(gd.rd32(Mloc)))
def poweron(): gd = Gameduino() gd.setup_1280x720() # Make sure $c0000 is 0x15 gd.cmd_memwrite(0xc0000, 1) gd.cc(b'\x15' * 4) ld = common.Loader(gd) ld.add = ld.uadd # Handle 0: gameduino logo gd.BitmapHandle(0) im = Image.open("assets/gameduino.png").convert("RGB") ld.RGB565(im) (w, h) = im.size gd.BitmapSize(eve.NEAREST, eve.BORDER, eve.BORDER, 0, 3 * h) # Handle 1: grid H = 0x60 grid = Image.frombytes( "L", (4, 4), bytes([H, H, H, H, H, 0, 0, 0, H, 0, 0, 0, H, 0, 0, 0])) gd.BitmapHandle(1) ld.L8(grid) gd.BitmapSize(eve.BILINEAR, eve.REPEAT, eve.REPEAT, 0, 3 * h) # Handle 2: dazzler glowing text daz = gentext("dazzler") gd.BitmapHandle(2) ld.L8(daz) gd.ClearColorRGB(0x20, 0x00, 0x00) gd.Clear() gd.Begin(eve.BITMAPS) gd.SaveContext() gd.cmd_scale(3, 3) gd.cmd_setmatrix() gd.BitmapHandle(0) gd.Vertex2f((1280 - 3 * w) / 2, 65) gd.RestoreContext() gd.SaveContext() gd.cmd_loadidentity() gd.cmd_scale(0.75, 0.75) gd.cmd_setmatrix() gd.ColorRGB(0x20, 0x00, 0x00) gd.BitmapHandle(1) gd.Vertex2f(0, 0) gd.RestoreContext() gd.BitmapHandle(2) gd.ColorA(0xf0) (x, y) = ((1280 - daz.size[0]) / 2, 380) gd.Vertex2f(x, y) gd.cmd_text(640, 690, 31, eve.OPT_CENTER, __VERSION__) gd.ColorRGB(0xe0, 0xe0, 0xe0) gd.cmd_text(10, 690, 29, eve.OPT_CENTERY | eve.OPT_FORMAT, "%s", 0xb0000) gd.cmd_text(1270, 690, 29, eve.OPT_RIGHTX | eve.OPT_CENTERY | eve.OPT_FORMAT, "%s", 0xb0100) gd.swap() print('poweron is', len(gd.buf), 'bytes') return gd.buf
def make_loadscreen(): gd = Gameduino() gd.cmd_memwrite(eve.REG_MACRO_0, 4) gd.ClearStencil(0) gd.cmd_memzero(0, 2**20) if 0: gd.cmd_memset(0, 0x69, 2**20) gd.cmd_memwrite(0, 2**16) import random gd.cc(bytes([random.randrange(0x40, 0x60) for _ in range(2**16)])) gd.BitmapHandle(0) gd.cmd_setbitmap(0, eve.RGB565, 256, 128) gd.BitmapSize(eve.NEAREST, eve.BORDER, eve.BORDER, 4 * 256, 4) gd.BitmapSizeH((4 * 256) >> 9, (4) >> 9) ld = common.Loader(gd, 2**20 - 8 - 16) ld.add = ld.uadd H = 150 grid = Image.frombytes( "L", (4, 4), bytes([H, H, H, H, H, 0, 0, 0, H, 0, 0, 0, H, 0, 0, 0])) gd.BitmapHandle(1) ld.L8(grid) gd.BitmapSize(eve.NEAREST, eve.REPEAT, eve.REPEAT, 4 * 256, 4 * 128) gd.BitmapSizeH((4 * 256) >> 9, (4 * 128) >> 9) gd.BitmapHandle(2) gd.cmd_setbitmap(LP + 4, eve.TEXT8X8, 8 * 32, 8 * 1) gd.BitmapSize(eve.NEAREST, eve.BORDER, eve.BORDER, 512, 16) gd.BitmapSizeH(512 >> 9, 16 >> 9) gd.VertexFormat(2) gd.ClearColorRGB(0x20, 0x00, 0x00) gd.Macro(0) gd.Clear() gd.StencilMask(0) gd.StencilFunc(eve.EQUAL, 0, 0xff) gd.cmd_text(640, 60, 31, eve.OPT_CENTER, "Unpacking slot image, please wait") gd.StencilFunc(eve.EQUAL, 1, 0xff) gd.cmd_text(640, 60, 31, eve.OPT_CENTER, "Writing to flash, please wait") gd.StencilFunc(eve.ALWAYS, 1, 0xff) gd.Begin(eve.BITMAPS) gd.SaveContext() gd.ColorRGB(200, 255, 200) gd.cmd_scale(2, 2) gd.cmd_setmatrix() gd.BitmapHandle(2) gd.Vertex2f(640 - 256, 120) gd.RestoreContext() gd.SaveContext() gd.cmd_loadidentity() gd.cmd_scale(4, 4) gd.cmd_setmatrix() gd.BitmapHandle(0) gd.BlendFunc(1, 0) (x, y) = ((1280 - 1024) / 2, (720 - 512) / 2 + 80) for i in range(128): gd.BitmapSource(LP + 8192 * i) gd.Vertex2f(x, y + 4 * i) gd.RestoreContext() gd.BitmapHandle(1) gd.ColorRGB(0, 0, 0) gd.Vertex2f(x, y) gd.swap() for i in range(0): for j in range(10): gd.cmd_sync() gd.cmd_memwrite(eve.REG_MACRO_0, 4) gd.ClearStencil(i) return gd.buf
def make_menu(): gd = Gameduino() if 1: gd.cmd_memwrite(eve.REG_MACRO_0, 4) gd.ClearStencil(0x20 | 0x10 | 0x08 | 2) if 0: gd.cmd_memzero(0x0, 32 * 8) def setlabel(n, s): gd.cmd_memwrite(32 * n, len(s) + 1) gd.cc(eve.align4(s + bytes([0]))) setlabel(0, b"Dazzler boot 1.1.0") setlabel(1, b"Text mode 1.1.0") setlabel(2, b"Asteroids") setlabel(7, b"SAYS 7") gd.setup_1280x720() ld = common.Loader(gd, 0x200) ld.add = ld.uadd # Handle 0: microSD gd.BitmapHandle(0) im = Image.open("assets/microsd.png").convert("L") ld.L8(im) # Handle 1: Wii gd.BitmapHandle(1) im = Image.open("assets/Wii_Classic_Controller_Icon.png").convert("L") ld.L8(im) gd.VertexFormat(2) gd.ClearColorRGB(0x20, 0x00, 0x00) gd.Macro(0) gd.Clear() gd.StencilMask(0) rim = [(12, (0x40, 0x40, 0x40)), (8, (0x18, 0x00, 0x00))] px = 110 - 4 for s in range(8): y = 90 * s gd.Begin(eve.RECTS) for (w, col) in rim: gd.ColorRGB(*col) gd.LineWidth(w) gd.Vertex2f(110, y + 10) gd.Vertex2f(700, y + 80) gd.SaveContext() gd.StencilFunc(eve.EQUAL, s, 0x07) gd.ColorRGB(0x40, 0x40, 0x40) gd.Vertex2f(110, y + 10) gd.Vertex2f(700, y + 80) gd.RestoreContext() gd.Begin(eve.POINTS) for (w, col) in rim: gd.ColorRGB(*col) gd.PointSize(2 * 20 + w) gd.Vertex2f(px, y + 45) gd.ColorRGB(0xff, 0xff, 0xff) gd.cmd_number(px, y + 45, 29, eve.OPT_CENTER, s) gd.cmd_text(160, y + 45, 30, eve.OPT_CENTERY | eve.OPT_FORMAT, "%s", 32 * s) s = "Press A to launch the slot. Press X to load it from microSD" gd.ColorRGB(255, 255, 255) gd.cmd_fillwidth(400) gd.cmd_text(810, 110, 30, eve.OPT_FILL, s) gd.Begin(eve.BITMAPS) def light(mask, dr): gd.StencilFunc(eve.ALWAYS, 0, 0) gd.ColorRGB(0x40, 0x40, 0x40) dr() gd.StencilFunc(eve.EQUAL, mask, mask) gd.ColorRGB(0xc0, 0xc0, 0xc0) dr() gd.BitmapHandle(0) light(0x08, lambda: gd.Vertex2f(740, 610)) gd.BitmapHandle(1) light(0x10, lambda: gd.Vertex2f(824, 600)) light(0x20, lambda: gd.Vertex2f(1050, 600)) gd.swap() for i in range(0): for j in range(10): gd.cmd_sync() gd.cmd_memwrite(eve.REG_MACRO_0, 4) gd.ClearStencil(i) return gd.buf
# ---------------------------- Asteroids gd = Gameduino() gd.setup_1280x720() sfx = [ "explode1.wav", "explode2.wav", "explode3.wav", "fire.wav", "life.wav", "lsaucer.wav", "sfire.wav", "ssaucer.wav", "thrust.wav", "thumphi.wav", "thumplo.wav" ] def ldwav(fn): return sample("assets/asteroids_samples/" + fn) wavs = [ldwav(fn) for fn in sfx] ld = common.Loader(gd) ld.add = ld.uadd ld.Lastc("assets/asteroids_internal.astc") gd.Clear() gd.cmd_text(640, 360, 31, eve.OPT_CENTER, "Asteroids is loading") gd.Vertex2f(0, 0) gd.swap() make_liteboot("Asteroids", "../j1/build/asteroids.hex", [gd.buf] + wavs, "_loadflash_asteroids.bin") # ---------------------------- Textmode gd = Gameduino() t = textmode.Textmode(gd)
def load(self): gd = self.gd ld = common.Loader(self.gd) # ld.add(struct.pack("4I", self.version, 0, 0, 0)) self.subload(ld)
def draw(self): gd = self.gd y0 = 720 - 640 t = time.time() # + 180 * 24 * 3600 t = time.time() + self.t * 600 (sun_lat, sun_lon) = subsolar_point(t) print(self.t, sun_lat, sun_lon) x = 640 + 640 * sun_lon / 180 y = y0 + 320 - 320 * sun_lat / 90 lim = light(sun_lat, sun_lon) ld = common.Loader(gd) ld.a = (1 << 20) - (256 * 128) gd.BitmapHandle(2) ld.L8(lim) gd.BitmapSize(gd3.BILINEAR, gd3.REPEAT, gd3.BORDER, 0, 0) gd.VertexFormat(2) # Match the color of the arctic br = lim.load()[128, 0] / 255 r = int(common.lerp(br, 27, 255)) g = int(common.lerp(br, 27, 255)) b = int(common.lerp(br, 55, 255)) gd.ClearColorRGB(r, g, b) gd.Clear() gd.Begin(gd3.BITMAPS) gd.SaveContext() gd.BitmapHandle(1) i = 180 gd.ColorRGB(i, i, i) gd.Vertex2f(0, y0) gd.RestoreContext() gd.SaveContext() sf = 1280 / 256 gd.cmd_scale(sf, sf) gd.cmd_setmatrix() gd.BitmapHandle(2) gd.ColorMask(0, 0, 0, 1) gd.BlendFunc(1, 0) gd.Vertex2f(0, y0) gd.RestoreContext() gd.SaveContext() gd.BlendFunc(gd3.DST_ALPHA, gd3.ONE_MINUS_DST_ALPHA) gd.BitmapHandle(0) gd.Vertex2f(0, y0) gd.RestoreContext() gd.SaveContext() gd.Begin(gd3.POINTS) gd.ColorRGB(80, 70, 30) gd.BlendFunc(gd3.SRC_ALPHA, gd3.ONE) for i in range(50, 250, 50): gd.PointSize(i) gd.Vertex2f(x, y) gd.RestoreContext() dt = datetime.datetime.fromtimestamp(t, timezone.utc) if 0: gd.SaveContext() gd.ColorRGB(0, 0, 0) gd.cmd_text(640, 3, 31, gd3.OPT_CENTERX, dt.ctime()) gd.RestoreContext() if 0: for i in range(25): hr = (dt.hour - 12 + i) % 12 gd.cmd_clock(1280 * i // 24, 30, 20, gd3.OPT_FLAT | gd3.OPT_NOSECS, hr, dt.minute, 0, 0) self.t += 1 # gd.screenshot_im().save("out.png"); sys.exit(0); # time.sleep(10) assert self.t < 180