~psivaa/uci-engine/rabbitmq-restish-with-proxy

« back to all changes in this revision

Viewing changes to charms/precise/webui/hooks/charmhelpers/fetch/bzrurl.py

  • Committer: Joe Talbott
  • Date: 2014-01-27 14:54:08 UTC
  • mfrom: (126.3.8 webui)
  • mto: This revision was merged to the branch mainline in revision 161.
  • Revision ID: joe.talbott@canonical.com-20140127145408-zpubebx02y6oumxq
merge doanac's cleanup branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import os
2
 
from charmhelpers.fetch import (
3
 
    BaseFetchHandler,
4
 
    UnhandledSource
5
 
)
6
 
from charmhelpers.core.host import mkdir
7
 
 
8
 
try:
9
 
    from bzrlib.branch import Branch
10
 
except ImportError:
11
 
    from charmhelpers.fetch import apt_install
12
 
    apt_install("python-bzrlib")
13
 
    from bzrlib.branch import Branch
14
 
 
15
 
 
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'):
21
 
            return False
22
 
        else:
23
 
            return True
24
 
 
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
32
 
            load_plugins()
33
 
        try:
34
 
            remote_branch = Branch.open(source)
35
 
            remote_branch.bzrdir.sprout(dest).open_branch()
36
 
        except Exception as e:
37
 
            raise e
38
 
 
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", branch_name)
43
 
        if not os.path.exists(dest_dir):
44
 
            mkdir(dest_dir, perms=0755)
45
 
        try:
46
 
            self.branch(source, dest_dir)
47
 
        except OSError as e:
48
 
            raise UnhandledSource(e.strerror)
49
 
        return dest_dir