class CheckThread(QtCore.QThread): def __init__(self, model, flickr, directory, parent=None): super(CheckThread, self).__init__(parent) logger.info("init check thread") self.model = model self.flickr = flickr self.directory = directory self.photos = [] self.upload_thread = None def run(self): temp = '' SUPPORT_FORMATS = getattr(settings, 'SUPPORT_FORMATS') if os.path.isdir(self.directory): for root, dirs, files in os.walk(self.directory): #logger.info(dirs) for filename in files: name, ext = os.path.splitext(filename) if ext.lower() in SUPPORT_FORMATS: filepath = os.path.join(root, filename) if not Utils.checkDB(filepath): if root != self.directory: temp = os.path.basename(root) self.photos.append([temp, filepath]) else: self.photos.append(["", filepath]) for photoset, photo in self.photos: self.upload_thread = UploadThread(self, self.flickr, photo, photoset) self.upload_thread.check() self.model.finishUploadThread()
def run(self): temp = '' SUPPORT_FORMATS = getattr(settings, 'SUPPORT_FORMATS') if os.path.isdir(self.directory): for root, dirs, files in os.walk(self.directory): #logger.info(dirs) for filename in files: name, ext = os.path.splitext(filename) if ext.lower() in SUPPORT_FORMATS: filepath = os.path.join(root, filename) if not Utils.checkDB(filepath): if root != self.directory: temp = os.path.basename(root) self.photos.append([temp, filepath]) else: self.photos.append(["", filepath]) for photoset, photo in self.photos: self.upload_thread = UploadThread(self, self.flickr, photo, photoset) self.upload_thread.check() self.model.finishUploadThread()
def upload_files(self, files, bucket_name): """ Uploads files to a bucket in OCI Object Storage. Can be called from the select_files function. :param files: A tuple of files. First element is a list of absolute paths to the files. Second element is the mimetype of files :type files: tuple :param bucket_name: The name of bucket to upload file(s) to in OCI :type bucket_name: string TODO: Progress window is bigger than it should be, but functional """ filesizes = [] for file in files[0]: filesizes.append(get_filesize(file)) c = self.progress_thread_count self.progress_thread_count += 1 self.upload_thread_count += 1 progress_thread = ProgressWindow(files, filesizes, c) upload_thread = UploadThread(files, bucket_name, self.oci_manager, filesizes, c) upload_thread.file_uploaded.connect(progress_thread.next_file) upload_thread.file_uploaded.connect(self.file_uploaded) upload_thread.bytes_uploaded.connect(progress_thread.set_progress) upload_thread.all_files_uploaded.connect(self.delete_threads) upload_thread.upload_failed.connect(progress_thread.retry_handler) progress_thread.cancel_signal.connect(self.thread_cancelled) progress_thread.retry.clicked.connect(upload_thread.start) # progress_thread.setMinimumHeight(50) self.progress_threads[c] = progress_thread self.upload_threads[c] = upload_thread self.progress_threads[c].show() self.upload_threads[c].start()