Skip to content

Commit 57e4755

Browse files
committed
Merge branch 'master' of https://github.com/girder/slicer_cli_web into slicer-cli-web-singularity
2 parents 55eea51 + e870b2c commit 57e4755

File tree

6 files changed

+70
-21
lines changed

6 files changed

+70
-21
lines changed

example-average-color/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
FROM python:3.11-slim
22
LABEL maintainer="Kitware, Inc. <kitware@kitware.com>"
33

4-
RUN pip install --find-links https://girder.github.io/large_image_wheels large_image[sources]
5-
RUN pip install girder-slicer-cli-web
4+
RUN pip install --no-cache-dir --find-links https://girder.github.io/large_image_wheels large_image[sources]
5+
6+
RUN pip install --no-cache-dir girder-slicer-cli-web
67

78
COPY . /
89
ENTRYPOINT ["python", "./cli_list.py"]

example-girder-requests/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
FROM python:3.11-slim
22
MAINTAINER David Manthey <david.manthey@kitware.com>
33

4-
RUN pip install --find-links https://girder.github.io/large_image_wheels large_image[sources]
5-
RUN pip install girder-slicer-cli-web
6-
RUN pip install girder-client
4+
RUN pip install --no-cache--dir --find-links https://girder.github.io/large_image_wheels large_image[sources]
5+
RUN pip install --no-cache--dir girder-slicer-cli-web
6+
RUN pip install --no-cache--dir girder-client
77

88
COPY . $PWD
99
ENTRYPOINT ["python", "./cli_list.py"]

slicer_cli_web/image_job.py

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import json
2020
import os
21+
import time
2122

2223
import docker
2324
from girder import logger
@@ -213,7 +214,7 @@ def jobPullAndLoad(job):
213214
switch_to_sif_image_folder()
214215
pull_image_and_convert_to_sif(pullList)
215216
else:
216-
pullDockerImage(docker_client, pullList)
217+
pullDockerImage(docker_client, pullList, job)
217218
except DockerImageNotFoundError as err:
218219
errorState = True
219220
notExistSet = set(err.imageName)
@@ -389,19 +390,57 @@ def getCliData(name, client, job):
389390
raise DockerImageError('Error getting %s cli data from image ' % (name) + str(err))
390391

391392

392-
def pullDockerImage(client, names):
393+
def pullDockerImage(client, names, job=None):
393394
"""
394395
Attempt to pull the docker images listed in names. Failure results in a
395396
DockerImageNotFoundError being raised
396397
397-
:params client: The docker python client
398-
:params names: A list of docker images to be pulled from the Dockerhub
398+
:param client: The docker python client
399+
:param names: A list of docker images to be pulled from the Dockerhub
400+
:param job: A job to update with status.
399401
"""
400402
imgNotExistList = []
401403
for name in names:
402404
try:
403405
logger.info('Pulling %s image', name)
404-
client.images.pull(name)
406+
lastlog = time.time()
407+
stats = {}
408+
for line in client.api.pull(name, stream=True, decode=True):
409+
try:
410+
line.update(line.get('progressDetail', {}))
411+
if 'id' not in line or ('total' not in line and line['id'] not in stats):
412+
continue
413+
stats.setdefault(line['id'], line).update(line)
414+
if time.time() - lastlog >= 10:
415+
total = sum(record['total'] for record in stats.values())
416+
downloaded = sum(
417+
record['total'] for record in stats.values()
418+
if record['status'] != 'Downloading')
419+
downloaded += sum(
420+
record['current'] for record in stats.values()
421+
if record['status'] == 'Downloading')
422+
extracted = sum(
423+
record['total'] for record in stats.values()
424+
if record['status'] == 'Pull complete')
425+
extracted += sum(
426+
record['current'] for record in stats.values()
427+
if record['status'] == 'Extracting')
428+
if total:
429+
msg = f'Pulling {name} image: '
430+
if downloaded < total:
431+
val = downloaded
432+
msg += 'downloaded '
433+
else:
434+
val = extracted
435+
msg += 'extracted '
436+
msg += f'{val}/{total} ({val * 100 / total:4.2f}%)'
437+
logger.info(msg)
438+
if job:
439+
job = Job().updateJob(job, log=msg + '\n')
440+
lastlog = time.time()
441+
except Exception:
442+
# Don't fail if the log code has an issue
443+
pass
405444
# some invalid image names will not be pulled but the pull method
406445
# will not throw an exception so the only way to confirm if a pull
407446
# succeeded is to attempt a docker inspect on the image

slicer_cli_web/prepare_task.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ def _add_optional_output_param(param, args, user, result_hooks, reference, templ
189189
ref = reference.copy()
190190
ref['identifier'] = param.identifier()
191191
result_hooks.append(GirderUploadVolumePathToFolder(
192-
path, folder, upload_kwargs={'reference': json.dumps(ref)}))
192+
path, folder, must_exist=False,
193+
upload_kwargs={'reference': json.dumps(ref)}))
193194

194195
return container_args
195196

slicer_cli_web/web_client/views/ItemSelectorWidget.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const ItemSelectorWidget = BrowserWidget.extend({
6969
settings.input = {
7070
label: 'Item name',
7171
validate: (val) => {
72-
if (val && val.trim()) {
72+
if ((val && val.trim()) || (!val && !this.model.required)) {
7373
return $.Deferred().resolve().promise();
7474
}
7575
return $.Deferred().reject('Specify an item name').promise();
@@ -264,14 +264,22 @@ const ItemSelectorWidget = BrowserWidget.extend({
264264
});
265265
break;
266266
case 'new-file':
267-
this.model.set({
268-
path: this._path(),
269-
parent: model,
270-
value: new ItemModel({
271-
name: fileName,
272-
folderId: model.id
273-
})
274-
});
267+
if (!fileName) {
268+
this.model.set({
269+
path: this._path(),
270+
parent: model,
271+
value: null
272+
});
273+
} else {
274+
this.model.set({
275+
path: this._path(),
276+
parent: model,
277+
value: new ItemModel({
278+
name: fileName,
279+
folderId: model.id
280+
})
281+
});
282+
}
275283
break;
276284
case 'multi':
277285
if (fileName.trim() === '') {

small-docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ RUN chmod a+x /usr/local/bin/groupadd
1414
RUN touch /usr/local/bin/useradd
1515
RUN chmod a+x /usr/local/bin/useradd
1616

17-
RUN pip install girder-slicer-cli-web
17+
RUN pip install --no-cache-dir girder-slicer-cli-web
1818
COPY . $PWD
1919

2020
ENTRYPOINT ["python", "./cli_list.py"]

0 commit comments

Comments
 (0)