import yaml import errno class Config(object): def __init__(self, engine, gui, message): try: self.config_file = open("config", "r") self.data = yaml.load(self.config_file) except IOError, e: print "Dropping into developer mode due to missing or invalid config file" gui.enable() engine.set_debug(True) message.set_debug(True) self.data['timeout'] = 10.0 self.data['status_target'] = 'http://10.8.0.171:8000/status' if not hasattr(self.data, 'gui') or self.data['gui']: gui.enable() debug = hasattr(self.data, 'debug') and self.data['debug'] engine.set_debug(debug) message.set_debug(debug) def save(self): self.config_file = open(self.config_file.name, "w") json.dump(self.config, self.config_file) self.config_file.close() def set_active_rect(self, rect): self.config['active_rect'] = rect def set_perspective_points(self, points): self.config['perspective_points'] = points def set_status_target(self, status_url): self.config['status_target'] = status_url def set_image_target(self, image_url): self.config['image_url'] = image_url