Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/pip/vcs/mercurial.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 from pip.utils import display_path, rmtree | |
9 from pip.vcs import vcs, VersionControl | |
10 from pip.download import path_to_url | |
11 from pip._vendor.six.moves import configparser | |
12 | |
13 | |
14 logger = logging.getLogger(__name__) | |
15 | |
16 | |
17 class Mercurial(VersionControl): | |
18 name = 'hg' | |
19 dirname = '.hg' | |
20 repo_name = 'clone' | |
21 schemes = ('hg', 'hg+http', 'hg+https', 'hg+ssh', 'hg+static-http') | |
22 | |
23 def export(self, location): | |
24 """Export the Hg repository at the url to the destination location""" | |
25 temp_dir = tempfile.mkdtemp('-export', 'pip-') | |
26 self.unpack(temp_dir) | |
27 try: | |
28 self.run_command( | |
29 ['archive', location], | |
30 filter_stdout=self._filter, show_stdout=False, cwd=temp_dir) | |
31 finally: | |
32 rmtree(temp_dir) | |
33 | |
34 def switch(self, dest, url, rev_options): | |
35 repo_config = os.path.join(dest, self.dirname, 'hgrc') | |
36 config = configparser.SafeConfigParser() | |
37 try: | |
38 config.read(repo_config) | |
39 config.set('paths', 'default', url) | |
40 with open(repo_config, 'w') as config_file: | |
41 config.write(config_file) | |
42 except (OSError, configparser.NoSectionError) as exc: | |
43 logger.warning( | |
44 'Could not switch Mercurial repository to %s: %s', url, exc, | |
45 ) | |
46 else: | |
47 self.run_command(['update', '-q'] + rev_options, cwd=dest) | |
48 | |
49 def update(self, dest, rev_options): | |
50 self.run_command(['pull', '-q'], cwd=dest) | |
51 self.run_command(['update', '-q'] + rev_options, cwd=dest) | |
52 | |
53 def obtain(self, dest): | |
54 url, rev = self.get_url_rev() | |
55 if rev: | |
56 rev_options = [rev] | |
57 rev_display = ' (to revision %s)' % rev | |
58 else: | |
59 rev_options = [] | |
60 rev_display = '' | |
61 if self.check_destination(dest, url, rev_options, rev_display): | |
62 logger.info( | |
63 'Cloning hg %s%s to %s', | |
64 url, | |
65 rev_display, | |
66 display_path(dest), | |
67 ) | |
68 self.run_command(['clone', '--noupdate', '-q', url, dest]) | |
69 self.run_command(['update', '-q'] + rev_options, cwd=dest) | |
70 | |
71 def get_url(self, location): | |
72 url = self.run_command( | |
73 ['showconfig', 'paths.default'], | |
74 show_stdout=False, cwd=location).strip() | |
75 if self._is_local_repository(url): | |
76 url = path_to_url(url) | |
77 return url.strip() | |
78 | |
79 def get_tag_revs(self, location): | |
80 tags = self.run_command(['tags'], show_stdout=False, cwd=location) | |
81 tag_revs = [] | |
82 for line in tags.splitlines(): | |
83 tags_match = re.search(r'([\w\d\.-]+)\s*([\d]+):.*$', line) | |
84 if tags_match: | |
85 tag = tags_match.group(1) | |
86 rev = tags_match.group(2) | |
87 if "tip" != tag: | |
88 tag_revs.append((rev.strip(), tag.strip())) | |
89 return dict(tag_revs) | |
90 | |
91 def get_branch_revs(self, location): | |
92 branches = self.run_command( | |
93 ['branches'], show_stdout=False, cwd=location) | |
94 branch_revs = [] | |
95 for line in branches.splitlines(): | |
96 branches_match = re.search(r'([\w\d\.-]+)\s*([\d]+):.*$', line) | |
97 if branches_match: | |
98 branch = branches_match.group(1) | |
99 rev = branches_match.group(2) | |
100 if "default" != branch: | |
101 branch_revs.append((rev.strip(), branch.strip())) | |
102 return dict(branch_revs) | |
103 | |
104 def get_revision(self, location): | |
105 current_revision = self.run_command( | |
106 ['parents', '--template={rev}'], | |
107 show_stdout=False, cwd=location).strip() | |
108 return current_revision | |
109 | |
110 def get_revision_hash(self, location): | |
111 current_rev_hash = self.run_command( | |
112 ['parents', '--template={node}'], | |
113 show_stdout=False, cwd=location).strip() | |
114 return current_rev_hash | |
115 | |
116 def get_src_requirement(self, dist, location, find_tags): | |
117 repo = self.get_url(location) | |
118 if not repo.lower().startswith('hg:'): | |
119 repo = 'hg+' + repo | |
120 egg_project_name = dist.egg_name().split('-', 1)[0] | |
121 if not repo: | |
122 return None | |
123 current_rev = self.get_revision(location) | |
124 current_rev_hash = self.get_revision_hash(location) | |
125 tag_revs = self.get_tag_revs(location) | |
126 branch_revs = self.get_branch_revs(location) | |
127 if current_rev in tag_revs: | |
128 # It's a tag | |
129 full_egg_name = '%s-%s' % (egg_project_name, tag_revs[current_rev]) | |
130 elif current_rev in branch_revs: | |
131 # It's the tip of a branch | |
132 full_egg_name = '%s-%s' % ( | |
133 egg_project_name, | |
134 branch_revs[current_rev], | |
135 ) | |
136 else: | |
137 full_egg_name = '%s-dev' % egg_project_name | |
138 return '%s@%s#egg=%s' % (repo, current_rev_hash, full_egg_name) | |
139 | |
140 vcs.register(Mercurial) |