Skip to content

Commit

Permalink
Allow multiple concurrent uploads,
Browse files Browse the repository at this point in the history
and multiple concurrent downloads of the same archive.
  • Loading branch information
sz3 committed Feb 22, 2020
1 parent ebaa8ee commit de68154
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
19 changes: 15 additions & 4 deletions pogui/pogui.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(self, config):
self.config = config
self.cli.set_keyfiles(*self.config.get('keyfiles', []))
self._refresh_list_manifests()
self._progress_count = 0

def _refresh_list_manifests(self):
locations = self.config.get('fs', []) + ['local']
Expand Down Expand Up @@ -109,12 +110,12 @@ def scanManifest(self, mfn):
paths = backfill_parent_dirs(blobs.keys())
return [{'path': p, **blob_details(p, blobs.get(p))} for p in paths]

def _backgroundProgress(self, status_iter, mfn, dest_path=None):
def _backgroundProgress(self, status_iter, progress_id, dest_path=None):
for info in status_iter:
# need to snapshot these better
percent = info['current'] * 100 / info['total']
print('giving {} to window'.format(info))
window.evaluate_js("ProgressBar.update('{}', '{:.2f}%');".format(mfn, percent))
window.evaluate_js("ProgressBar.update('{}', '{:.2f}%');".format(progress_id, percent))

if dest_path:
system_open_folder(dest_path)
Expand All @@ -132,10 +133,15 @@ def downloadArchive(self, mfn):

status_iter = self.cli.decrypt(real_mfn_path, cwd=path)
first_chunk = next(status_iter)

self._progress_count += 1
progress_id = f'{mfn}.{self._progress_count}'
Thread(
target=self._backgroundProgress,
kwargs={'status_iter': status_iter, 'mfn': mfn, 'dest_path': path}
kwargs={'status_iter': status_iter, 'progress_id': progress_id, 'dest_path': path}
).start()

first_chunk['progress_id'] = progress_id
return first_chunk

def downloadFile(self, params):
Expand All @@ -147,10 +153,15 @@ def createArchive(self, params):
paths, destinations = params
status_iter = self.cli.encrypt(paths, destinations)
first_chunk = next(status_iter)

self._progress_count += 1
progress_id = f'NewArchive.{self._progress_count}'
Thread(
target=self._backgroundProgress,
kwargs={'status_iter': status_iter, 'mfn': 'create-archive'}
kwargs={'status_iter': status_iter, 'progress_id': progress_id}
).start()

first_chunk['progress_id'] = progress_id
return first_chunk

def getLocalFolders(self, __=None):
Expand Down
5 changes: 3 additions & 2 deletions pogui/web/create-archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ return {
{
var paths = CheckList.get('create-archive-list').items();
var destinations = CreateArchive.getDestinations();
Api.createArchive(paths, destinations).then(function() {
ProgressBar.add('create-archive');
Api.createArchive(paths, destinations).then(function(res) {
if (res)
ProgressBar.add(res['progress_id']);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion pogui/web/filebrowser/fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ return {
download.click(function() {
Api.downloadArchive(id).then(function(res) {
if (res)
ProgressBar.add(id);
ProgressBar.add(res['progress_id']);
});
});
act.append(download);
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
install_requires=[
'b2',
'boto3',
'pogcli==0.1.2',
'pogcli==0.1.3',
'pywebview',
'pyyaml',
],
Expand Down
8 changes: 4 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ def test_downloadArchive(self, mock_thread, mock_window):
])

res = self.api.downloadArchive('s3:bucket/dir/file.mfn')
self.assertEqual(res, {'current': 1, 'total': 2, 'filename': 'foo'})
self.assertEqual(res, {'current': 1, 'total': 2, 'filename': 'foo', 'progress_id': 's3:bucket/dir/file.mfn.1'})
mock_thread.assert_called_once_with(target=self.api._backgroundProgress, kwargs={
'status_iter': self.api.cli.decrypt.return_value,
'mfn': 's3:bucket/dir/file.mfn',
'progress_id': 's3:bucket/dir/file.mfn.1',
'dest_path': '/home/user/',
})

Expand All @@ -208,11 +208,11 @@ def test_createArchive(self, mock_thread, mock_window):
])

res = self.api.createArchive((['foo', 'bar'], ['s3:bucket1', 'b2:bucket2']))
self.assertEqual(res, {'current': 1, 'total': 2, 'filename': 'foo'})
self.assertEqual(res, {'current': 1, 'total': 2, 'filename': 'foo', 'progress_id': 'NewArchive.1'})

mock_thread.assert_called_once_with(target=self.api._backgroundProgress, kwargs={
'status_iter': self.api.cli.encrypt.return_value,
'mfn': 'create-archive',
'progress_id': 'NewArchive.1',
})

def test_getLocalFolders(self, mock_window):
Expand Down

0 comments on commit de68154

Please sign in to comment.