2
from charmhelpers.fetch import (
6
from charmhelpers.core.host import mkdir
11
from charmhelpers.fetch import apt_install
12
apt_install("python-git")
16
class GitUrlFetchHandler(BaseFetchHandler):
17
"""Handler for git branches via generic and github URLs"""
18
def can_handle(self, source):
19
url_parts = self.parse_url(source)
20
#TODO (mattyw) no support for ssh git@ yet
21
if url_parts.scheme not in ('http', 'https', 'git'):
26
def clone(self, source, dest, branch):
27
if not self.can_handle(source):
28
raise UnhandledSource("Cannot handle {}".format(source))
30
repo = Repo.clone_from(source, dest)
31
repo.git.checkout(branch)
33
def install(self, source, branch="master"):
34
url_parts = self.parse_url(source)
35
branch_name = url_parts.path.strip("/").split("/")[-1]
36
dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched",
38
if not os.path.exists(dest_dir):
39
mkdir(dest_dir, perms=0755)
41
self.clone(source, dest_dir, branch)
43
raise UnhandledSource(e.strerror)