1515# specific language governing permissions and limitations under the License.
1616
1717import os
18+ import shutil
1819import tempfile
1920from urllib .parse import urlparse
2021
2829
2930class VCSResponse :
3031 """
31- Represent the response from fetching a VCS URL with:
32- - `dest_dir`: destination of directory
33- - `vcs_type`: VCS Type of URL (git,bzr,hg,svn)
34- - `domain` : Source of git VCS (GitHub, Gitlab, Bitbucket)
32+ Represent the response from fetching a VCS URL with:
33+ - `dest_dir`: destination of directory
34+ - `vcs_type`: VCS Type of URL (git,bzr,hg,svn)
35+ - `domain` : Source of git VCS (GitHub, Gitlab, Bitbucket)
3536 """
3637
3738 def __init__ (self , dest_dir , vcs_type , domain ):
3839 self .dest_dir = dest_dir
3940 self .vcs_type = vcs_type
4041 self .domain = domain
4142
43+ def delete (self ):
44+ """
45+ Delete the temporary directory.
46+ """
47+ if os .path .isdir (self .dest_dir ):
48+ shutil .rmtree (path = self .dest_dir )
49+
4250
4351def fetch_via_vcs (url ):
4452 """
4553 Take `url` as input and store the content of it at location specified at `location` string
46- Return a VCSResponse object
54+ Return a VCSResponse object
4755 """
4856 parsed_url = urlparse (url )
4957 scheme = parsed_url .scheme
5058 domain = parsed_url .netloc
51- temp = tempfile .mkdtemp ()
52- os .rmdir (temp )
59+ dest_dir = os .path .join (tempfile .mkdtemp (), "checkout" )
5360 if scheme not in vcs .all_schemes :
5461 raise Exception ("Not a supported/known scheme." )
5562
@@ -58,6 +65,6 @@ def fetch_via_vcs(url):
5865 vcs_type = vcs_name
5966
6067 backend = vcs .get_backend_for_scheme (scheme )
61- backend .obtain (dest = temp , url = misc .hide_url (url ))
68+ backend .obtain (dest = dest_dir , url = misc .hide_url (url ))
6269
63- return VCSResponse (dest_dir = temp , vcs_type = vcs_type , domain = domain )
70+ return VCSResponse (dest_dir = dest_dir , vcs_type = vcs_type , domain = domain )
0 commit comments