def generateNotes(self): """Generate new notes""" state = "default" self.uniq_id = str(uuid.uuid4()).replace("-","") self.occl_id = '%s-%s' % (self.uniq_id, self.occl_tp) ( svg_node, layer_node ) = self._getMnodesAndSetIds() if not self.mnode_ids: tooltip("No cards to generate.<br>\ Are you sure you set your masks correctly?") return False self.new_svg = svg_node.toxml() # write changes to svg omask_path = self._saveMask(self.new_svg, self.occl_id, "O") qmasks = self._generateMaskSVGsFor("Q") amasks = self._generateMaskSVGsFor("A") image_path = mw.col.media.addFile(self.image_path) img = fname2img(image_path) mw.checkpoint("Adding Image Occlusion Cards") for nr, idx in enumerate(self.mnode_indexes): note_id = self.mnode_ids[idx] self._saveMaskAndReturnNote(omask_path, qmasks[nr], amasks[nr], img, note_id) tooltip("%s %s <b>added</b>" % self._cardS(len(qmasks)), parent=None) return state
def getSentimentKafka(event, context): text = event['data'] sentimentList ="" blob = TextBlob(text) if blob.sentiment.polarity > 0: sentimentList = "Positive" elif blob.sentiment.polarity < 0: sentimentList ="Negative" else: sentimentList = "Neutral" producer = KafkaProducer( bootstrap_servers=['localhost:30092'], value_serializer=lambda x: dumps(x).encode('utf-8')) messageId = uuid.uuid4() data = {'id': messageId, 'sentiment': sentimentList} producer.send('test', value=data) sleep(5) consumer = KafkaConsumer( 'test', bootstrap_servers=['localhost:30092'], auto_offset_reset='earliest', value_deserializer=lambda x: loads(x.decode('utf-8'))) for message in consumer: message = message.value print('{} message was read!'.format(message)) return sentimentList
def _pull(self, uri, enumCtx): """ Sent Pull request and return replay file handler """ return self._wsman_request(XML_REQ%(ENUM_ACTION_PULL, self._url, uri, uuid.uuid4(), PULL_TMPL%enumCtx), ENUM_ACTION_PULL)
def _pull(self, uri, enumCtx): """ Sent Pull request and return replay file handler """ return self._wsman_request( XML_REQ % (ENUM_ACTION_PULL, self._url, uri, uuid.uuid4(), PULL_TMPL % enumCtx), ENUM_ACTION_PULL)
def _getClass(self, classname): """ Sent Intrinsic GetClass request and return replay file handler """ return self._wsman_request(INTR_REQ%(classname, classname, self._url, classname, uuid.uuid4()), '/'.join((XML_NS_CIM_INTRINSIC, classname, 'GetClass')))
def _release(self, uri, enumCtx): """ Sent Release request and return replay file handler """ self._wsman_request(XML_REQ%(ENUM_ACTION_RELEASE, self._url, uri, uuid.uuid4(), RELEASE_TMPL%enumCtx), ENUM_ACTION_RELEASE).read() return
def _enumerate(self, uri, query): """ Sent Enumerate request and return replay file handler """ return self._wsman_request(XML_REQ%(ENUM_ACTION_ENUMERATE, self._url, uri, uuid.uuid4(), ENUM_TMPL%(self._fltr and self._fltr%query or '')), ENUM_ACTION_ENUMERATE)
def _release(self, uri, enumCtx): """ Sent Release request and return replay file handler """ self._wsman_request( XML_REQ % (ENUM_ACTION_RELEASE, self._url, uri, uuid.uuid4(), RELEASE_TMPL % enumCtx), ENUM_ACTION_RELEASE).read() return
def _getClass(self, classname): """ Sent Intrinsic GetClass request and return replay file handler """ return self._wsman_request( INTR_REQ % (classname, classname, self._url, classname, uuid.uuid4()), '/'.join((XML_NS_CIM_INTRINSIC, classname, 'GetClass')))
def _enumerate(self, uri, query): """ Sent Enumerate request and return replay file handler """ return self._wsman_request( XML_REQ % (ENUM_ACTION_ENUMERATE, self._url, uri, uuid.uuid4(), ENUM_TMPL % (self._fltr and self._fltr % query or '')), ENUM_ACTION_ENUMERATE)
def close(self): """ Closes the cursor. The cursor is unusable from this point. """ self.description = None if self._enumCtx: self._connection._wsman_request(XML_REQ%(ENUM_ACTION_RELEASE, self._url, self._uri, uuid.uuid4(), RELEASE_TMPL%self._enumCtx)) self._enumCtx = None del self._rows[:] self._parser = None self._selectors.clear()
def fetchone(self): """Fetches a single row from the cursor. None indicates that no more rows are available.""" self._check_executed() try: while not self._rows and self._enumCtx: self._connection._wsman_request(XML_REQ%(ENUM_ACTION_PULL, self._url, self._uri, uuid.uuid4(),PULL_TMPL%self._enumCtx),self._get_parser()) if not self._rows: return None self.rownumber += 1 return self._rows.pop(0) except OperationalError, e: raise OperationalError(e)
def close(self): """ Closes the cursor. The cursor is unusable from this point. """ self.description = None if self._enumCtx: self._connection._wsman_request( XML_REQ % (ENUM_ACTION_RELEASE, self._url, self._uri, uuid.uuid4(), RELEASE_TMPL % self._enumCtx)) self._enumCtx = None del self._rows[:] self._parser = None self._selectors.clear()
def fetchone(self): """Fetches a single row from the cursor. None indicates that no more rows are available.""" self._check_executed() try: while not self._rows and self._enumCtx: self._connection._wsman_request( XML_REQ % (ENUM_ACTION_PULL, self._url, self._uri, uuid.uuid4(), PULL_TMPL % self._enumCtx), self._get_parser()) if not self._rows: return None self.rownumber += 1 return self._rows.pop(0) except OperationalError, e: raise OperationalError(e)
def execute(self, operation, *args): """ Prepare and execute a database operation (query or command). Parameters may be provided as sequence or mapping and will be bound to variables in the operation. Parameter style for WSManDb is %-formatting, as in: cur.execute('select * from table where id=%d', id) cur.execute('select * from table where strname=%s', name) Please consult online documentation for more examples and guidelines. """ if not self._connection: raise ProgrammingError("Cursor closed.") if not self._connection._conkwargs: raise ProgrammingError("Connection closed.") self.description = None self.rownumber = -1 self._selectors.clear() good_sql = False if self._enumCtx: try: self._connection._wsman_request(XML_REQ%(ENUM_ACTION_RELEASE, self._url, self._uri, uuid.uuid4(), RELEASE_TMPL%self._enumCtx)) finally: self._enumCtx = None # for this method default value for params cannot be None, # because None is a valid value for format string. if (args != () and len(args) != 1): raise TypeError("execute takes 1 or 2 arguments (%d given)"%( len(args) + 1,)) if args != (): operation = operation%args[0] operation = operation.encode('unicode-escape') if operation.upper() == 'SELECT 1': self._connection._identify() self._rows.append((1L,)) self.description = (('1',CIM_UINT64,None,None,None,None,None),) self.rownumber = 0 return try: props, classname, where = WQLPAT.match(operation).groups('') except: raise ProgrammingError("Syntax error in the query statement.") if where: try: self._selectors.update( eval('(lambda **kws:kws)(%s)'%ANDPAT.sub(',', where)) ) if [v for v in self._selectors.values() if type(v) is list]: kbkeys = '' if props != '*': kbkeys = ',%s'%','.join(cursor._selectors.keys()) operation = 'SELECT %s%s FROM %s'%(props, kbkeys, classname) elif self._connection._fltr: self._selectors.clear() except: self._selectors.clear() if props == '*': self._props = [] else: self._props=[p for p in set(props.replace(' ','').split(','))] try: if not self._connection._wsm_vendor: self._connection._identify() if 'Microsoft' in self._connection._wsm_vendor: classname = '*' elif 'Openwsman' in self._connection._wsm_vendor: try: self._connection._wsman_request(INTR_REQ%(classname, classname, self._url, classname, uuid.uuid4()), self._get_parser(True)) except Exception: pass if not self._namespace.startswith('http'): self._uri = '/'.join(({ 'CIM': XML_NS_CIM_CLASS, 'OpenWBEM': XML_NS_OWBEM_CIM_CLASS, 'Linux': XML_NS_LINUX_CIM_CLASS, 'OMC': XML_NS_OMC_CIM_CLASS, 'PG': XML_NS_PG_CIM_CLASS, '*': '/'.join((XML_NS_WIN32_CIM_CLASS, self._namespace)), 'Win32': '/'.join((XML_NS_WIN32_CIM_CLASS,self._namespace)), }.get(classname.split('_', 1)[0], XML_NS_CIM_CLASS), classname)) else: self._uri = '/'.join((self._namespace, classname)) self._connection._wsman_request(XML_REQ%(ENUM_ACTION_ENUMERATE, self._url, self._uri, uuid.uuid4(), ENUM_TMPL%(self._fltr and self._fltr%operation or '')),self._get_parser()) if not self._enumCtx: return self._connection._wsman_request(XML_REQ%(ENUM_ACTION_PULL, self._url, self._uri, uuid.uuid4(), PULL_TMPL%self._enumCtx),self._get_parser()) if self.description: self.rownumber = 0 except InterfaceError, e: raise InterfaceError(e)
def execute(self, operation, *args): """ Prepare and execute a database operation (query or command). Parameters may be provided as sequence or mapping and will be bound to variables in the operation. Parameter style for WSManDb is %-formatting, as in: cur.execute('select * from table where id=%d', id) cur.execute('select * from table where strname=%s', name) Please consult online documentation for more examples and guidelines. """ if not self._connection: raise ProgrammingError("Cursor closed.") if not self._connection._conkwargs: raise ProgrammingError("Connection closed.") self.description = None self.rownumber = -1 self._selectors.clear() good_sql = False if self._enumCtx: try: self._connection._wsman_request( XML_REQ % (ENUM_ACTION_RELEASE, self._url, self._uri, uuid.uuid4(), RELEASE_TMPL % self._enumCtx)) finally: self._enumCtx = None # for this method default value for params cannot be None, # because None is a valid value for format string. if (args != () and len(args) != 1): raise TypeError("execute takes 1 or 2 arguments (%d given)" % (len(args) + 1, )) if args != (): operation = operation % args[0] operation = operation.encode('unicode-escape') if operation.upper() == 'SELECT 1': self._connection._identify() self._rows.append((1L, )) self.description = (('1', CIM_UINT64, None, None, None, None, None), ) self.rownumber = 0 return try: props, classname, where = WQLPAT.match(operation).groups('') except: raise ProgrammingError("Syntax error in the query statement.") if where: try: self._selectors.update( eval('(lambda **kws:kws)(%s)' % ANDPAT.sub(',', where))) if [v for v in self._selectors.values() if type(v) is list]: kbkeys = '' if props != '*': kbkeys = ',%s' % ','.join(cursor._selectors.keys()) operation = 'SELECT %s%s FROM %s' % (props, kbkeys, classname) elif self._connection._fltr: self._selectors.clear() except: self._selectors.clear() if props == '*': self._props = [] else: self._props = [p for p in set(props.replace(' ', '').split(','))] try: if not self._connection._wsm_vendor: self._connection._identify() if 'Microsoft' in self._connection._wsm_vendor: classname = '*' elif 'Openwsman' in self._connection._wsm_vendor: try: self._connection._wsman_request( INTR_REQ % (classname, classname, self._url, classname, uuid.uuid4()), self._get_parser(True)) except Exception: pass if not self._namespace.startswith('http'): self._uri = '/'.join(({ 'CIM': XML_NS_CIM_CLASS, 'OpenWBEM': XML_NS_OWBEM_CIM_CLASS, 'Linux': XML_NS_LINUX_CIM_CLASS, 'OMC': XML_NS_OMC_CIM_CLASS, 'PG': XML_NS_PG_CIM_CLASS, '*': '/'.join((XML_NS_WIN32_CIM_CLASS, self._namespace)), 'Win32': '/'.join((XML_NS_WIN32_CIM_CLASS, self._namespace)), }.get(classname.split('_', 1)[0], XML_NS_CIM_CLASS), classname)) else: self._uri = '/'.join((self._namespace, classname)) self._connection._wsman_request( XML_REQ % (ENUM_ACTION_ENUMERATE, self._url, self._uri, uuid.uuid4(), ENUM_TMPL % (self._fltr and self._fltr % operation or '')), self._get_parser()) if not self._enumCtx: return self._connection._wsman_request( XML_REQ % (ENUM_ACTION_PULL, self._url, self._uri, uuid.uuid4(), PULL_TMPL % self._enumCtx), self._get_parser()) if self.description: self.rownumber = 0 except InterfaceError, e: raise InterfaceError(e)