def setup(self, intf=None, orig=False): Device.setup(self, orig=orig) if self.format and self.format.exists and not self.format.status: self.format.device = self.path for parent in self.parents: if orig: parent.originalFormat.setup() else: parent.format.setup()
def lambda_handler(request, context): global umap, device print('- Lambda_handler request:') print(json.dumps(request)) print('- Lambda_handler context:') print(context) response = validate_request( request) # IF THERE IS NO ERROR, this returns a 'None' object if response is not None: return send_response(response.get()) #database_url = None # use environment variable DATABASE_URL (defaults to 'sqlite:///:memory:') database_url = 'mysql://*****:*****@100.101.102.103:3306/customers' print('Using Database: ', database_url) try: if database_url is None: db = dataset.connect() else: db = dataset.connect(database_url) except Exception as e: print("EXCAPTION: Could not connect to database; " + str(e)) response = get_error_response('DATABASE_ERROR', 'Could not connect to database.') return send_response(response.get()) umap = UserMap(db) # you must always call setup() after this table_exists = umap.setup() if (not table_exists): response = get_error_response('DATABASE_ERROR', 'User table is missing.') return send_response(response.get()) device = Device(db) # you must always call setup() table_exists = device.setup() if (not table_exists): response = get_error_response('DATABASE_ERROR', 'Device table is missing.') return send_response(response.get()) (namespace, name) = get_name_and_space(request) if namespace == 'Alexa.Authorization': # the user has just enabled the skill if name == 'AcceptGrant': response = handle_grant(request) return send_response(response.get()) if namespace == 'Alexa.Discovery': if name == 'Discover': response = handle_discovery(request) return send_response(response.get()) if namespace == 'Alexa.PowerController': response = handle_power_state(request) return send_response(response.get()) # None of the above response = get_error_response('INVALID_DIRECTIVE', 'Invalid Alexa request; Unknown directive') return send_response(response.get())