Skip to content

Commit 6d0d25d

Browse files
committed
trying workaround for pull
1 parent b7e4ec1 commit 6d0d25d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

spython/main/pull.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
from spython.utils import stream_command
2222
import os
2323
import re
24+
import shutil
2425
import sys
26+
import tempfile
2527

2628
def pull(self,
2729
image=None,
@@ -99,8 +101,20 @@ def pull(self,
99101

100102
# Option 1: For hash or commit, need return value to get final_image
101103
if name_by_commit or name_by_hash:
102-
output = self._run_command(cmd, capture=True)
103-
final_image = output.split('Container is at:')[-1].strip('\n').strip()
104+
105+
# Set pull to temporary location
106+
tmp_folder = tempfile.mkdtemp()
107+
self.setenv('SINGULARITY_PULLFOLDER', tmp_folder)
108+
self._run_command(cmd, capture=capture)
109+
110+
try:
111+
tmp_image = os.path.join(tmp_folder, os.listdir(tmp_folder)[0])
112+
final_image = os.path.join(pull_folder, os.path.basename(tmp_image))
113+
shutil.move(tmp_image, final_image)
114+
shutil.rmtree(tmp_folder)
115+
116+
except:
117+
bot.error('Issue pulling image with commit or hash, try without?')
104118

105119
# Option 2: Streaming we just run to show user
106120
elif stream is False:

0 commit comments

Comments
 (0)