Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/pip/vcs/bazaar.py @ 0:d67268158946 draft
planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author | bcclaywell |
---|---|
date | Mon, 12 Oct 2015 17:43:33 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d67268158946 |
---|---|
1 from __future__ import absolute_import | |
2 | |
3 import logging | |
4 import os | |
5 import tempfile | |
6 import re | |
7 | |
8 # TODO: Get this into six.moves.urllib.parse | |
9 try: | |
10 from urllib import parse as urllib_parse | |
11 except ImportError: | |
12 import urlparse as urllib_parse | |
13 | |
14 from pip.utils import rmtree, display_path | |
15 from pip.vcs import vcs, VersionControl | |
16 from pip.download import path_to_url | |
17 | |
18 | |
19 logger = logging.getLogger(__name__) | |
20 | |
21 | |
22 class Bazaar(VersionControl): | |
23 name = 'bzr' | |
24 dirname = '.bzr' | |
25 repo_name = 'branch' | |
26 schemes = ( | |
27 'bzr', 'bzr+http', 'bzr+https', 'bzr+ssh', 'bzr+sftp', 'bzr+ftp', | |
28 'bzr+lp', | |
29 ) | |
30 | |
31 def __init__(self, url=None, *args, **kwargs): | |
32 super(Bazaar, self).__init__(url, *args, **kwargs) | |
33 # Python >= 2.7.4, 3.3 doesn't have uses_fragment or non_hierarchical | |
34 # Register lp but do not expose as a scheme to support bzr+lp. | |
35 if getattr(urllib_parse, 'uses_fragment', None): | |
36 urllib_parse.uses_fragment.extend(['lp']) | |
37 urllib_parse.non_hierarchical.extend(['lp']) | |
38 | |
39 def export(self, location): | |
40 """ | |
41 Export the Bazaar repository at the url to the destination location | |
42 """ | |
43 temp_dir = tempfile.mkdtemp('-export', 'pip-') | |
44 self.unpack(temp_dir) | |
45 if os.path.exists(location): | |
46 # Remove the location to make sure Bazaar can export it correctly | |
47 rmtree(location) | |
48 try: | |
49 self.run_command(['export', location], cwd=temp_dir, | |
50 filter_stdout=self._filter, show_stdout=False) | |
51 finally: | |
52 rmtree(temp_dir) | |
53 | |
54 def switch(self, dest, url, rev_options): | |
55 self.run_command(['switch', url], cwd=dest) | |
56 | |
57 def update(self, dest, rev_options): | |
58 self.run_command(['pull', '-q'] + rev_options, cwd=dest) | |
59 | |
60 def obtain(self, dest): | |
61 url, rev = self.get_url_rev() | |
62 if rev: | |
63 rev_options = ['-r', rev] | |
64 rev_display = ' (to revision %s)' % rev | |
65 else: | |
66 rev_options = [] | |
67 rev_display = '' | |
68 if self.check_destination(dest, url, rev_options, rev_display): | |
69 logger.info( | |
70 'Checking out %s%s to %s', | |
71 url, | |
72 rev_display, | |
73 display_path(dest), | |
74 ) | |
75 self.run_command(['branch', '-q'] + rev_options + [url, dest]) | |
76 | |
77 def get_url_rev(self): | |
78 # hotfix the URL scheme after removing bzr+ from bzr+ssh:// readd it | |
79 url, rev = super(Bazaar, self).get_url_rev() | |
80 if url.startswith('ssh://'): | |
81 url = 'bzr+' + url | |
82 return url, rev | |
83 | |
84 def get_url(self, location): | |
85 urls = self.run_command(['info'], show_stdout=False, cwd=location) | |
86 for line in urls.splitlines(): | |
87 line = line.strip() | |
88 for x in ('checkout of branch: ', | |
89 'parent branch: '): | |
90 if line.startswith(x): | |
91 repo = line.split(x)[1] | |
92 if self._is_local_repository(repo): | |
93 return path_to_url(repo) | |
94 return repo | |
95 return None | |
96 | |
97 def get_revision(self, location): | |
98 revision = self.run_command( | |
99 ['revno'], show_stdout=False, cwd=location) | |
100 return revision.splitlines()[-1] | |
101 | |
102 def get_tag_revs(self, location): | |
103 tags = self.run_command( | |
104 ['tags'], show_stdout=False, cwd=location) | |
105 tag_revs = [] | |
106 for line in tags.splitlines(): | |
107 tags_match = re.search(r'([.\w-]+)\s*(.*)$', line) | |
108 if tags_match: | |
109 tag = tags_match.group(1) | |
110 rev = tags_match.group(2) | |
111 tag_revs.append((rev.strip(), tag.strip())) | |
112 return dict(tag_revs) | |
113 | |
114 def get_src_requirement(self, dist, location, find_tags): | |
115 repo = self.get_url(location) | |
116 if not repo: | |
117 return None | |
118 if not repo.lower().startswith('bzr:'): | |
119 repo = 'bzr+' + repo | |
120 egg_project_name = dist.egg_name().split('-', 1)[0] | |
121 current_rev = self.get_revision(location) | |
122 tag_revs = self.get_tag_revs(location) | |
123 | |
124 if current_rev in tag_revs: | |
125 # It's a tag | |
126 full_egg_name = '%s-%s' % (egg_project_name, tag_revs[current_rev]) | |
127 else: | |
128 full_egg_name = '%s-dev_r%s' % (dist.egg_name(), current_rev) | |
129 return '%s@%s#egg=%s' % (repo, current_rev, full_egg_name) | |
130 | |
131 | |
132 vcs.register(Bazaar) |