~bloodearnest/charms/precise/squid-reverseproxy/trunk

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/fetch/bzrurl.py

  • Committer: Marco Ceppi
  • Date: 2013-11-07 01:40:09 UTC
  • mfrom: (28.1.85 master)
  • Revision ID: marco@ceppi.net-20131107014009-lqqg63wkyt6ot2ou
[sidnei] Greatly improve test coverage
[sidnei] Allow the use of an X-Balancer-Name header to select which cache_peer backend will be used for a specific request.
[sidnei] Support 'all-services' being set in the relation, in the way that the haproxy sets it, in addition to the previously supported 'sitenames' setting. Makes it compatible with the haproxy charm.
[sidnei] When the list of supported 'sitenames' (computed from dstdomain acls) changes, notify services related via the 'cached-website' relation. This allows to add new services in the haproxy service (or really, any other service related), which notifies the squid service, which then bubbles up to services related via cached-website.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
from bzrlib.branch import Branch
 
3
from charmhelpers.fetch import (
 
4
    BaseFetchHandler,
 
5
    UnhandledSource
 
6
)
 
7
from charmhelpers.core.host import mkdir
 
8
 
 
9
 
 
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'):
 
15
            return False
 
16
        else:
 
17
            return True
 
18
 
 
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
 
26
            load_plugins()
 
27
        try:
 
28
            remote_branch = Branch.open(source)
 
29
            remote_branch.bzrdir.sprout(dest).open_branch()
 
30
        except Exception as e:
 
31
            raise e
 
32
 
 
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)
 
39
        try:
 
40
            self.branch(source, dest_dir)
 
41
        except OSError as e:
 
42
            raise UnhandledSource(e.strerror)
 
43
        return dest_dir
 
44