Пример #1
0
class Database:
    # TODO: sanitise dbfilename
    def __init__(self, dbfilename):
        try:
            self.name = dbfilename
            self.dbsemaphore = QSemaphore(1)  # to control concurrent write access to db
            metadata.bind = "sqlite:///" + dbfilename
            # 		metadata.bind.echo = True									# uncomment to see detailed database logs
            setup_all()
            create_all()
        except:
            print "[-] Could not create database. Please try again."

    def openDB(self, dbfilename):
        try:
            self.name = dbfilename
            metadata.bind = "sqlite:///" + dbfilename
            # 		metadata.bind.echo = True									# uncomment to see detailed database logs
            setup_all()
        except:
            print "[-] Could not open database file. Is the file corrupted?"

            # this function commits any modified data to the db, ensuring no concurrent write access to the DB (within the same thread)
            # if you code a thread that writes to the DB, make sure you acquire/release at the beginning/end of the thread (see nmap importer)

    def commit(self):
        self.dbsemaphore.acquire()
        session.commit()
        self.dbsemaphore.release()
Пример #2
0
class Database:
    # TODO: sanitise dbfilename
    def __init__(self, dbfilename):
        try:
            self.name = dbfilename
            self.dbsemaphore = QSemaphore(
                1)  # to control concurrent write access to db
            metadata.bind = 'sqlite:///' + dbfilename
            #		metadata.bind.echo = True									# uncomment to see detailed database logs
            setup_all()
            create_all()
        except:
            print '[-] Could not create database. Please try again.'

    def openDB(self, dbfilename):
        try:
            self.name = dbfilename
            metadata.bind = 'sqlite:///' + dbfilename
            #		metadata.bind.echo = True									# uncomment to see detailed database logs
            setup_all()
        except:
            print '[-] Could not open database file. Is the file corrupted?'

    # this function commits any modified data to the db, ensuring no concurrent write access to the DB (within the same thread)
    # if you code a thread that writes to the DB, make sure you acquire/release at the beginning/end of the thread (see nmap importer)
    def commit(self):
        self.dbsemaphore.acquire()
        session.commit()
        self.dbsemaphore.release()
Пример #3
0
 def __init__(self, dbfilename):
     try:
         self.name = dbfilename
         self.dbsemaphore = QSemaphore(
             1)  # to control concurrent write access to db
         metadata.bind = 'sqlite:///' + dbfilename
         #		metadata.bind.echo = True									# uncomment to see detailed database logs
         setup_all()
         create_all()
     except:
         print '[-] Could not create database. Please try again.'
Пример #4
0
 def delay_method_call(self, *args, **kwargs):
     if self.thread() != QThread.currentThread():
         semaphore = QSemaphore()
     else:
         semaphore = None
     event = QueuedCallEvent(method, (self,) + args, kwargs, semaphore)
     QCoreApplication.postEvent(self, event)
     if semaphore is None:
         QCoreApplication.sendPostedEvents()
     else:
         # Wait until the other thread's event loop processes the event
         semaphore.acquire()
     return event.result()
Пример #5
0
 def delay_method_call(self, *args, **kwargs):
     if self.thread() != QThread.currentThread():
         semaphore = QSemaphore()
     else:
         semaphore = None
     event = QueuedCallEvent(method, (self, ) + args, kwargs, semaphore)
     QCoreApplication.postEvent(self, event)
     if semaphore is None:
         QCoreApplication.sendPostedEvents()
     else:
         # Wait until the other thread's event loop processes the event
         semaphore.acquire()
     return event.result()
Пример #6
0
    def __init__(self, pdbConnector):
        QThread.__init__(self)

        self.resultRecordQueue = deque()
        self.resultRecordMutex = QMutex()
        self.resultRecordSem = QSemaphore(0)

        self.resultConsoleQueue = deque()
        self.resultConsoleMutex = QMutex()
        self.resultConsoleSem = QSemaphore(0)

        self.parser = PdbParser(pdbConnector, self)
        self.pdbConnector = pdbConnector
Пример #7
0
 def __init__(self, *args):
   QThread.__init__(self)
   self.typeQueue = Queue()
   self.regImage = re.compile("(JPEG|JPG|jpg|jpeg|GIF|gif|bmp|BMP|png|PNG|pbm|PBM|pgm|PGM|ppm|PPM|xpm|XPM|xbm|XBM|TIFF|tiff).*", re.IGNORECASE)
   self.typeQueue = []
   self.setUniq = set()
   self.qmutex = QMutex()
   self.qsem = QSemaphore()
Пример #8
0
 def __init__(self, engines, finished):
     super(Collect, self).__init__()
     self.engines = engines
     self.semaphore = QSemaphore()
     self.queue = Queue()
     self.finished = finished
     for engine in engines:
         engine.query_finished.connect(self.handle_query_finished)
Пример #9
0
 def __init__(self, dbfilename):
     try:
         self.name = dbfilename
         self.dbsemaphore = QSemaphore(1)  # to control concurrent write access to db
         metadata.bind = "sqlite:///" + dbfilename
         # 		metadata.bind.echo = True									# uncomment to see detailed database logs
         setup_all()
         create_all()
     except:
         print "[-] Could not create database. Please try again."
Пример #10
0
class Collect(QRunnable):
    """Collect results from engines and emit signal."""

    def __init__(self, engines, finished):
        super(Collect, self).__init__()
        self.engines = engines
        self.semaphore = QSemaphore()
        self.queue = Queue()
        self.finished = finished
        for engine in engines:
            engine.query_finished.connect(self.handle_query_finished)

    def run(self):
        for i in range(len(self.engines)):
            self.semaphore.acquire()
        self.finished(dump_queue(self.queue))

    @pyqtSlot(object)
    def handle_query_finished(self, response):
        self.queue.put(response)
        self.semaphore.release()
Пример #11
0
class TypeWorker(QThread):
  def __init__(self, *args):
    QThread.__init__(self)
    self.typeQueue = Queue()
    self.regImage = re.compile("(JPEG|JPG|jpg|jpeg|GIF|gif|bmp|BMP|png|PNG|pbm|PBM|pgm|PGM|ppm|PPM|xpm|XPM|xbm|XBM|TIFF|tiff).*", re.IGNORECASE)
    self.typeQueue = []
    self.setUniq = set()
    self.qmutex = QMutex()
    self.qsem = QSemaphore()

  def enqueue(self, parent, index, node):
    self.qmutex.lock()
    if long(node.this) not in self.setUniq:
       self.typeQueue.insert(0, (parent, index, node))
       self.setUniq.add(long(node.this))
       self.qsem.release()
    self.qmutex.unlock()

  def clear(self):
    self.qmutex.lock()
    self.typeQueue = []
    self.setUniq.clear()
    self.qsem.acquire(self.qsem.available())
    self.qmutex.unlock()

  def get(self):
    self.qsem.acquire()
    self.qmutex.lock()
    res = self.typeQueue.pop()
    self.setUniq.remove(long(res[2].this))
    self.qmutex.unlock()
    return res

  def isImage(self, ftype):
    res = self.regImage.search(ftype)
    return res

  def run(self):
     count = 0
     while True:
       (parent, index, node) = self.get()
       if node.size():
         ftype = str(node.dataType())
         if parent.imagesthumbnails and self.isImage(ftype):
           thumb = ImageThumb()
           img = thumb.getImage(ftype, node, index)
           if img:
             parent.emit(SIGNAL('dataImage'), index, node, img)
Пример #12
0
    def __init__(self, connector, parent=None):
        QThread.__init__(self, parent)

        self.resultRecordQueue = deque()
        self.resultRecordMutex = QMutex()
        self.resultRecordSem = QSemaphore(0)
Пример #13
0
	def __init__(self,n=0):
		QSemaphore.__init__(self,n)