~ibmcharmers/charms/xenial/ibm-cinder-storwize-svc/trunk

« back to all changes in this revision

Viewing changes to .tox/py35/lib/python3.5/site-packages/pip/vcs/bazaar.py

  • Committer: Ankammarao
  • Date: 2017-03-06 05:11:42 UTC
  • Revision ID: achittet@in.ibm.com-20170306051142-dpg27z4es1k56hfn
Marked tests folder executable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from __future__ import absolute_import
 
2
 
 
3
import logging
 
4
import os
 
5
import tempfile
 
6
 
 
7
# TODO: Get this into six.moves.urllib.parse
 
8
try:
 
9
    from urllib import parse as urllib_parse
 
10
except ImportError:
 
11
    import urlparse as urllib_parse
 
12
 
 
13
from pip.utils import rmtree, display_path
 
14
from pip.vcs import vcs, VersionControl
 
15
from pip.download import path_to_url
 
16
 
 
17
 
 
18
logger = logging.getLogger(__name__)
 
19
 
 
20
 
 
21
class Bazaar(VersionControl):
 
22
    name = 'bzr'
 
23
    dirname = '.bzr'
 
24
    repo_name = 'branch'
 
25
    schemes = (
 
26
        'bzr', 'bzr+http', 'bzr+https', 'bzr+ssh', 'bzr+sftp', 'bzr+ftp',
 
27
        'bzr+lp',
 
28
    )
 
29
 
 
30
    def __init__(self, url=None, *args, **kwargs):
 
31
        super(Bazaar, self).__init__(url, *args, **kwargs)
 
32
        # Python >= 2.7.4, 3.3 doesn't have uses_fragment or non_hierarchical
 
33
        # Register lp but do not expose as a scheme to support bzr+lp.
 
34
        if getattr(urllib_parse, 'uses_fragment', None):
 
35
            urllib_parse.uses_fragment.extend(['lp'])
 
36
            urllib_parse.non_hierarchical.extend(['lp'])
 
37
 
 
38
    def export(self, location):
 
39
        """
 
40
        Export the Bazaar repository at the url to the destination location
 
41
        """
 
42
        temp_dir = tempfile.mkdtemp('-export', 'pip-')
 
43
        self.unpack(temp_dir)
 
44
        if os.path.exists(location):
 
45
            # Remove the location to make sure Bazaar can export it correctly
 
46
            rmtree(location)
 
47
        try:
 
48
            self.run_command(['export', location], cwd=temp_dir,
 
49
                             show_stdout=False)
 
50
        finally:
 
51
            rmtree(temp_dir)
 
52
 
 
53
    def switch(self, dest, url, rev_options):
 
54
        self.run_command(['switch', url], cwd=dest)
 
55
 
 
56
    def update(self, dest, rev_options):
 
57
        self.run_command(['pull', '-q'] + rev_options, cwd=dest)
 
58
 
 
59
    def obtain(self, dest):
 
60
        url, rev = self.get_url_rev()
 
61
        if rev:
 
62
            rev_options = ['-r', rev]
 
63
            rev_display = ' (to revision %s)' % rev
 
64
        else:
 
65
            rev_options = []
 
66
            rev_display = ''
 
67
        if self.check_destination(dest, url, rev_options, rev_display):
 
68
            logger.info(
 
69
                'Checking out %s%s to %s',
 
70
                url,
 
71
                rev_display,
 
72
                display_path(dest),
 
73
            )
 
74
            self.run_command(['branch', '-q'] + rev_options + [url, dest])
 
75
 
 
76
    def get_url_rev(self):
 
77
        # hotfix the URL scheme after removing bzr+ from bzr+ssh:// readd it
 
78
        url, rev = super(Bazaar, self).get_url_rev()
 
79
        if url.startswith('ssh://'):
 
80
            url = 'bzr+' + url
 
81
        return url, rev
 
82
 
 
83
    def get_url(self, location):
 
84
        urls = self.run_command(['info'], show_stdout=False, cwd=location)
 
85
        for line in urls.splitlines():
 
86
            line = line.strip()
 
87
            for x in ('checkout of branch: ',
 
88
                      'parent branch: '):
 
89
                if line.startswith(x):
 
90
                    repo = line.split(x)[1]
 
91
                    if self._is_local_repository(repo):
 
92
                        return path_to_url(repo)
 
93
                    return repo
 
94
        return None
 
95
 
 
96
    def get_revision(self, location):
 
97
        revision = self.run_command(
 
98
            ['revno'], show_stdout=False, cwd=location)
 
99
        return revision.splitlines()[-1]
 
100
 
 
101
    def get_src_requirement(self, dist, location):
 
102
        repo = self.get_url(location)
 
103
        if not repo:
 
104
            return None
 
105
        if not repo.lower().startswith('bzr:'):
 
106
            repo = 'bzr+' + repo
 
107
        egg_project_name = dist.egg_name().split('-', 1)[0]
 
108
        current_rev = self.get_revision(location)
 
109
        return '%s@%s#egg=%s' % (repo, current_rev, egg_project_name)
 
110
 
 
111
    def check_version(self, dest, rev_options):
 
112
        """Always assume the versions don't match"""
 
113
        return False
 
114
 
 
115
 
 
116
vcs.register(Bazaar)