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
16
class BzrUrlFetchHandler(BaseFetchHandler):
17
"""Handler for bazaar branches via generic and lp URLs"""
18
def can_handle(self, source):
19
url_parts = self.parse_url(source)
20
if url_parts.scheme not in ('bzr+ssh', 'lp'):
25
def branch(self, source, dest):
26
url_parts = self.parse_url(source)
27
# If we use lp:branchname scheme we need to load plugins
28
if not self.can_handle(source):
29
raise UnhandledSource("Cannot handle {}".format(source))
30
if url_parts.scheme == "lp":
31
from bzrlib.plugin import load_plugins
34
remote_branch = Branch.open(source)
35
remote_branch.bzrdir.sprout(dest).open_branch()
36
except Exception as e:
39
def install(self, source):
40
url_parts = self.parse_url(source)
41
branch_name = url_parts.path.strip("/").split("/")[-1]
42
dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched",
44
if not os.path.exists(dest_dir):
45
mkdir(dest_dir, perms=0755)
47
self.branch(source, dest_dir)
49
raise UnhandledSource(e.strerror)