1212urllib3 .disable_warnings ()
1313
1414# Graphical needs for drawing full line
15- console_rows , console_columns = os .popen ('stty size' , 'r' ).read ().split ()
15+ try :
16+ console_rows , console_columns = os .popen ('stty size' , 'r' ).read ().split ()
17+ except :
18+ console_rows , console_columns = 20 , 20
1619
1720############# DEFAULTs VAR
1821
2326
2427username = ""
2528password = ""
29+ output_path = "."
2630
2731json_manifest_type = 'application/vnd.docker.distribution.manifest.v2+json'
2832json_manifest_type_bis = 'application/vnd.docker.distribution.manifest.list.v2+json'
@@ -101,7 +105,10 @@ def progress_bar(ublob, nb_traits):
101105############## Check if args < 2
102106
103107if len (sys .argv ) < 2 :
104- print ('Usage:\n \t docker_pull.py [registry/][repository/]image[:tag|@digest] [username] [password]\n ' )
108+ print ('Usage:' )
109+ print ('\t docker_pull.py [registry/][repository/]image[:tag|@digest] ' )
110+ print ('\t docker_pull.py [registry/][repository/]image[:tag|@digest] output_path' )
111+ print ('\t docker_pull.py [registry/][repository/]image[:tag|@digest] username password output_path\n ' )
105112 exit (1 )
106113
107114############## Get info from arg
@@ -113,6 +120,12 @@ def progress_bar(ublob, nb_traits):
113120 username = sys .argv [2 ]
114121 password = sys .argv [3 ]
115122
123+ if len (sys .argv ) == 3 :
124+ output_path = sys .argv [2 ]
125+
126+ if len (sys .argv ) == 5 :
127+ output_path = sys .argv [4 ]
128+
116129############## Get repository url + registry url for auth
117130
118131if len (imgparts ) > 1 and ('.' in imgparts [0 ] or ':' in imgparts [0 ]):
@@ -183,7 +196,7 @@ def progress_bar(ublob, nb_traits):
183196layers = resp .json ()['layers' ]
184197
185198# Create tmp folder that will hold the image
186- imgdir = '/tmp/ tmp_{}_{} ' .format (img . replace ('/' , '.' ), tag )
199+ imgdir = output_path + '/ tmp_{}' .format (sys . argv [ 1 ]. replace ('/' , '.' ). replace ( ':' , '@' ) )
187200
188201if os .path .exists (imgdir ):
189202 shutil .rmtree (imgdir )
@@ -305,7 +318,7 @@ def progress_bar(ublob, nb_traits):
305318file .close ()
306319
307320# Create image tar and clean tmp folder
308- docker_tar = repository . replace ('/' , '_' ) + '_' + img .replace ('/' , '_ ' ) + '.tar'
321+ docker_tar = output_path + "/" + sys . argv [ 1 ]. replace ('/' , '_' ).replace (':' , '@ ' ) + '.tar'
309322sys .stdout .write ("Creating archive..." )
310323sys .stdout .flush ()
311324tar = tarfile .open (docker_tar , "w" )
0 commit comments