~james-page/charms/trusty/nova-compute-vmware/resync

« back to all changes in this revision

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

  • Committer: james.page at ubuntu
  • Date: 2014-12-15 09:09:13 UTC
  • mfrom: (106.1.8 nova-compute-vmware)
  • Revision ID: james.page@ubuntu.com-20141215090913-2ltpvm5xxb6rmk68
[corey.bryant,r=james-page] Sort out charmhelpers issues.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
)
6
6
from charmhelpers.core.host import mkdir
7
7
 
 
8
import six
 
9
if six.PY3:
 
10
    raise ImportError('GitPython does not support Python 3')
 
11
 
8
12
try:
9
13
    from git import Repo
10
14
except ImportError:
17
21
    """Handler for git branches via generic and github URLs"""
18
22
    def can_handle(self, source):
19
23
        url_parts = self.parse_url(source)
20
 
        #TODO (mattyw) no support for ssh git@ yet
 
24
        # TODO (mattyw) no support for ssh git@ yet
21
25
        if url_parts.scheme not in ('http', 'https', 'git'):
22
26
            return False
23
27
        else:
30
34
        repo = Repo.clone_from(source, dest)
31
35
        repo.git.checkout(branch)
32
36
 
33
 
    def install(self, source, branch="master"):
 
37
    def install(self, source, branch="master", dest=None):
34
38
        url_parts = self.parse_url(source)
35
39
        branch_name = url_parts.path.strip("/").split("/")[-1]
36
 
        dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched",
37
 
                                branch_name)
 
40
        if dest:
 
41
            dest_dir = os.path.join(dest, branch_name)
 
42
        else:
 
43
            dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched",
 
44
                                    branch_name)
38
45
        if not os.path.exists(dest_dir):
39
 
            mkdir(dest_dir, perms=0755)
 
46
            mkdir(dest_dir, perms=0o755)
40
47
        try:
41
48
            self.clone(source, dest_dir, branch)
42
49
        except OSError as e: