def run(self): L.d("running") self.stopvar = False rex = re.compile(".*\[(\d{7})\]$") imdb_db = imdb.IMDb() db = get_user_db() tp = QThreadPool.globalInstance() writer = IndexWriter() count = 0 it = QDirIterator(self.media_path, QDirIterator.Subdirectories) while it.hasNext(): dir = it.next() try: directory = unicode(dir) match = rex.match(directory) if match: count += 1 imdb_id = match.group(1) movie = db.get_doc(imdb_id) if movie: L.d("%s already in db - skipping" % imdb_id) else: j = Job(imdb_db, imdb_id, self) j.obj.finished.connect(writer.index_movie, Qt.QueuedConnection) tp.start(j) except: pass print count self.exec_()
def sync(self): self.index_thread = IndexThread(MOVIE_DIR) print self.index_thread.finished.connect(self._indexer_closed) print self.shutmedown.connect(self.index_thread.set_stopped, Qt.QueuedConnection) self.index_thread.start() L.d("syncer started")
def really_close(self): #L.d("stopping indexer thread") #self.index_thread.quit() #L.d("waiting for threadpool to be done...") #from PySide.QtCore import QThreadPool #tp = QThreadPool.globalInstance() #tp.waitForDone() L.d("Threadpool done") self.close()
def run(self): if self.thread.stopvar: # threadpool already stopped - do nothing return L.d("fetching %s ..." % self.imdb_id) movie = self.imdb_db.get_movie(self.imdb_id) nm = normalize(movie) nm['_id'] = str(self.imdb_id) self.obj.finished.emit(nm)
def run(self): if self.thread.stopvar: # threadpool already stopped - do nothing return L.d( "fetching %s ..." % self.imdb_id) movie = self.imdb_db.get_movie(self.imdb_id) nm = normalize(movie) nm['_id'] = str(self.imdb_id) self.obj.finished.emit(nm)
def closeEvent(self, event): L.d("shutdown requested") L.d("hiding window") self.setVisible(False) if self.index_thread and self.index_thread.isRunning(): event.ignore() L.d("setting quit") self._shutdown_requested = True self.index_thread.set_stopped() #self.shutmedown.emit() #QTimer.singleShot(10, self.really_close) else: L.d("goodby") event.accept()
def _indexer_closed(self): L.d("indexer finished") if self._shutdown_requested: self.close()
def index_movie(self, movie): self.index.index_movie(movie) self.db.create_doc(json.dumps(movie), doc_id=movie["_id"]) L.d("%s finished" % movie['title'])
def _shutdown(self): tp = QThreadPool.globalInstance() L.d("waiting for threadpool to be done...") tp.waitForDone() self.quit()
def set_stopped(self): L.d("setting stopvar") self.stopvar = True QTimer.singleShot(10, self._shutdown)