def on_new_connection(self, mgr, connection): """Handle the establishment of new DBGp connections. Binds new connections to page manager instances. """ page_mgr = PageManager() page_mgr.setup(connection) self._page_mgrs.append(page_mgr)
def __init__(self, *, memorysize=10): self.time = 0 # This state's wall duration self.clock = 0 # The current wall clock self.mem = PhysicalMemory(memorysize) self.pagemngr = PageManager(self.mem) self.sched = Scheduler() self.pidcount = 0 self.pid = None
def test_process_run_two_segments(): mem = PhysicalMemory(1) pm = PageManager(mem) proc = Process(pm, '../programs/two_fifties.process', 1) proc.run(100) assert proc.state == ProcessState.EXIT assert proc.program_counter == 2
def test_process_run(): mem = PhysicalMemory(1) pm = PageManager(mem) proc = Process(pm, '../programs/100work.process', 1) proc.run(90) assert proc.unfinished_work == 90 proc.run(10) assert proc.state == ProcessState.EXIT
class Ceefax: _instance = None def __init__(self, test=None): self.start_time = config.now() if config.NAME == "KLBFAX": points.add_one_random(printing=True) if not os.path.isdir(config.config_dir): os.mkdir(config.config_dir) self.test = test def begin(self): with Screen() as scr: self.page_manager = PageManager(scr) self.start_loop() def start_loop(self): self.page_manager.start_loop(self.test) def kill(self): raise KeyboardInterrupt
def __init__(self, hub): Thread.__init__(self) self.hub = hub self.pageManager = PageManager(self) # for Adafruit PiTFT: if 'armv6l' in platform.uname(): os.putenv('SDL_VIDEODRIVER', 'fbcon') os.putenv('SDL_FBDEV' , '/dev/fb1') os.putenv('SDL_MOUSEDRV' , 'TSLIB') os.putenv('SDL_MOUSEDEV' , '/dev/input/touchscreen') # Init pygame and screen pygame.display.init() pygame.font.init() if 'armv6l' in platform.uname(): pygame.mouse.set_visible(False) self.logic = None
class SimulationState: def __init__(self, *, memorysize=10): self.time = 0 # This state's wall duration self.clock = 0 # The current wall clock self.mem = PhysicalMemory(memorysize) self.pagemngr = PageManager(self.mem) self.sched = Scheduler() self.pidcount = 0 self.pid = None def serialize(self): obj = {} obj['clock'] = self.clock obj['time'] = self.time obj['pid'] = self.pid obj['mem'] = self.mem.serialize() obj['pagemngr'] = self.pagemngr.serialize() obj['scheduler'] = self.sched.serialize() return obj
def begin(self): with Screen() as scr: self.page_manager = PageManager(scr) self.start_loop()
#!/usr/bin/env python import sys sys.path.insert(0, '..') from page import PageManager, Page from cupt import DummyScreen page_manager = PageManager(DummyScreen()) page_manager.test_all_pages()
def test_make_page(): mem = PhysicalMemory(1) pm = PageManager(mem) page = pm.make_page(32) assert pm.mem.get(page.addr) == 32
class TFT(Thread): DEBUG = False FPS = 10 WINDOW_WIDTH = 320 WINDOW_HEIGHT = 240 WINDOW_SIZE = (WINDOW_WIDTH, WINDOW_HEIGHT) BLACK = ( 0, 0, 0) def __init__(self, hub): Thread.__init__(self) self.hub = hub self.pageManager = PageManager(self) # for Adafruit PiTFT: if 'armv6l' in platform.uname(): os.putenv('SDL_VIDEODRIVER', 'fbcon') os.putenv('SDL_FBDEV' , '/dev/fb1') os.putenv('SDL_MOUSEDRV' , 'TSLIB') os.putenv('SDL_MOUSEDEV' , '/dev/input/touchscreen') # Init pygame and screen pygame.display.init() pygame.font.init() if 'armv6l' in platform.uname(): pygame.mouse.set_visible(False) self.logic = None def stop(self): self.stopped = True sleep(0.2) pygame.quit() def run(self): self.stopped = False self.FPSCLOCK = pygame.time.Clock() self.screen = pygame.display.set_mode(self.WINDOW_SIZE, 0, 32) #wait for the ralay to load if 'armv6l' in platform.uname(): dependencies = set(["RELAY", "TEMPERATURE", "HUMIDITY", "LUMINOSITY", "CURRENT","USER MANAGER", "SCHEDULE MANAGER", "LOGIC ENGINE"]) waiting = len(dependencies) while waiting > 0: waiting = 0 for x in dependencies: if x not in self.hub: waiting = waiting + 1 print "Waiting for ", x if self.DEBUG and waiting > 0: print "PITFT waiting for "+str(waiting)+" Modules to be Loaded" sleep(0.5) self.relay = self.hub["RELAY"] self.scheduler = self.hub["SCHEDULE MANAGER"] self.logic = self.hub["LOGIC ENGINE"] self.draw() intermediate_update = 0 while not self.stopped: self.update() if intermediate_update > self.FPS*5: self.draw() intermediate_update = 0 else: intermediate_update += 1 def update(self): self.FPSCLOCK.tick(self.FPS) self.handleEvents() def draw(self): if self.DEBUG: print "Draw Screen" self.screen.fill(self.BLACK) self.pageManager.render() pygame.display.update() def handleEvents(self): if self.stopped: return try: pevents = pygame.event.get() except: return for event in pevents: if self.DEBUG: print event if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE): self.stop() redraw = self.pageManager.currentPage.handleEvent(event) if redraw and not self.stopped: self.draw() return def get_local_IP(self): ip = "0.0.0.0" if 'armv6l' in platform.uname(): try: p = subprocess.Popen("sudo ifconfig br0; sudo ifconfig bat0", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) lines = p.stdout.readlines() for line in lines: if "inet addr:" in line: ip = str(line.split()[1].split(':')[1]) return ip except: return ip return ip
#!/usr/bin/env python import sys sys.path.insert(0, '..') import os os.environ["WWW"] = "1" from page import PageManager, Page from ceefax import Ceefax from cupt import DummyScreen cee = Ceefax() page_manager = PageManager(DummyScreen()) cee.page_manager = page_manager page_manager.export_all_to_html()