2
from charmhelpers.fetch import (
6
from charmhelpers.core.host import mkdir
10
raise ImportError('GitPython does not support Python 3')
15
from charmhelpers.fetch import apt_install
16
apt_install("python-git")
20
class GitUrlFetchHandler(BaseFetchHandler):
21
"""Handler for git branches via generic and github URLs"""
22
def can_handle(self, source):
23
url_parts = self.parse_url(source)
24
# TODO (mattyw) no support for ssh git@ yet
25
if url_parts.scheme not in ('http', 'https', 'git'):
30
def clone(self, source, dest, branch):
31
if not self.can_handle(source):
32
raise UnhandledSource("Cannot handle {}".format(source))
34
repo = Repo.clone_from(source, dest)
35
repo.git.checkout(branch)
37
def install(self, source, branch="master", dest=None):
38
url_parts = self.parse_url(source)
39
branch_name = url_parts.path.strip("/").split("/")[-1]
41
dest_dir = os.path.join(dest, branch_name)
43
dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched",
45
if not os.path.exists(dest_dir):
46
mkdir(dest_dir, perms=0o755)
48
self.clone(source, dest_dir, branch)
50
raise UnhandledSource(e.strerror)