def run(expo_num, level_name, mode): game_str = "game%s" % expo_num game_settings_str = "Game%sSettings" % expo_num _temp = __import__("pkg.exponates", globals(), locals(), [game_str]) Exhibit = getattr(_temp, game_str).Exhibit _temp = __import__("pkg.settings", globals(), locals(), [game_settings_str]) Settings = getattr(_temp, game_settings_str) invoker = Invoker() settings = Settings(mode) level = None for l in settings.exhibit.levels: if l.name == level_name: level = l if level is None: level = settings.exhibit.levels[0] # inject level-specific settings into settings object for key, val in level.params.items(): setattr(settings, key, val) # set test exhibit to selected level if expo_num == "Test" and level_name != "default": io_settings_str = "Game%sSettings" % level_name _temp = __import__("pkg.settings", globals(), locals(), [io_settings_str]) IOSettings = getattr(_temp, io_settings_str) io_settings = IOSettings(mode) settings.key_map = io_settings.key_map settings.light_map = io_settings.light_map settings.seven_length = io_settings.seven_length logger.info("start_expo.py, before localizing settings") try: from pkg.local_settings import localize_settings except Exception as e: logger.warn("no local settings") if "localize_settings" in locals(): try: localize_settings(settings) logger.info("localizing settings") except Exception as e: logger.error("failed to load local setings") logger.error(e) if mode == "emulator": env = Emulator(invoker, settings) else: from pkg.rpi_env import RpiEnv env = RpiEnv(invoker, settings) exhibit = Exhibit(invoker, env, settings) invoker.start() env.run()
def __format__(self, text, phormat, length): """ helper text-formatting function """ text = phormat%text _text = re.sub(r'[.,]','',text) while len(_text)>length: text=text[0:-1] _text = re.sub(r'[.,]','',text) logger.warn('stripping 7 segment text too long; stripping it') text=' '*(length-len(_text))+text return text
def _start(): try: with Popen(self.env, self.st.script_command, shell=False, stdout=subprocess.PIPE) as child: then = 0 while True: out = child.stdout.readline() m = re.search(r'^(\d+)\t([\d.]+)\t([\d.]+)', out) if m: now = int(m.group(1)) power = float(m.group(2))*float(m.group(3)) energy = power * (now - then) / 1000 then = now if global_idle == True and power <= self.st.threshold: pass else: self.fire_event(energy, power) else: logger.warn('problem parsing ' + str(out)) except Exception as e: logger.error(e)