def SetupServer(app=None, socketio=None, host='localhost', port=5000, debug=True): # Initial Setup global FLASK_CORE_APP, SOCKET_IO_CORE, DB_CONNECTION, MESSAGING_GATEWAY if app is None: app = FLASK_CORE_APP if socketio is None: socketio = SOCKET_IO_CORE aPort = int(os.getenv('PORT', port)) if (aPort != port or host != 'localhost') and debug: host = '0.0.0.0' debug = False logWarning("Going to host 0") app.debug = bool(debug) #Allow some env specification of helpful test services services = [ CSVLoggingService("logfile.csv"), ] if os.getenv('TESTSERVICE', ''): logWarning('SKO_Architecture.MessagingGateway.TestService will be run') from SKO_Architecture.MessagingGateway import TestService services.append(TestService()) MESSAGING_GATEWAY = HTTPMessagingGateway( None, SOCKET_IO_CORE, flask.ext.socketio, services ) return socketio
def eval(self, num_string, parseAll=True): #logWarning('here it is ', num_string) if isinstance(num_string, unicode): num_string = num_string.encode('ascii', 'ignore') if len(num_string) == 0: return '' poses = [m.start() for m in re.finditer('\(', num_string)] #logWarning(poses) newstring = '' n = 0 while n < len(num_string): if n not in poses: newstring = newstring + num_string[n] else: if n == 0: newstring = newstring + num_string[n] elif (num_string[n - 1].isdigit()) or (num_string[n - 1] == ')'): newstring = newstring + "*(" else: newstring = newstring + num_string[n] n = n + 1 num_string = newstring #logWarning('string after = ' , num_string) self.exprStack = [] try: results = self.bnf.parseString(num_string, parseAll) val = self.evaluateStack(self.exprStack[:]) except ParseException, err: logWarning(err.line, '\n', num_string, '\n', " " * (err.column - 1) + "^", '\n', err) val = num_string
def _createValue(self, key, value, name="", description="", tags=None, storageType=DATA_TYPE_DB, dataType=""): # Force Valid Default values if name is None: name = "" if description is None: description = "" if tags is None: tags = [] if dataType is None: dataType = "" if storageType is None: storageType = DATA_TYPE_DB # Must be a valid storage type if ( key is not None and isinstance(key, basestring) and isinstance(storageType, int) and storageType in VALID_STORAGE_TYPES ): storageData = {"key": key, "value": value, "name": name, "data_type": dataType, "description": description} storageClass = self.STORAGE_ADAPTORS[storageType] data = storageClass(**storageData) if name != "": self.name_map[name] = key self.adaptor_map[key] = storageType for tag in tags: self.addTagKey(tag, key, delaySave=True) data.save() self.save() self.reload() return True else: logWarning("Couldn't create :" + str(key)) return False
def _updateValue(self, key, value=None, name=None, description=None, tags=None, storageType=None, dataType=None): key = self.resolveRef(key, name) currentName = self.getName(key) data = self._getData(key) if key is not None and data is not None: if name is not None and currentName != name: isChanged, data = self._changeName(name, data) if not isChanged: # Failed on change name attempt logWarning("Failed to update, rename failed: ", name) return False if value is not None: data.value = value if dataType is not None: data.data_type = dataType if description is not None: data.description = description if storageType is not None: # @TODO: Fix this so it works appropriately # (e.g., changes the stored object type) # For now, no-op # self.adaptor_map[key] = storageType pass if tags is not None: self.changeTags(tags, key, delaySave=True) data.save() self.save() self.reload() return True else: logWarning("Error in updateValue. Couldn't get rename for: " + str(key)) return False
def eval(self, num_string, parseAll=True): #logWarning('here it is ', num_string) if isinstance(num_string, unicode): num_string = num_string.encode('ascii', 'ignore') if len(num_string) == 0: return '' poses = [m.start() for m in re.finditer('\(',num_string )] #logWarning(poses) newstring = '' n=0 while n < len(num_string): if n not in poses: newstring = newstring+num_string[n] else: if n == 0: newstring = newstring+num_string[n] elif (num_string[n-1].isdigit()) or (num_string[n-1] == ')'): newstring = newstring + "*(" else: newstring = newstring + num_string[n] n = n+1 num_string = newstring #logWarning('string after = ' , num_string) self.exprStack=[] try: results=self.bnf.parseString(num_string, parseAll) val=self.evaluateStack( self.exprStack[:] ) except ParseException, err: logWarning(err.line, '\n', num_string, '\n', " "*(err.column-1) + "^", '\n', err) val = num_string
def StartServer(app=None, socketio=None, host='localhost', port=5000, debug=True): socketio = SetupServer(app, socketio, host, port, debug) Thread(target=background_thread).start() logWarning("Starting Socket App") try: socketio.run(app, host=host, port=port) except Exception, err: DB_CONNECTION.close()
def sendMessage(self, msg): print("%s sending %s" % (self.__class__.__name__, msg)) if self._gateway is not None: print("Actually sent it.") self._gateway.dispatchMessage(msg, self.getId()) self.distributeMessage(msg, msg.getContextValue(ORIGINATING_SERVICE_ID_KEY)) logWarning("Message DISTRIBUTED: %s" % (msg, ))
def template_imports(path): if path[-5:] in ('.html',): try: path = path.split('//')[-1] logWarning(path) return render_template(path) except Exception: abort(404) else: return abort(404)
def handleConvertMsg(self, msg): text = msg.getActor() if text is None: text = '' try: text = self.translateToSpeech(text) except Exception, err: text = None logWarning("COULD NOT TRANSLATE: ", msg.getActor()) raise err
def _getData(self, key): if key is None: return None storage = self.getStorageAdaptor(key) if storage is not None: data = storage.objects(key=key).first() if data is None: logWarning("No data for: ", key) return data logWarning("No data for: ", key) return None
def createCalendarData(self, ownerId=None, ownerType=None, permissions=None, data=None): if ownerId is None: logWarning("NO OWNER ID WAS GIVEN WHEN ATTEMPTING TO LOOK UP CALENDAR") return None if data is None: data = Calendar().to_ical() result = self.DB_BRIDGE.getCalendarFromOwnerId(ownerId) if result is None: result = DBCalendarData() result.setCalendarData(ownerId, ownerType, permissions, data) result.saveToDB() return result
def stringToMessage(self, msg): if (CATCH_BAD_MESSAGES): try: msg = nativizeObject(msg) except: logWarning( "ERROR: Could not process message data received. Received:" + str(msg)) msg = None else: msg = nativizeObject(msg) return msg
def logfile_imports(path): if path[-4:] in ('.log', '.csv'): try: path = path.split('//') path.insert(0, 'Services') path = '//'.join(path) logWarning(path) return FLASK_CORE_APP.send_static_file(path) except Exception: abort(404) else: return abort(404)
def processStorageInform(self, bucket, verb, key=None, value=None, tags=None, aType=None, allowCreate=None, name=None, description=None, dataType=None): if verb == self.VALUE_VERB: logWarning("IS SETTING", value) if isinstance(value, SuperGlu_Serializable): logWarning("IS SERIALIZABLE") dataType = SERIALIZABLE_DATA_TYPE if key is None: key = value.getId() elif key != value.getId(): logWarning('BAD KEY for Storage (%s != %s)' % (key, value.getId())) return False if isinstance(value, NamedSerializable): if name is None: name = value.getName() elif name != value.getName(): logWarning('BAD NAME for Storage(%s != %s)' % (name, value.getName())) return False value = serializeObject(value, JSON_FORMAT) return bucket.setValue(key, value, name, description, tags, aType, dataType, True, allowCreate) elif verb == self.VOID_VERB: return bucket.delValue(key, name)
def processStorageInform( self, bucket, verb, key=None, value=None, tags=None, aType=None, allowCreate=None, name=None, description=None, dataType=None, ): if verb == self.VALUE_VERB: logWarning("IS SETTING", value) if isinstance(value, Serializable): logWarning("IS SERIALIZABLE") dataType = SERIALIZABLE_DATA_TYPE if key is None: key = value.getId() elif key != value.getId(): logWarning("BAD KEY for Storage (%s != %s)" % (key, value.getId())) return False if isinstance(value, NamedSerializable): if name is None: name = value.getName() elif name != value.getName(): logWarning("BAD NAME for Storage(%s != %s)" % (name, value.getName())) return False value = serializeObject(value, JSON_FORMAT) return bucket.setValue(key, value, name, description, tags, aType, dataType, True, allowCreate) elif verb == self.VOID_VERB: return bucket.delValue(key, name)
def onReceiveAJAXMessage(self, msg, sid): """ Take message from client and send parent gateway and any child serices """ if self.DATA_KEY in msg: sessionId = msg.get(SESSION_KEY, None) #if sessionId is not None and len(self._socketioModule.rooms()) == 0: self._socketio.server.enter_room(sid, sessionId, self.MESSAGES_NAMESPACE) # Wrap in a try/except msg = self.stringToMessage(msg[self.DATA_KEY]) msg.setContextValue("sid", sid) if isinstance(msg, Message): if self._gateway is not None: self._gateway.dispatchMessage(msg, self.getId()) self.distributeMessage(msg) else: logWarning("GATEWAY DID NOT UNDERSTAND: ", msg)
def createCalendarData(self, ownerId=None, ownerType=None, permissions=None, data=None): if ownerId is None: logWarning( "NO OWNER ID WAS GIVEN WHEN ATTEMPTING TO LOOK UP CALENDAR") return None if data is None: data = Calendar().to_ical() result = self.DB_BRIDGE.getCalendarFromOwnerId(ownerId) if result is None: result = DBCalendarData() result.setCalendarData(ownerId, ownerType, permissions, data) result.saveToDB() return result
def addTagKey(self, tag, key=None, name=None, delaySave=False): if not delaySave: self.reload() key = self.resolveRef(key, name) try: tag = str(tag) except Exception: logWarning("ERROR: Invalid tag couldn't convert from unicode") tag = None if key is not None and isinstance(tag, str) and not self.hasTagKey(tag, key): if self.hasTag(tag): self.tag_maps[tag].append(key) else: self.tag_maps[tag] = [key] if not delaySave: self.save() self.reload()
def dispatchMessage(self, msg, senderId=None): """ Send a message from a child node to parent and sibling nodes """ self.addContextDataToMsg(msg) msg.setContextValue(ORIGINATING_SERVICE_ID_KEY, senderId) logWarning("Message DISPATCH") logWarning(msg) self.sendMessage(msg) logWarning("Message DISPATCH SENT: %s" % (msg, )) self._distributeMessage(self._nodes, msg, senderId) logWarning("Message DISTRIBUTED: %s" % (msg, ))
def addTagKey(self, tag, key=None, name=None, delaySave=False): if not delaySave: self.reload() key = self.resolveRef(key, name) try: tag = str(tag) except Exception: logWarning("ERROR: Invalid tag couldn't convert from unicode") tag = None if key is not None and isinstance( tag, str) and not self.hasTagKey(tag, key): if self.hasTag(tag): self.tag_maps[tag].append(key) else: self.tag_maps[tag] = [key] if not delaySave: self.save() self.reload()
def processQueuedMessages(self, wait=0.001): socketio = self._socketio msgKey = self.MESSAGES_KEY dataKey = self.DATA_KEY sessionKey = SESSION_KEY messagesNS = self.MESSAGES_NAMESPACE while True: time.sleep(wait) if not self._messages.empty(): sid, sessionId, msg = self.dequeueAJAXMessage() #if sessionId and len(self._socketio.server.rooms(sessionId)) > 0: if sessionId: self._socketio.emit(msgKey, { dataKey: msg, sessionKey: sessionId }, namespace=messagesNS, room=sessionId) else: logWarning("Could not find room %s (Message was: %s)" % (sessionId, msg))
def _createValue(self, key, value, name='', description='', tags=None, storageType=DATA_TYPE_DB, dataType=''): # Force Valid Default values if name is None: name = '' if description is None: description = '' if tags is None: tags = [] if dataType is None: dataType = '' if storageType is None: storageType = DATA_TYPE_DB # Must be a valid storage type if (key is not None and isinstance(key, basestring) and isinstance(storageType, int) and storageType in VALID_STORAGE_TYPES): storageData = { 'key': key, 'value': value, 'name': name, 'data_type': dataType, 'description': description } storageClass = self.STORAGE_ADAPTORS[storageType] data = storageClass(**storageData) if name != '': self.name_map[name] = key self.adaptor_map[key] = storageType for tag in tags: self.addTagKey(tag, key, delaySave=True) data.save() self.save() self.reload() return True else: logWarning("Couldn't create :" + str(key)) return False
def setValue( self, key=None, value=None, name=None, description=None, tags=None, storageType=None, dataType=None, allowOverwrite=False, allowCreate=True, ): self.reload() logWarning("SETTING VALUE") hasKey = self.hasKey(key) hasName = self.hasName(name) ref = self.resolveRef(key, name) # Make sure reference is valid, if any given if (ref is None) and ((hasKey and hasName) or (hasName and key is not None)): logWarning("INVALID: Mismatched unique keys in set value: (key=%s, name=%s)" % (key, name)) return False # Overwrite existing data # This is aborted if another entry uses has the new 'name' elif (ref is not None) and allowOverwrite: return self._updateValue(key, value, name, description, tags, storageType, dataType) # Create a new entry # The key must not already exist and a non-None value must be given elif (ref is None) and allowCreate: return self._createValue(key, value, name, description, tags, storageType, dataType) else: logWarning("INVALID CONDITION") return False
def setValue(self, key=None, value=None, name=None, description=None, tags=None, storageType=None, dataType=None, allowOverwrite=False, allowCreate=True): self.reload() logWarning("SETTING VALUE") hasKey = self.hasKey(key) hasName = self.hasName(name) ref = self.resolveRef(key, name) # Make sure reference is valid, if any given if (ref is None) and ((hasKey and hasName) or (hasName and key is not None)): logWarning( "INVALID: Mismatched unique keys in set value: (key=%s, name=%s)" % (key, name)) return False # Overwrite existing data # This is aborted if another entry uses has the new 'name' elif (ref is not None) and allowOverwrite: return self._updateValue(key, value, name, description, tags, storageType, dataType) # Create a new entry # The key must not already exist and a non-None value must be given elif (ref is None) and allowCreate: return self._createValue(key, value, name, description, tags, storageType, dataType) else: logWarning('INVALID CONDITION') return False
def findAssignmentNumber(self, task, sessions): possibleTaskNumber = -1 for session in sessions: #sessionTask = session.getTask() #logInfo("task id is {0}, and session id is {1}".format(task._taskId, session.task), 1) if task._taskId == session.task: logInfo("found session with previous task", 1) if session.assignmentNumber is not None: logInfo( "session.assignmentNumber = {0}".format( session.assignmentNumber), 5) try: possibleTaskNumber = int(session.assignmentNumber) except: logWarning( "Failed to Find session.assignmentNumber for | {0}" .format(session.task)) possibleTaskNumber = 0 else: possibleTaskNumber = 0 return possibleTaskNumber + 1
def receiveMessage(self, msg): """ Get message from a child and process/distribute it """ super(HTTPMessagingGateway, self).receiveMessage(msg) logWarning("Message Received") self.queueAJAXMessage(msg) logWarning("Message Distributing %s" % msg.getId()) self.distributeMessage(msg) logWarning("Message Distributed %s" % msg.getId())
def getCalendarFromOwnerId(self, ownerId=None, useCache=True): if ownerId is None: logWarning("NO OWNER ID WAS GIVEN WHEN ATTEMPTING TO LOOK UP CALENDAR") return None if useCache: result = self.calendarCache.get(ownerId, None) if result is not None: return result; foundCalendars = DBCalendarData.find_by_index("ownerIdIndex", []) calendarData = None if len(foundCalendars) == 0: logInfo("No calendar found, creating a new calendar for owner:{0}".format(ownerId), 1) calendarData = DBCalendarData() calendarData.setCalendarData(ownerId) elif len(foundCalendars) == 1: calendarData = foundCalendars[0] elif len(foundCalendars) > 1: logWarning("{0} owns more than a single calendar. Database may be corrupted. Defaulting to the first value".format(ownerId)) calendarData = foundCalendars[0] self.calendarCache[ownerId] = calendarData return calendarData
def staticImports(path): if path[-3:] not in ('.git'): try: return BASIC_BLUEPRINT.send_static_file(path) except Exception as e: logWarning('exception=') logWarning(e) logWarning(path) abort(404) else: return abort(404)
def cssImports(path): if path[-3:] == '.css': try: return BASIC_BLUEPRINT.send_static_file(path) except Exception as e: logWarning('exception=') logWarning(e) logWarning(path) abort(404) else: return abort(404)
def before_first(): logWarning('Handling database init') if application.debug: # Debug/local dev logWarning('Debug Mode: MongoDB') default_database(Database( 'mongodb', mongo_url='mongodb://localhost:27017/TestDB')) else: # Production! logWarning('Production Mode: DynamoDB') default_database(Database('dynamodb')) set_db_application_prefix(APPLICATION_NAME) # Make sure we have our tables #IncomingMessage.ensure_table() initDerivedDataTables()
def before_first(): logWarning('Handling database init') if application.debug: # Debug/local dev logWarning('Debug Mode: MongoDB') default_database(Database( 'mongodb', mongo_url='mongodb://localhost:27017/TestDB')) else: # Production! logWarning('Production Mode: MongoDB') default_database(Database( 'mongodb', mongo_url='mongodb://localhost:27017/TestDB')) set_db_application_prefix(APPLICATION_NAME) # Make sure we have our tables #IncomingMessage.ensure_table() initDerivedDataTables()
def StartServer(app=None, socketio=None, host=None, port=DEFAULT_PORT, debug=True): if socketio is None: socketio = SOCKET_IO_CORE if host is None: if debug: host = '0.0.0.0' else: host = '127.0.0.1' Thread(target=background_thread).start() logWarning("Starting Socket App1") try: logWarning(host) logWarning(port) socketio.run(app, host=host, port=port) except Exception as err: logError("Error: Could not start socketio.") DB_CONNECTION.close()
def processStorageInform(self, bucket, verb, key=None, value=None, tags=None, aType=None, allowCreate=None, name=None, description=None, dataType=None): if verb == self.VALUE_VERB: logWarning("IS SETTING", value) if isinstance(value, Serializable): logWarning("IS SERIALIZABLE") if key is None: key = value.getId() elif key != value.getId(): logWarning('BAD KEY for Storage (%s != %s)'%(key, value.getId())) return False if isinstance(value, NamedSerializable): if name is None: name = value.getName() elif name != value.getName(): logWarning('BAD NAME for Storage(%s != %s)'%(name, value.getName())) return False #NOTE we are assuming that the value class and dbValue class have the toDB and saveToDB functions respectively. #If they do not have them they must be implemented or the system will not save the data. try: if isinstance(value, list): for valueObject in value: logInfo("saving task {0} to database".format(valueObject._name), 4) dbValue = DBSerializable.convert(valueObject) dbValue.saveToDB() except NotImplementedError: logInfo('failed to serialize object', 1) dbValue = JSONtoDBSerializable(value) dbValue.saveToDB() return True #GLUDB does not currently allow for deletion of items so this should always return false elif verb == self.VOID_VERB: return False
def receiveMessage(self, msg): logWarning("TEST SERVICE GOT: \n", self.messageToString(msg)) default = "{{missing}}" authKey = msg.getContextValue(Message.AUTHENTICATION_KEY, default) logWarning(" ===> authN:[%s], authZ:[%s], ShouldBeBlank:[%s] <=== " % ( authKey, msg.getContextValue(Message.AUTHORIZATION_KEY, default), msg.getContextValue('BE-BLANK', default), )) if authKey: try: from AWS_Core_Services.Authentication.UserData import UserData user = UserData.read(authKey) if user: logWarning("USER IN MESSAGE: %s" % str(user)) else: logWarning("USER IN MESSAGE: {{{NONE}}}") except: pass super(TestService, self).receiveMessage(msg)
def receiveMessage(self, msg): # TODO: Restore bucket management #if ((msg.getActor() == STORAGE_SERVICE_NAME) and # (msg.getContextValue(self.BUCKET_KEY, None) is not None) and # (self.hasBucket(msg.getContextValue(self.BUCKET_KEY)))): print("STORAGE RECEIVED MESSAGE: %s" % (msg, )) if (msg.getActor() == STORAGE_SERVICE_NAME): bucket = self.getBucket(msg.getContextValue(self.BUCKET_KEY)) # Inform: Set some value(s) if (msg.getSpeechAct() == INFORM_ACT): try: logWarning("INFORMING") value = self.processStorageInform( bucket, msg.getVerb(), msg.getObject(), msg.getResult(), msg.getContextValue(self.TAGS_KEY, None), msg.getContextValue(self.TYPE_KEY, None), msg.getContextValue(self.ALLOW_CREATE_KEY, True), msg.getContextValue(self.NAME_KEY, None), msg.getContextValue(self.DESCRIPTION_KEY, None), msg.getContextValue(self.DATA_TYPE_KEY, None)) if (value == True): response = self.makeConfirmMessage(msg) else: response = self.makeDisconfirmMessage(msg) except Exception: self.sendMessage(self.makeDisconfirmMessage(msg)) raise self.sendMessage(response) # Request: get some value(s) elif (msg.getSpeechAct() == REQUEST_ACT): try: value = self.processStorageRequest( bucket, msg.getVerb(), msg.getObject(), msg.getContextValue(self.TAGS_KEY, None), msg.getContextValue(self.TYPE_KEY, None), msg.getContextValue(self.NAME_KEY, None)) if msg.getVerb() == self.CONTAINS_VERB: response = self.makeReplyToContainsMessage( msg, value[0], value[1]) elif msg.getVerb() != INFORM_REF_ACT or value is None: response = self.makeRequestAnswerMessage(msg, value) else: response = self.makeReplyToInformRefMessage( msg, value[0], value[1]) except Exception: self.sendMessage(self.makeDisconfirmMessage(msg)) raise self.sendMessage(response) # Inform about the name of a value (rename) elif (msg.getSpeechAct() == INFORM_REF_ACT): try: value = self.processStorageRename( bucket, msg.getVerb(), msg.getObject(), msg.getResult(), msg.getContextValue(self.NAME_KEY, None)) if (value == True): response = self.makeConfirmMessage(msg) else: response = self.makeDisconfirmMessage(msg) except Exception: self.sendMessage(self.makeDisconfirmMessage(msg)) raise self.sendMessage(response) else: logWarning("COULD NOT PROCESS (%s): %s" % (self.getId(), serializeObject(msg)))
def onDisconnect(): logWarning('Client disconnected')
def sendTestString(self, aStr): logWarning("Test Service is Sending: ", aStr) self.sendMessage(Message("TestService", "Sent Test", "To Server", aStr))
def onConnect(): logWarning("Connected")
def onConnect(): logWarning("Connected") #flask.ext.socketio.emit('my response', {'data': 'Connected', 'count': 0}) @SOCKET_IO_CORE.on('disconnect', namespace='/messaging') def onDisconnect(): logWarning('Client disconnected') #First check to see if HOST and PORT were specified in the #environment - if so, we use those values directly and skip #the "usual" logic below envHost, envPort = None, None try: envHost = os.getenv('HOST', None) envPort = int(os.getenv('PORT', 0)) except: pass if envHost and envPort: logWarning("Using Host/Port from environment: %s:%d" % (envHost, envPort)) StartServer(FLASK_CORE_APP, SOCKET_IO_CORE, envHost, envPort, DEBUG_MODE) elif DEBUG_MODE: StartDebugServer(FLASK_CORE_APP, SOCKET_IO_CORE) elif DEBUG_ON_VM: StartVMDebugServer(FLASK_CORE_APP, SOCKET_IO_CORE) elif False: StartDirectServer(FLASK_CORE_APP, SOCKET_IO_CORE) else: StartProductionServer(FLASK_CORE_APP, SOCKET_IO_CORE)
def logOnly(self, strg, loc, toks): logWarning("LOG: ", toks)
self.name_map[name] = key self._changeName(name, data) self.save() return StorageObject.objects, self.adaptor_map, self.name_map if __name__ == "__main__": # Backup to files if False: outDataFile = "StorageServiceBackup.log" conn = connect("StorageService_DB") try: storageService = MongoStorageService(conn) outData = storageService.exportBucket("ONR") except Exception, exc: logWarning(exc) finally: conn.close() outStr = serializeObject(outData) with open(outDataFile, "wb") as aFile: aFile.write(outStr) if False: conn = connect("StorageService_DB") try: storageService = MongoStorageService(conn) bucket = storageService.getBucket("ONR") bucket.resolveInconsistencies() # except Exception as exc: # logWarning("EXCEPT: ", exc) finally: conn.close()
def receiveMessage(self, msg): if ( (msg.getActor() == STORAGE_SERVICE_NAME) and (msg.getContextValue(self.BUCKET_KEY, None) is not None) and (self.hasBucket(msg.getContextValue(self.BUCKET_KEY))) ): bucket = self.getBucket(msg.getContextValue(self.BUCKET_KEY)) # Inform: Set some value(s) if msg.getSpeechAct() == INFORM_ACT: try: logWarning("INFORMING") value = self.processStorageInform( bucket, msg.getVerb(), msg.getObject(), msg.getResult(), msg.getContextValue(self.TAGS_KEY, None), msg.getContextValue(self.TYPE_KEY, None), msg.getContextValue(self.ALLOW_CREATE_KEY, True), msg.getContextValue(self.NAME_KEY, None), msg.getContextValue(self.DESCRIPTION_KEY, None), msg.getContextValue(self.DATA_TYPE_KEY, None), ) if value == True: response = self.makeConfirmMessage(msg) else: response = self.makeDisconfirmMessage(msg) except Exception: self.sendMessage(self.makeDisconfirmMessage(msg)) raise self.sendMessage(response) # Request: get some value(s) elif msg.getSpeechAct() == REQUEST_ACT: try: value = self.processStorageRequest( bucket, msg.getVerb(), msg.getObject(), msg.getContextValue(self.TAGS_KEY, None), msg.getContextValue(self.TYPE_KEY, None), msg.getContextValue(self.NAME_KEY, None), ) if msg.getVerb() == self.CONTAINS_VERB: response = self.makeReplyToContainsMessage(msg, value[0], value[1]) elif msg.getVerb() != INFORM_REF_ACT or value is None: response = self.makeRequestAnswerMessage(msg, value) else: response = self.makeReplyToInformRefMessage(msg, value[0], value[1]) except Exception: self.sendMessage(self.makeDisconfirmMessage(msg)) raise self.sendMessage(response) # Inform about the name of a value (rename) elif msg.getSpeechAct() == INFORM_REF_ACT: try: value = self.processStorageRename( bucket, msg.getVerb(), msg.getObject(), msg.getResult(), msg.getContextValue(self.NAME_KEY, None), ) if value == True: response = self.makeConfirmMessage(msg) else: response = self.makeDisconfirmMessage(msg) except Exception: self.sendMessage(self.makeDisconfirmMessage(msg)) raise self.sendMessage(response) else: logWarning("COULD NOT PROCESS (%s): %s" % (self.getId(), serializeObject(msg)))
def delBucket(self, name): if name is not None: buckets = Bucket.objects(bucket_name=name) buckets.delete() else: logWarning("Could not remove missing bucket: %s"(name))
def _renameBucket(self, oldName, newName): bucket = self.getBucket(oldName) if bucket: bucket.setBucketName(newName) else: logWarning("Could not rename missing bucket: %s"(oldName))
if application.config.get('DEBUG', None): # Debug mode - running on a workstation application.debug = True logging.basicConfig(level=logging.DEBUG) else: # We are running on AWS Elastic Beanstalk (or something like it) application.debug = False # See .ebextensions/01logging.config logging.basicConfig( filename='log/Re.log', level=logging.INFO ) APPLICATION_NAME = application.config.get('APPLICATION_NAME', 'noName') logWarning('Application debug is %s'%(application.debug,)) # Register our blueprints application.register_blueprint(BASIC_BLUEPRINT) # Start up the messaging system SOCKET_IO_CORE = flask_socketio.SocketIO(application) #Allow some env specification of helpful test services services = [DBLoggingService(), StudentModelMessaging(), GLUDBStorageService(), CSVReader(), RecommenderMessaging(), ICalReader()] MESSAGING_GATEWAY = HTTPMessagingGateway( None, SOCKET_IO_CORE, flask_socketio,
if application.config.get('DEBUG', None): # Debug mode - running on a workstation application.debug = True logging.basicConfig(level=logging.DEBUG) else: # We are running on AWS Elastic Beanstalk (or something like it) application.debug = False # See .ebextensions/01logging.config logging.basicConfig( filename='log/Re.log', level=logging.INFO ) APPLICATION_NAME = application.config.get('APPLICATION_NAME', 'noName') logWarning('Application debug is %s'%(application.debug,)) # Register our blueprints application.register_blueprint(BASIC_BLUEPRINT) # Start up the messaging system SOCKET_IO_CORE = flask.ext.socketio.SocketIO(application) #Allow some env specification of helpful test services services = [DBLoggingService(), StudentModelMessaging(), GLUDBStorageService(), CSVReader(), RecommenderMessaging(), ICalReader()] MESSAGING_GATEWAY = HTTPMessagingGateway( None, SOCKET_IO_CORE, flask.ext.socketio,
def delBucket(self, name): if name is not None: buckets = Bucket.objects(bucket_name=name) buckets.delete() else: logWarning("Could not remove missing bucket: %s" (name, ))