def p_BinaryArithExpr(self, p): '''BinaryArithExpr : AnnidateArithExpr PLUS AnnidateArithExpr | AnnidateArithExpr MINUS AnnidateArithExpr | AnnidateArithExpr MUL AnnidateArithExpr | AnnidateArithExpr DIVIDE AnnidateArithExpr | MINUS AnnidateArithExpr ''' if len(p) > 3: oper = Operation(p[1].value, str(p[2]), p[3].value) node = self.manager.createNode(oper, [p[1], p[3]]) p[0] = node else: tmpNode = self.manager.createNode(Number("0"), []) oper = Operation(tmpNode.value, str(p[1]), p[2].value) p[0] = self.manager.createNode(oper, [tmpNode, p[2]]) self.myPrint("BinaryArithExpr", p)
def get_operation(self, name): """ :param name: string :rtype: Operation """ if not self.definitions_database.exists_operation(name): raise ValueError("'{0}' is not a defined Operation.".format(name)) extractor_name, inspector_name, param_values = self.definitions_database.get_operation_exec_info( name) try: extractor = self.repositories_manager.get_extractor_instance( extractor_name) except (ImportError, AttributeError, TypeError): raise RuntimeError( 'Could not instantiate the operation\'s extractor class') try: inspector = self.repositories_manager.get_inspector_instance( inspector_name) except (ImportError, AttributeError, TypeError): raise RuntimeError( 'Could not instantiate the operation\'s inspector class') return Operation(extractor, inspector, param_values)
def p_AnnidateArithExpr(self, p): '''AnnidateArithExpr : LPAREN AnnidateArithExpr PLUS AnnidateArithExpr RPAREN | LPAREN AnnidateArithExpr MINUS AnnidateArithExpr RPAREN | LPAREN AnnidateArithExpr MUL AnnidateArithExpr RPAREN | LPAREN AnnidateArithExpr DIVIDE AnnidateArithExpr RPAREN | LPAREN MINUS AnnidateArithExpr RPAREN ''' if len(p) > 5: oper = Operation(p[2].value, str(p[3]), p[4].value) node = self.manager.createNode(oper, [p[2], p[4]]) p[0] = node else: tmpNode = self.manager.createNode(Number("0"), []) oper = Operation(tmpNode.value, str(p[2]), p[3].value) p[0] = self.manager.createNode(oper, [tmpNode, p[3]]) self.myPrint("AnnidateArithExpr", p)
def p_AnnidateArithExprNegativeSpecial(self, p): '''AnnidateArithExpr : LPAREN AnnidateArithExpr NEGNUMBER RPAREN ''' negative_string = str(p[3]) positive_string = remove_starting_minus_from_string(negative_string) tmpNode = self.manager.createNode(Number(positive_string), []) oper = Operation(p[2].value, "-", tmpNode.value) p[0] = self.manager.createNode(oper, [p[2], tmpNode]) self.myPrint("AnnidateArithExprNegativeSpecial", p)
def test_operation(self): op = Operation(self.extractor, self.inspector, self.param_values) op.execute(self.device_info, self.data_dir_path, simple_output=True) self.assertTrue( os.path.exists( os.path.join(self.data_dir_path, EXTRACTED_DATA_DIR_NAME))) self.assertTrue( os.path.exists( os.path.join(self.data_dir_path, INSPECTED_DATA_FILE_NAME))) self.assertTrue( os.path.exists( os.path.join(self.data_dir_path, SOURCE_DATA_FILE_NAME)))
def create_operation(self, operation: dict) -> (int, str): try: if not self._validate_user_id(user_id=operation['user_id']): logging.error( Error.ERROR_OPERATION_USER_NOT_EXISTS.format( operation['user_id'])) return 409, Error.ERROR_OPERATION_USER_NOT_EXISTS.format( operation['user_id']) operation = Operation(**operation) operation.idx = sequence_dao.increment_and_get_sequence( SEQUENCE_COLLECTION_OPERATION) operation.status = Status.CREATED.value operation.created_timestamp = str(datetime.now()) operation_dao.create(obj=operation) logging.info(Message.OPERATION_CREATED.format(operation.idx)) return 200, Message.OPERATION_CREATED.format(operation.idx) except Exception as e: logging.error(Error.ERROR_OPERATION_CREATE.format(str(e))) return 500, Error.ERROR_OPERATION_CREATE.format(str(e))
def update_operation_status(self, operation_id: int, operation_status: str) -> str: try: logging.info( "------------- update operation status executed -----------") status, operation = self._validate_operation_id( operation_id=operation_id) if not status: logging.error( Error.ERROR_OPERATION_NOT_EXISTS.format(operation_id)) return Error.ERROR_OPERATION_NOT_EXISTS.format(operation_id) operation = Operation(**operation) operation.status = operation_status operation.updated_timestamp = str(datetime.now()) operation_dao.update(obj=operation) logging.info(Message.OPERATION_UPDATED.format(operation.idx)) return Message.OPERATION_UPDATED.format(operation.idx) except Exception as e: logging.error(Error.ERROR_OPERATION_UPDATE.format(str(e))) return Error.ERROR_OPERATION_UPDATE.format(str(e))