2727
2828class Singularity :
2929
30- def __init__ (self ,sudo = True ,sudopw = None ,debug = False ):
30+
31+ def __init__ (self ,sudo = False ,sudopw = None ,debug = False ):
3132 '''upon init, store user password to not ask for it again'''
3233
3334 self .sudopw = sudopw
@@ -117,7 +118,7 @@ def execute(self,image_path,command,writable=False,contain=False):
117118 if self .debug == True :
118119 cmd = ["singularity" ,'--debug' ,"exec" ]
119120 else :
120- cmd = ["singularity" ,"exec" ]
121+ cmd = ["singularity" ,'--quiet' , "exec" ]
121122
122123 cmd = self .add_flags (cmd ,writable = writable ,contain = contain )
123124
@@ -194,6 +195,21 @@ def importcmd(self,image_path,input_source,import_type=None,command=None):
194195 return None
195196
196197
198+ def pull (self ,image_path ):
199+ '''pull will pull a singularity hub image
200+ :param image_path: full path to image
201+ '''
202+ if not image_path .startswit ('shub://' ):
203+ bot .logger .error ("pull is only valid for the shub://uri, %s is invalid." ,image_name )
204+ sys .exit (1 )
205+
206+ if self .debug == True :
207+ cmd = ['singularity' ,'--debug' ,'pull' ,image_path ]
208+ else :
209+ cmd = ['singularity' ,'pull' ,image_path ]
210+ return self .run_command (cmd )
211+
212+
197213
198214 def run (self ,image_path ,command ,writable = False ,contain = False ):
199215 '''run will run a command inside the container, probably not intended for within python
@@ -213,6 +229,7 @@ def run(self,image_path,command,writable=False,contain=False):
213229 # Run the command
214230 return self .run_command (cmd ,sudo = sudo )
215231
232+
216233 def start (self ,image_path ,writable = False ,contain = False ):
217234 '''start will start a container
218235 '''
@@ -276,7 +293,7 @@ def get_image(image,return_existed=False,sudopw=None,size=None,debug=False):
276293 cli = Singularity (debug = debug ) # This command will ask the user for sudo
277294
278295 tmpdir = tempfile .mkdtemp ()
279- image_name = "%s.img" % image .replace ("docker://" ,"" )
296+ image_name = "%s.img" % image .replace ("docker://" ,"" ). replace ( "/" , "-" )
280297 bot .logger .info ("Found docker image %s, creating and importing..." ,image_name )
281298 image_path = "%s/%s" % (tmpdir ,image_name )
282299 cli .create (image_path ,size = size )
0 commit comments