@@ -52,20 +52,7 @@ def verbose(msg):
5252
5353 with ExitStack () as stack :
5454 verbose (f"== Fetching PEP artifact from { settings .PEP_ARTIFACT_URL } " )
55- peps_last_updated = get_peps_last_updated ()
56- with requests .get (settings .PEP_ARTIFACT_URL , stream = True ) as r :
57- artifact_last_modified = parsedate (r .headers ['last-modified' ])
58- if peps_last_updated > artifact_last_modified :
59- verbose (f"== No update to artifacts, we're done here!" )
60- return
61-
62- temp_file = stack .enter_context (TemporaryFile ())
63- for chunk in r .iter_content (chunk_size = 8192 ):
64- if chunk :
65- temp_file .write (chunk )
66-
67- temp_file .seek (0 )
68-
55+ temp_file = self .get_artifact_tarball (stack , verbose )
6956 temp_dir = stack .enter_context (TemporaryDirectory ())
7057 tar_ball = stack .enter_context (TarFile .open (fileobj = temp_file , mode = 'r:gz' ))
7158 tar_ball .extractall (path = temp_dir , numeric_owner = False )
@@ -129,3 +116,23 @@ def verbose(msg):
129116 verbose ("- Skipping non-PEP related image '{}'" .format (img ))
130117
131118 verbose ("== Finished" )
119+
120+ def get_artifact_tarball (self , stack , verbose ):
121+ artifact_url = settings .PEP_ARTIFACT_URL
122+ if not artifact_url .startswith (('http://' , 'https://' )):
123+ return stack .enter_context (open (artifact_url , 'rb' ))
124+
125+ peps_last_updated = get_peps_last_updated ()
126+ with requests .get (artifact_url , stream = True ) as r :
127+ artifact_last_modified = parsedate (r .headers ['last-modified' ])
128+ if peps_last_updated > artifact_last_modified :
129+ verbose (f"== No update to artifacts, we're done here!" )
130+ return
131+
132+ temp_file = stack .enter_context (TemporaryFile ())
133+ for chunk in r .iter_content (chunk_size = 8192 ):
134+ if chunk :
135+ temp_file .write (chunk )
136+
137+ temp_file .seek (0 )
138+ return temp_file
0 commit comments