2
from charmhelpers.fetch import (
6
from charmhelpers.core.host import mkdir
9
from bzrlib.branch import Branch
11
from charmhelpers.fetch import apt_install
12
apt_install("python-bzrlib")
13
from bzrlib.branch import Branch
15
class BzrUrlFetchHandler(BaseFetchHandler):
16
"""Handler for bazaar branches via generic and lp URLs"""
17
def can_handle(self, source):
18
url_parts = self.parse_url(source)
19
if url_parts.scheme not in ('bzr+ssh', 'lp'):
24
def branch(self, source, dest):
25
url_parts = self.parse_url(source)
26
# If we use lp:branchname scheme we need to load plugins
27
if not self.can_handle(source):
28
raise UnhandledSource("Cannot handle {}".format(source))
29
if url_parts.scheme == "lp":
30
from bzrlib.plugin import load_plugins
33
remote_branch = Branch.open(source)
34
remote_branch.bzrdir.sprout(dest).open_branch()
35
except Exception as e:
38
def install(self, source):
39
url_parts = self.parse_url(source)
40
branch_name = url_parts.path.strip("/").split("/")[-1]
41
dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", branch_name)
42
if not os.path.exists(dest_dir):
43
mkdir(dest_dir, perms=0755)
45
self.branch(source, dest_dir)
47
raise UnhandledSource(e.strerror)