2
from bzrlib.branch import Branch
3
from charmhelpers.fetch import (
7
from charmhelpers.core.host import mkdir
10
class BzrUrlFetchHandler(BaseFetchHandler):
11
"""Handler for bazaar branches via generic and lp URLs"""
12
def can_handle(self, source):
13
url_parts = self.parse_url(source)
14
if url_parts.scheme not in ('bzr+ssh', 'lp'):
19
def branch(self, source, dest):
20
url_parts = self.parse_url(source)
21
# If we use lp:branchname scheme we need to load plugins
22
if not self.can_handle(source):
23
raise UnhandledSource("Cannot handle {}".format(source))
24
if url_parts.scheme == "lp":
25
from bzrlib.plugin import load_plugins
28
remote_branch = Branch.open(source)
29
remote_branch.bzrdir.sprout(dest).open_branch()
30
except Exception as e:
33
def install(self, source):
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", branch_name)
37
if not os.path.exists(dest_dir):
38
mkdir(dest_dir, perms=0755)
40
self.branch(source, dest_dir)
42
raise UnhandledSource(e.strerror)