15
15
# specific language governing permissions and limitations under the License.
16
16
17
17
import os
18
+ import shutil
18
19
import tempfile
19
20
from urllib .parse import urlparse
20
21
28
29
29
30
class VCSResponse :
30
31
"""
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)
35
36
"""
36
37
37
38
def __init__ (self , dest_dir , vcs_type , domain ):
38
39
self .dest_dir = dest_dir
39
40
self .vcs_type = vcs_type
40
41
self .domain = domain
41
42
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
+
42
50
43
51
def fetch_via_vcs (url ):
44
52
"""
45
53
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
47
55
"""
48
56
parsed_url = urlparse (url )
49
57
scheme = parsed_url .scheme
50
58
domain = parsed_url .netloc
51
- temp = tempfile .mkdtemp ()
52
- os .rmdir (temp )
59
+ dest_dir = os .path .join (tempfile .mkdtemp (), "checkout" )
53
60
if scheme not in vcs .all_schemes :
54
61
raise Exception ("Not a supported/known scheme." )
55
62
@@ -58,6 +65,6 @@ def fetch_via_vcs(url):
58
65
vcs_type = vcs_name
59
66
60
67
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 ))
62
69
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