2727# Plugin for fetching and unpacking tarballs from the Web
2828# @param url URL for the tarball
2929# @param cmd Command line to use to fetch the tarball (e.g., "curl -o")
30+ # @param subdir Subdirectory of interest in package
3031# @}
3132class FetchTarball (FetchMTTTool ):
3233
@@ -40,6 +41,7 @@ def __init__(self):
4041 self .options = {}
4142 self .options ['url' ] = (None , "URL to tarball" )
4243 self .options ['cmd' ] = ("wget" , "Command to use to fetch the tarball" )
44+ self .options ['subdir' ] = (None , "Subdirectory of interest in package" )
4345 return
4446
4547 def activate (self ):
@@ -86,6 +88,21 @@ def execute(self, log, keyvals, testDef):
8688 if self .done [tarball ] is not None :
8789 log ['status' ] = self .done [repo ][0 ]
8890 log ['location' ] = self .done [repo ][1 ]
91+ # if they specified a subdirectory of interest,
92+ # check to see if it exists
93+ if cmds ['subdir' ] is not None :
94+ # check that this subdirectory actually exists
95+ ckdir = os .path .join (log ['location' ], cmds ['subdir' ])
96+ if not os .path .exists (ckdir ):
97+ log ['status' ] = 1
98+ log ['stderr' ] = "Subdirectory " + cmds ['subdir' ] + " was not found"
99+ return
100+ if not os .path .isdir (ckdir ):
101+ log ['status' ] = 1
102+ log ['stderr' ] = "Subdirectory " + cmds ['subdir' ] + " is not a directory"
103+ return
104+ # adjust the location so later stages can find it
105+ log ['location' ] = ckdir
89106 return
90107 except KeyError :
91108 pass
@@ -189,13 +206,29 @@ def execute(self, log, keyvals, testDef):
189206 log ['status' ] = results ['status' ]
190207 log ['stdout' ] = results ['stdout' ]
191208 log ['stderr' ] = results ['stderr' ]
192- testDef .logger .verbose_print ("setting location to " + package )
193209
194210 # log our absolute location so others can find it
195211 log ['location' ] = os .getcwd ()
196212 # track that we serviced this one
197213 self .done [tarball ] = (results ['status' ], log ['location' ])
198214
215+ # if they specified a subdirectory of interest,
216+ # check to see if it exists
217+ if cmds ['subdir' ] is not None :
218+ # check that this subdirectory actually exists
219+ ckdir = os .path .join (log ['location' ], cmds ['subdir' ])
220+ if not os .path .exists (ckdir ):
221+ log ['status' ] = 1
222+ log ['stderr' ] = "Subdirectory " + cmds ['subdir' ] + " was not found"
223+ return
224+ if not os .path .isdir (ckdir ):
225+ log ['status' ] = 1
226+ log ['stderr' ] = "Subdirectory " + cmds ['subdir' ] + " is not a directory"
227+ return
228+ # adjust our location so later stages can find it
229+ log ['location' ] = ckdir
230+
231+ testDef .logger .verbose_print ("setting location to " + log ['location' ])
199232 # change back to the original directory
200233 os .chdir (cwd )
201234
0 commit comments