-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuploader.py
More file actions
45 lines (37 loc) · 1.71 KB
/
Copy pathuploader.py
File metadata and controls
45 lines (37 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from PySide2.QtCore import QFileInfo, QObject, Signal
from ht_requests.ht_requests import ht_utilities
from ht_requests.ht_requests import htauthcontroller
from ht_requests.ht_requests import ht_requests
from tqdm import tqdm
class Uploader(QObject):
currentUploadDone = Signal(int)
allUploadsDone = Signal()
currentlyUploading = Signal(str)
def __init__(self, parent=None):
super(Uploader, self).__init__(parent)
self.interrupt = False
def performUpload(self, metadataList, authControl, ht_id_path, metadata):
self.interrupt = False
# Check that all files initially exist. This is a quick sanity check. The user could
# *still* delete a file out from under the codes.
for i in tqdm(range(len(metadataList)), desc="Checking Files"):
if not QFileInfo.exists(metadataList[i]):
self.currentlyUploading.emit(
"File Missing: " + metadataList[i].split("/")[-1])
self.interrupt = True
for i in tqdm(range(len(metadataList)), desc="Uploading Files"):
if self.interrupt:
break
if not QFileInfo.exists(metadataList[i]):
self.currentlyUploading.emit(
"File Missing: " + metadataList[i].split("/")[-1])
break
else:
self.currentlyUploading.emit(
"Currently uploading: " + metadataList[i].split("/")[-1])
ht_requests.upload_file(
authControl, metadataList[i], 'user', None, ht_id_path, metadata)
self.currentUploadDone.emit(i+1)
self.allUploadsDone.emit()
def interruptUpload(self):
self.interrupt = True