diff options
author | Chirayu Desai <cdesai@cyanogenmod.org> | 2013-03-01 19:14:38 +0530 |
---|---|---|
committer | Chirayu Desai <cdesai@cyanogenmod.org> | 2013-04-18 21:35:49 +0530 |
commit | 217ea7d2747e3098009afe0b389fc4b45f55ea5a (patch) | |
tree | 4ea2663a01fb22002ec6cd6ede9cb3babd89a692 | |
parent | fef4ae74e26efecf5c803793351b6c843eab4970 (diff) | |
download | git-repo-217ea7d2747e3098009afe0b389fc4b45f55ea5a.tar.gz |
Some fixes for supporting python3
* Fix imports.
* Use python3 syntax.
* Wrap map() calls with list().
* Use list() only wherever needed.
(Thanks Conley!)
* Fix dictionary iteration methods
(s/iteritems/items/).
* Make use of sorted() in appropriate places
* Use iterators directly in the loop.
* Don't use .keys() wherever it isn't needed.
* Use sys.maxsize instead of sys.maxint
TODO:
* Make repo work fully with python3. :)
Some of this was done by the '2to3' tool [1], by
applying the needed fixes in a way that doesn't
break compatibility with python2.
Links:
[1]: http://docs.python.org/2/library/2to3.html
Change-Id: Ibdf3bf9a530d716db905733cb9bfef83a48820f7
Signed-off-by: Chirayu Desai <cdesai@cyanogenmod.org>
-rw-r--r-- | command.py | 2 | ||||
-rw-r--r-- | git_config.py | 17 | ||||
-rw-r--r-- | git_refs.py | 9 | ||||
-rwxr-xr-x | main.py | 7 | ||||
-rw-r--r-- | manifest_xml.py | 64 | ||||
-rw-r--r-- | project.py | 49 | ||||
-rw-r--r-- | subcmds/__init__.py | 4 | ||||
-rw-r--r-- | subcmds/branches.py | 5 | ||||
-rw-r--r-- | subcmds/help.py | 10 | ||||
-rw-r--r-- | subcmds/info.py | 2 | ||||
-rw-r--r-- | subcmds/overview.py | 2 | ||||
-rw-r--r-- | subcmds/status.py | 11 | ||||
-rw-r--r-- | subcmds/sync.py | 31 | ||||
-rw-r--r-- | subcmds/upload.py | 7 |
14 files changed, 130 insertions, 90 deletions
@@ -140,7 +140,7 @@ class Command(object): | |||
140 | groups = [x for x in re.split(r'[,\s]+', groups) if x] | 140 | groups = [x for x in re.split(r'[,\s]+', groups) if x] |
141 | 141 | ||
142 | if not args: | 142 | if not args: |
143 | all_projects_list = all_projects.values() | 143 | all_projects_list = list(all_projects.values()) |
144 | derived_projects = {} | 144 | derived_projects = {} |
145 | for project in all_projects_list: | 145 | for project in all_projects_list: |
146 | if submodules_ok or project.sync_s: | 146 | if submodules_ok or project.sync_s: |
diff --git a/git_config.py b/git_config.py index 56cc6a24..9524df9b 100644 --- a/git_config.py +++ b/git_config.py | |||
@@ -14,8 +14,9 @@ | |||
14 | # limitations under the License. | 14 | # limitations under the License. |
15 | 15 | ||
16 | from __future__ import print_function | 16 | from __future__ import print_function |
17 | import cPickle | 17 | |
18 | import os | 18 | import os |
19 | import pickle | ||
19 | import re | 20 | import re |
20 | import subprocess | 21 | import subprocess |
21 | import sys | 22 | import sys |
@@ -262,7 +263,7 @@ class GitConfig(object): | |||
262 | Trace(': unpickle %s', self.file) | 263 | Trace(': unpickle %s', self.file) |
263 | fd = open(self._pickle, 'rb') | 264 | fd = open(self._pickle, 'rb') |
264 | try: | 265 | try: |
265 | return cPickle.load(fd) | 266 | return pickle.load(fd) |
266 | finally: | 267 | finally: |
267 | fd.close() | 268 | fd.close() |
268 | except EOFError: | 269 | except EOFError: |
@@ -271,7 +272,7 @@ class GitConfig(object): | |||
271 | except IOError: | 272 | except IOError: |
272 | os.remove(self._pickle) | 273 | os.remove(self._pickle) |
273 | return None | 274 | return None |
274 | except cPickle.PickleError: | 275 | except pickle.PickleError: |
275 | os.remove(self._pickle) | 276 | os.remove(self._pickle) |
276 | return None | 277 | return None |
277 | 278 | ||
@@ -279,13 +280,13 @@ class GitConfig(object): | |||
279 | try: | 280 | try: |
280 | fd = open(self._pickle, 'wb') | 281 | fd = open(self._pickle, 'wb') |
281 | try: | 282 | try: |
282 | cPickle.dump(cache, fd, cPickle.HIGHEST_PROTOCOL) | 283 | pickle.dump(cache, fd, pickle.HIGHEST_PROTOCOL) |
283 | finally: | 284 | finally: |
284 | fd.close() | 285 | fd.close() |
285 | except IOError: | 286 | except IOError: |
286 | if os.path.exists(self._pickle): | 287 | if os.path.exists(self._pickle): |
287 | os.remove(self._pickle) | 288 | os.remove(self._pickle) |
288 | except cPickle.PickleError: | 289 | except pickle.PickleError: |
289 | if os.path.exists(self._pickle): | 290 | if os.path.exists(self._pickle): |
290 | os.remove(self._pickle) | 291 | os.remove(self._pickle) |
291 | 292 | ||
@@ -537,8 +538,8 @@ class Remote(object): | |||
537 | self.url = self._Get('url') | 538 | self.url = self._Get('url') |
538 | self.review = self._Get('review') | 539 | self.review = self._Get('review') |
539 | self.projectname = self._Get('projectname') | 540 | self.projectname = self._Get('projectname') |
540 | self.fetch = map(RefSpec.FromString, | 541 | self.fetch = list(map(RefSpec.FromString, |
541 | self._Get('fetch', all_keys=True)) | 542 | self._Get('fetch', all_keys=True))) |
542 | self._review_url = None | 543 | self._review_url = None |
543 | 544 | ||
544 | def _InsteadOf(self): | 545 | def _InsteadOf(self): |
@@ -657,7 +658,7 @@ class Remote(object): | |||
657 | self._Set('url', self.url) | 658 | self._Set('url', self.url) |
658 | self._Set('review', self.review) | 659 | self._Set('review', self.review) |
659 | self._Set('projectname', self.projectname) | 660 | self._Set('projectname', self.projectname) |
660 | self._Set('fetch', map(str, self.fetch)) | 661 | self._Set('fetch', list(map(str, self.fetch))) |
661 | 662 | ||
662 | def _Set(self, key, value): | 663 | def _Set(self, key, value): |
663 | key = 'remote.%s.%s' % (self.name, key) | 664 | key = 'remote.%s.%s' % (self.name, key) |
diff --git a/git_refs.py b/git_refs.py index cfeffba9..4dd68769 100644 --- a/git_refs.py +++ b/git_refs.py | |||
@@ -66,7 +66,7 @@ class GitRefs(object): | |||
66 | def _NeedUpdate(self): | 66 | def _NeedUpdate(self): |
67 | Trace(': scan refs %s', self._gitdir) | 67 | Trace(': scan refs %s', self._gitdir) |
68 | 68 | ||
69 | for name, mtime in self._mtime.iteritems(): | 69 | for name, mtime in self._mtime.items(): |
70 | try: | 70 | try: |
71 | if mtime != os.path.getmtime(os.path.join(self._gitdir, name)): | 71 | if mtime != os.path.getmtime(os.path.join(self._gitdir, name)): |
72 | return True | 72 | return True |
@@ -89,7 +89,7 @@ class GitRefs(object): | |||
89 | attempts = 0 | 89 | attempts = 0 |
90 | while scan and attempts < 5: | 90 | while scan and attempts < 5: |
91 | scan_next = {} | 91 | scan_next = {} |
92 | for name, dest in scan.iteritems(): | 92 | for name, dest in scan.items(): |
93 | if dest in self._phyref: | 93 | if dest in self._phyref: |
94 | self._phyref[name] = self._phyref[dest] | 94 | self._phyref[name] = self._phyref[dest] |
95 | else: | 95 | else: |
@@ -108,6 +108,7 @@ class GitRefs(object): | |||
108 | return | 108 | return |
109 | try: | 109 | try: |
110 | for line in fd: | 110 | for line in fd: |
111 | line = str(line) | ||
111 | if line[0] == '#': | 112 | if line[0] == '#': |
112 | continue | 113 | continue |
113 | if line[0] == '^': | 114 | if line[0] == '^': |
@@ -150,6 +151,10 @@ class GitRefs(object): | |||
150 | finally: | 151 | finally: |
151 | fd.close() | 152 | fd.close() |
152 | 153 | ||
154 | try: | ||
155 | ref_id = ref_id.decode() | ||
156 | except AttributeError: | ||
157 | pass | ||
153 | if not ref_id: | 158 | if not ref_id: |
154 | return | 159 | return |
155 | ref_id = ref_id[:-1] | 160 | ref_id = ref_id[:-1] |
@@ -50,6 +50,11 @@ from pager import RunPager | |||
50 | 50 | ||
51 | from subcmds import all_commands | 51 | from subcmds import all_commands |
52 | 52 | ||
53 | try: | ||
54 | input = raw_input | ||
55 | except NameError: | ||
56 | pass | ||
57 | |||
53 | global_options = optparse.OptionParser( | 58 | global_options = optparse.OptionParser( |
54 | usage="repo [-p|--paginate|--no-pager] COMMAND [ARGS]" | 59 | usage="repo [-p|--paginate|--no-pager] COMMAND [ARGS]" |
55 | ) | 60 | ) |
@@ -286,7 +291,7 @@ def _AddPasswordFromUserInput(handler, msg, req): | |||
286 | if user is None: | 291 | if user is None: |
287 | print(msg) | 292 | print(msg) |
288 | try: | 293 | try: |
289 | user = raw_input('User: ') | 294 | user = input('User: ') |
290 | password = getpass.getpass() | 295 | password = getpass.getpass() |
291 | except KeyboardInterrupt: | 296 | except KeyboardInterrupt: |
292 | return | 297 | return |
diff --git a/manifest_xml.py b/manifest_xml.py index 51d51b95..cc441dc8 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
@@ -18,7 +18,15 @@ import itertools | |||
18 | import os | 18 | import os |
19 | import re | 19 | import re |
20 | import sys | 20 | import sys |
21 | import urlparse | 21 | try: |
22 | # For python3 | ||
23 | import urllib.parse | ||
24 | except ImportError: | ||
25 | # For python2 | ||
26 | import imp | ||
27 | import urlparse | ||
28 | urllib = imp.new_module('urllib') | ||
29 | urllib.parse = urlparse | ||
22 | import xml.dom.minidom | 30 | import xml.dom.minidom |
23 | 31 | ||
24 | from git_config import GitConfig | 32 | from git_config import GitConfig |
@@ -30,8 +38,8 @@ MANIFEST_FILE_NAME = 'manifest.xml' | |||
30 | LOCAL_MANIFEST_NAME = 'local_manifest.xml' | 38 | LOCAL_MANIFEST_NAME = 'local_manifest.xml' |
31 | LOCAL_MANIFESTS_DIR_NAME = 'local_manifests' | 39 | LOCAL_MANIFESTS_DIR_NAME = 'local_manifests' |
32 | 40 | ||
33 | urlparse.uses_relative.extend(['ssh', 'git']) | 41 | urllib.parse.uses_relative.extend(['ssh', 'git']) |
34 | urlparse.uses_netloc.extend(['ssh', 'git']) | 42 | urllib.parse.uses_netloc.extend(['ssh', 'git']) |
35 | 43 | ||
36 | class _Default(object): | 44 | class _Default(object): |
37 | """Project defaults within the manifest.""" | 45 | """Project defaults within the manifest.""" |
@@ -73,7 +81,7 @@ class _XmlRemote(object): | |||
73 | # ie, if manifestUrl is of the form <hostname:port> | 81 | # ie, if manifestUrl is of the form <hostname:port> |
74 | if manifestUrl.find(':') != manifestUrl.find('/') - 1: | 82 | if manifestUrl.find(':') != manifestUrl.find('/') - 1: |
75 | manifestUrl = 'gopher://' + manifestUrl | 83 | manifestUrl = 'gopher://' + manifestUrl |
76 | url = urlparse.urljoin(manifestUrl, url) | 84 | url = urllib.parse.urljoin(manifestUrl, url) |
77 | url = re.sub(r'^gopher://', '', url) | 85 | url = re.sub(r'^gopher://', '', url) |
78 | if p: | 86 | if p: |
79 | url = 'persistent-' + url | 87 | url = 'persistent-' + url |
@@ -162,10 +170,8 @@ class XmlManifest(object): | |||
162 | notice_element.appendChild(doc.createTextNode(indented_notice)) | 170 | notice_element.appendChild(doc.createTextNode(indented_notice)) |
163 | 171 | ||
164 | d = self.default | 172 | d = self.default |
165 | sort_remotes = list(self.remotes.keys()) | ||
166 | sort_remotes.sort() | ||
167 | 173 | ||
168 | for r in sort_remotes: | 174 | for r in sorted(self.remotes): |
169 | self._RemoteToXml(self.remotes[r], doc, root) | 175 | self._RemoteToXml(self.remotes[r], doc, root) |
170 | if self.remotes: | 176 | if self.remotes: |
171 | root.appendChild(doc.createTextNode('')) | 177 | root.appendChild(doc.createTextNode('')) |
@@ -257,12 +263,11 @@ class XmlManifest(object): | |||
257 | e.setAttribute('sync-s', 'true') | 263 | e.setAttribute('sync-s', 'true') |
258 | 264 | ||
259 | if p.subprojects: | 265 | if p.subprojects: |
260 | sort_projects = [subp.name for subp in p.subprojects] | 266 | sort_projects = list(sorted([subp.name for subp in p.subprojects])) |
261 | sort_projects.sort() | ||
262 | output_projects(p, e, sort_projects) | 267 | output_projects(p, e, sort_projects) |
263 | 268 | ||
264 | sort_projects = [key for key in self.projects.keys() | 269 | sort_projects = list(sorted([key for key, value in self.projects.items() |
265 | if not self.projects[key].parent] | 270 | if not value.parent])) |
266 | sort_projects.sort() | 271 | sort_projects.sort() |
267 | output_projects(None, root, sort_projects) | 272 | output_projects(None, root, sort_projects) |
268 | 273 | ||
@@ -386,9 +391,8 @@ class XmlManifest(object): | |||
386 | name = self._reqatt(node, 'name') | 391 | name = self._reqatt(node, 'name') |
387 | fp = os.path.join(include_root, name) | 392 | fp = os.path.join(include_root, name) |
388 | if not os.path.isfile(fp): | 393 | if not os.path.isfile(fp): |
389 | raise ManifestParseError, \ | 394 | raise ManifestParseError("include %s doesn't exist or isn't a file" |
390 | "include %s doesn't exist or isn't a file" % \ | 395 | % (name,)) |
391 | (name,) | ||
392 | try: | 396 | try: |
393 | nodes.extend(self._ParseManifestXml(fp, include_root)) | 397 | nodes.extend(self._ParseManifestXml(fp, include_root)) |
394 | # should isolate this to the exact exception, but that's | 398 | # should isolate this to the exact exception, but that's |
@@ -494,7 +498,7 @@ class XmlManifest(object): | |||
494 | name = None | 498 | name = None |
495 | m_url = m.GetRemote(m.remote.name).url | 499 | m_url = m.GetRemote(m.remote.name).url |
496 | if m_url.endswith('/.git'): | 500 | if m_url.endswith('/.git'): |
497 | raise ManifestParseError, 'refusing to mirror %s' % m_url | 501 | raise ManifestParseError('refusing to mirror %s' % m_url) |
498 | 502 | ||
499 | if self._default and self._default.remote: | 503 | if self._default and self._default.remote: |
500 | url = self._default.remote.resolvedFetchUrl | 504 | url = self._default.remote.resolvedFetchUrl |
@@ -588,7 +592,7 @@ class XmlManifest(object): | |||
588 | 592 | ||
589 | # Figure out minimum indentation, skipping the first line (the same line | 593 | # Figure out minimum indentation, skipping the first line (the same line |
590 | # as the <notice> tag)... | 594 | # as the <notice> tag)... |
591 | minIndent = sys.maxint | 595 | minIndent = sys.maxsize |
592 | lines = notice.splitlines() | 596 | lines = notice.splitlines() |
593 | for line in lines[1:]: | 597 | for line in lines[1:]: |
594 | lstrippedLine = line.lstrip() | 598 | lstrippedLine = line.lstrip() |
@@ -627,25 +631,22 @@ class XmlManifest(object): | |||
627 | if remote is None: | 631 | if remote is None: |
628 | remote = self._default.remote | 632 | remote = self._default.remote |
629 | if remote is None: | 633 | if remote is None: |
630 | raise ManifestParseError, \ | 634 | raise ManifestParseError("no remote for project %s within %s" % |
631 | "no remote for project %s within %s" % \ | 635 | (name, self.manifestFile)) |
632 | (name, self.manifestFile) | ||
633 | 636 | ||
634 | revisionExpr = node.getAttribute('revision') | 637 | revisionExpr = node.getAttribute('revision') |
635 | if not revisionExpr: | 638 | if not revisionExpr: |
636 | revisionExpr = self._default.revisionExpr | 639 | revisionExpr = self._default.revisionExpr |
637 | if not revisionExpr: | 640 | if not revisionExpr: |
638 | raise ManifestParseError, \ | 641 | raise ManifestParseError("no revision for project %s within %s" % |
639 | "no revision for project %s within %s" % \ | 642 | (name, self.manifestFile)) |
640 | (name, self.manifestFile) | ||
641 | 643 | ||
642 | path = node.getAttribute('path') | 644 | path = node.getAttribute('path') |
643 | if not path: | 645 | if not path: |
644 | path = name | 646 | path = name |
645 | if path.startswith('/'): | 647 | if path.startswith('/'): |
646 | raise ManifestParseError, \ | 648 | raise ManifestParseError("project %s path cannot be absolute in %s" % |
647 | "project %s path cannot be absolute in %s" % \ | 649 | (name, self.manifestFile)) |
648 | (name, self.manifestFile) | ||
649 | 650 | ||
650 | rebase = node.getAttribute('rebase') | 651 | rebase = node.getAttribute('rebase') |
651 | if not rebase: | 652 | if not rebase: |
@@ -764,7 +765,8 @@ class XmlManifest(object): | |||
764 | except ManifestParseError: | 765 | except ManifestParseError: |
765 | keep = "true" | 766 | keep = "true" |
766 | if keep != "true" and keep != "false": | 767 | if keep != "true" and keep != "false": |
767 | raise ManifestParseError, "optional \"keep\" attribute must be \"true\" or \"false\"" | 768 | raise ManifestParseError('optional "keep" attribute must be ' |
769 | '"true" or "false"') | ||
768 | project.AddAnnotation(name, value, keep) | 770 | project.AddAnnotation(name, value, keep) |
769 | 771 | ||
770 | def _get_remote(self, node): | 772 | def _get_remote(self, node): |
@@ -774,9 +776,8 @@ class XmlManifest(object): | |||
774 | 776 | ||
775 | v = self._remotes.get(name) | 777 | v = self._remotes.get(name) |
776 | if not v: | 778 | if not v: |
777 | raise ManifestParseError, \ | 779 | raise ManifestParseError("remote %s not defined in %s" % |
778 | "remote %s not defined in %s" % \ | 780 | (name, self.manifestFile)) |
779 | (name, self.manifestFile) | ||
780 | return v | 781 | return v |
781 | 782 | ||
782 | def _reqatt(self, node, attname): | 783 | def _reqatt(self, node, attname): |
@@ -785,7 +786,6 @@ class XmlManifest(object): | |||
785 | """ | 786 | """ |
786 | v = node.getAttribute(attname) | 787 | v = node.getAttribute(attname) |
787 | if not v: | 788 | if not v: |
788 | raise ManifestParseError, \ | 789 | raise ManifestParseError("no %s in <%s> within %s" % |
789 | "no %s in <%s> within %s" % \ | 790 | (attname, node.nodeName, self.manifestFile)) |
790 | (attname, node.nodeName, self.manifestFile) | ||
791 | return v | 791 | return v |
@@ -36,6 +36,11 @@ from trace import IsTrace, Trace | |||
36 | 36 | ||
37 | from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M | 37 | from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M |
38 | 38 | ||
39 | try: | ||
40 | input = raw_input | ||
41 | except NameError: | ||
42 | pass | ||
43 | |||
39 | def _lwrite(path, content): | 44 | def _lwrite(path, content): |
40 | lock = '%s.lock' % path | 45 | lock = '%s.lock' % path |
41 | 46 | ||
@@ -78,7 +83,7 @@ def _ProjectHooks(): | |||
78 | if _project_hook_list is None: | 83 | if _project_hook_list is None: |
79 | d = os.path.abspath(os.path.dirname(__file__)) | 84 | d = os.path.abspath(os.path.dirname(__file__)) |
80 | d = os.path.join(d , 'hooks') | 85 | d = os.path.join(d , 'hooks') |
81 | _project_hook_list = map(lambda x: os.path.join(d, x), os.listdir(d)) | 86 | _project_hook_list = [os.path.join(d, x) for x in os.listdir(d)] |
82 | return _project_hook_list | 87 | return _project_hook_list |
83 | 88 | ||
84 | 89 | ||
@@ -361,7 +366,7 @@ class RepoHook(object): | |||
361 | 'Do you want to allow this script to run ' | 366 | 'Do you want to allow this script to run ' |
362 | '(yes/yes-never-ask-again/NO)? ') % ( | 367 | '(yes/yes-never-ask-again/NO)? ') % ( |
363 | self._GetMustVerb(), self._script_fullpath) | 368 | self._GetMustVerb(), self._script_fullpath) |
364 | response = raw_input(prompt).lower() | 369 | response = input(prompt).lower() |
365 | print() | 370 | print() |
366 | 371 | ||
367 | # User is doing a one-time approval. | 372 | # User is doing a one-time approval. |
@@ -646,7 +651,7 @@ class Project(object): | |||
646 | all_refs = self._allrefs | 651 | all_refs = self._allrefs |
647 | heads = {} | 652 | heads = {} |
648 | 653 | ||
649 | for name, ref_id in all_refs.iteritems(): | 654 | for name, ref_id in all_refs.items(): |
650 | if name.startswith(R_HEADS): | 655 | if name.startswith(R_HEADS): |
651 | name = name[len(R_HEADS):] | 656 | name = name[len(R_HEADS):] |
652 | b = self.GetBranch(name) | 657 | b = self.GetBranch(name) |
@@ -655,7 +660,7 @@ class Project(object): | |||
655 | b.revision = ref_id | 660 | b.revision = ref_id |
656 | heads[name] = b | 661 | heads[name] = b |
657 | 662 | ||
658 | for name, ref_id in all_refs.iteritems(): | 663 | for name, ref_id in all_refs.items(): |
659 | if name.startswith(R_PUB): | 664 | if name.startswith(R_PUB): |
660 | name = name[len(R_PUB):] | 665 | name = name[len(R_PUB):] |
661 | b = heads.get(name) | 666 | b = heads.get(name) |
@@ -761,10 +766,7 @@ class Project(object): | |||
761 | paths.extend(df.keys()) | 766 | paths.extend(df.keys()) |
762 | paths.extend(do) | 767 | paths.extend(do) |
763 | 768 | ||
764 | paths = list(set(paths)) | 769 | for p in sorted(set(paths)): |
765 | paths.sort() | ||
766 | |||
767 | for p in paths: | ||
768 | try: | 770 | try: |
769 | i = di[p] | 771 | i = di[p] |
770 | except KeyError: | 772 | except KeyError: |
@@ -856,13 +858,13 @@ class Project(object): | |||
856 | all_refs = self._allrefs | 858 | all_refs = self._allrefs |
857 | heads = set() | 859 | heads = set() |
858 | canrm = {} | 860 | canrm = {} |
859 | for name, ref_id in all_refs.iteritems(): | 861 | for name, ref_id in all_refs.items(): |
860 | if name.startswith(R_HEADS): | 862 | if name.startswith(R_HEADS): |
861 | heads.add(name) | 863 | heads.add(name) |
862 | elif name.startswith(R_PUB): | 864 | elif name.startswith(R_PUB): |
863 | canrm[name] = ref_id | 865 | canrm[name] = ref_id |
864 | 866 | ||
865 | for name, ref_id in canrm.iteritems(): | 867 | for name, ref_id in canrm.items(): |
866 | n = name[len(R_PUB):] | 868 | n = name[len(R_PUB):] |
867 | if R_HEADS + n not in heads: | 869 | if R_HEADS + n not in heads: |
868 | self.bare_git.DeleteRef(name, ref_id) | 870 | self.bare_git.DeleteRef(name, ref_id) |
@@ -873,14 +875,14 @@ class Project(object): | |||
873 | heads = {} | 875 | heads = {} |
874 | pubed = {} | 876 | pubed = {} |
875 | 877 | ||
876 | for name, ref_id in self._allrefs.iteritems(): | 878 | for name, ref_id in self._allrefs.items(): |
877 | if name.startswith(R_HEADS): | 879 | if name.startswith(R_HEADS): |
878 | heads[name[len(R_HEADS):]] = ref_id | 880 | heads[name[len(R_HEADS):]] = ref_id |
879 | elif name.startswith(R_PUB): | 881 | elif name.startswith(R_PUB): |
880 | pubed[name[len(R_PUB):]] = ref_id | 882 | pubed[name[len(R_PUB):]] = ref_id |
881 | 883 | ||
882 | ready = [] | 884 | ready = [] |
883 | for branch, ref_id in heads.iteritems(): | 885 | for branch, ref_id in heads.items(): |
884 | if branch in pubed and pubed[branch] == ref_id: | 886 | if branch in pubed and pubed[branch] == ref_id: |
885 | continue | 887 | continue |
886 | if selected_branch and branch != selected_branch: | 888 | if selected_branch and branch != selected_branch: |
@@ -1223,7 +1225,7 @@ class Project(object): | |||
1223 | cmd = ['fetch', remote.name] | 1225 | cmd = ['fetch', remote.name] |
1224 | cmd.append('refs/changes/%2.2d/%d/%d' \ | 1226 | cmd.append('refs/changes/%2.2d/%d/%d' \ |
1225 | % (change_id % 100, change_id, patch_id)) | 1227 | % (change_id % 100, change_id, patch_id)) |
1226 | cmd.extend(map(str, remote.fetch)) | 1228 | cmd.extend(list(map(str, remote.fetch))) |
1227 | if GitCommand(self, cmd, bare=True).Wait() != 0: | 1229 | if GitCommand(self, cmd, bare=True).Wait() != 0: |
1228 | return None | 1230 | return None |
1229 | return DownloadedChange(self, | 1231 | return DownloadedChange(self, |
@@ -1612,7 +1614,7 @@ class Project(object): | |||
1612 | ids = set(all_refs.values()) | 1614 | ids = set(all_refs.values()) |
1613 | tmp = set() | 1615 | tmp = set() |
1614 | 1616 | ||
1615 | for r, ref_id in GitRefs(ref_dir).all.iteritems(): | 1617 | for r, ref_id in GitRefs(ref_dir).all.items(): |
1616 | if r not in all_refs: | 1618 | if r not in all_refs: |
1617 | if r.startswith(R_TAGS) or remote.WritesTo(r): | 1619 | if r.startswith(R_TAGS) or remote.WritesTo(r): |
1618 | all_refs[r] = ref_id | 1620 | all_refs[r] = ref_id |
@@ -1627,13 +1629,10 @@ class Project(object): | |||
1627 | ids.add(ref_id) | 1629 | ids.add(ref_id) |
1628 | tmp.add(r) | 1630 | tmp.add(r) |
1629 | 1631 | ||
1630 | ref_names = list(all_refs.keys()) | ||
1631 | ref_names.sort() | ||
1632 | |||
1633 | tmp_packed = '' | 1632 | tmp_packed = '' |
1634 | old_packed = '' | 1633 | old_packed = '' |
1635 | 1634 | ||
1636 | for r in ref_names: | 1635 | for r in sorted(all_refs): |
1637 | line = '%s %s\n' % (all_refs[r], r) | 1636 | line = '%s %s\n' % (all_refs[r], r) |
1638 | tmp_packed += line | 1637 | tmp_packed += line |
1639 | if r not in tmp: | 1638 | if r not in tmp: |
@@ -1666,7 +1665,7 @@ class Project(object): | |||
1666 | cmd.append('--no-tags') | 1665 | cmd.append('--no-tags') |
1667 | else: | 1666 | else: |
1668 | cmd.append('--tags') | 1667 | cmd.append('--tags') |
1669 | cmd.append((u'+refs/heads/*:') + remote.ToLocal('refs/heads/*')) | 1668 | cmd.append(str((u'+refs/heads/*:') + remote.ToLocal('refs/heads/*'))) |
1670 | elif tag_name is not None: | 1669 | elif tag_name is not None: |
1671 | cmd.append('tag') | 1670 | cmd.append('tag') |
1672 | cmd.append(tag_name) | 1671 | cmd.append(tag_name) |
@@ -1676,7 +1675,7 @@ class Project(object): | |||
1676 | branch = self.upstream | 1675 | branch = self.upstream |
1677 | if branch.startswith(R_HEADS): | 1676 | if branch.startswith(R_HEADS): |
1678 | branch = branch[len(R_HEADS):] | 1677 | branch = branch[len(R_HEADS):] |
1679 | cmd.append((u'+refs/heads/%s:' % branch) + remote.ToLocal('refs/heads/%s' % branch)) | 1678 | cmd.append(str((u'+refs/heads/%s:' % branch) + remote.ToLocal('refs/heads/%s' % branch))) |
1680 | 1679 | ||
1681 | ok = False | 1680 | ok = False |
1682 | for _i in range(2): | 1681 | for _i in range(2): |
@@ -2102,6 +2101,10 @@ class Project(object): | |||
2102 | line = fd.read() | 2101 | line = fd.read() |
2103 | finally: | 2102 | finally: |
2104 | fd.close() | 2103 | fd.close() |
2104 | try: | ||
2105 | line = line.decode() | ||
2106 | except AttributeError: | ||
2107 | pass | ||
2105 | if line.startswith('ref: '): | 2108 | if line.startswith('ref: '): |
2106 | return line[5:-1] | 2109 | return line[5:-1] |
2107 | return line[:-1] | 2110 | return line[:-1] |
@@ -2195,7 +2198,7 @@ class Project(object): | |||
2195 | if not git_require((1, 7, 2)): | 2198 | if not git_require((1, 7, 2)): |
2196 | raise ValueError('cannot set config on command line for %s()' | 2199 | raise ValueError('cannot set config on command line for %s()' |
2197 | % name) | 2200 | % name) |
2198 | for k, v in config.iteritems(): | 2201 | for k, v in config.items(): |
2199 | cmdv.append('-c') | 2202 | cmdv.append('-c') |
2200 | cmdv.append('%s=%s' % (k, v)) | 2203 | cmdv.append('%s=%s' % (k, v)) |
2201 | cmdv.append(name) | 2204 | cmdv.append(name) |
@@ -2211,6 +2214,10 @@ class Project(object): | |||
2211 | name, | 2214 | name, |
2212 | p.stderr)) | 2215 | p.stderr)) |
2213 | r = p.stdout | 2216 | r = p.stdout |
2217 | try: | ||
2218 | r = r.decode() | ||
2219 | except AttributeError: | ||
2220 | pass | ||
2214 | if r.endswith('\n') and r.index('\n') == len(r) - 1: | 2221 | if r.endswith('\n') and r.index('\n') == len(r) - 1: |
2215 | return r[:-1] | 2222 | return r[:-1] |
2216 | return r | 2223 | return r |
diff --git a/subcmds/__init__.py b/subcmds/__init__.py index 1fac802e..84efb4de 100644 --- a/subcmds/__init__.py +++ b/subcmds/__init__.py | |||
@@ -38,8 +38,8 @@ for py in os.listdir(my_dir): | |||
38 | try: | 38 | try: |
39 | cmd = getattr(mod, clsn)() | 39 | cmd = getattr(mod, clsn)() |
40 | except AttributeError: | 40 | except AttributeError: |
41 | raise SyntaxError, '%s/%s does not define class %s' % ( | 41 | raise SyntaxError('%s/%s does not define class %s' % ( |
42 | __name__, py, clsn) | 42 | __name__, py, clsn)) |
43 | 43 | ||
44 | name = name.replace('_', '-') | 44 | name = name.replace('_', '-') |
45 | cmd.NAME = name | 45 | cmd.NAME = name |
diff --git a/subcmds/branches.py b/subcmds/branches.py index 06d45abe..c2e7c4b9 100644 --- a/subcmds/branches.py +++ b/subcmds/branches.py | |||
@@ -98,14 +98,13 @@ is shown, then the branch appears in all projects. | |||
98 | project_cnt = len(projects) | 98 | project_cnt = len(projects) |
99 | 99 | ||
100 | for project in projects: | 100 | for project in projects: |
101 | for name, b in project.GetBranches().iteritems(): | 101 | for name, b in project.GetBranches().items(): |
102 | b.project = project | 102 | b.project = project |
103 | if name not in all_branches: | 103 | if name not in all_branches: |
104 | all_branches[name] = BranchInfo(name) | 104 | all_branches[name] = BranchInfo(name) |
105 | all_branches[name].add(b) | 105 | all_branches[name].add(b) |
106 | 106 | ||
107 | names = all_branches.keys() | 107 | names = list(sorted(all_branches)) |
108 | names.sort() | ||
109 | 108 | ||
110 | if not names: | 109 | if not names: |
111 | print(' (no branches)', file=sys.stderr) | 110 | print(' (no branches)', file=sys.stderr) |
diff --git a/subcmds/help.py b/subcmds/help.py index 78428825..4aa3f863 100644 --- a/subcmds/help.py +++ b/subcmds/help.py | |||
@@ -34,8 +34,7 @@ Displays detailed usage information about a command. | |||
34 | def _PrintAllCommands(self): | 34 | def _PrintAllCommands(self): |
35 | print('usage: repo COMMAND [ARGS]') | 35 | print('usage: repo COMMAND [ARGS]') |
36 | print('The complete list of recognized repo commands are:') | 36 | print('The complete list of recognized repo commands are:') |
37 | commandNames = self.commands.keys() | 37 | commandNames = list(sorted(self.commands)) |
38 | commandNames.sort() | ||
39 | 38 | ||
40 | maxlen = 0 | 39 | maxlen = 0 |
41 | for name in commandNames: | 40 | for name in commandNames: |
@@ -55,10 +54,9 @@ Displays detailed usage information about a command. | |||
55 | def _PrintCommonCommands(self): | 54 | def _PrintCommonCommands(self): |
56 | print('usage: repo COMMAND [ARGS]') | 55 | print('usage: repo COMMAND [ARGS]') |
57 | print('The most commonly used repo commands are:') | 56 | print('The most commonly used repo commands are:') |
58 | commandNames = [name | 57 | commandNames = list(sorted([name |
59 | for name in self.commands.keys() | 58 | for name, command in self.commands.items() |
60 | if self.commands[name].common] | 59 | if command.common])) |
61 | commandNames.sort() | ||
62 | 60 | ||
63 | maxlen = 0 | 61 | maxlen = 0 |
64 | for name in commandNames: | 62 | for name in commandNames: |
diff --git a/subcmds/info.py b/subcmds/info.py index 325874b5..c10e56cd 100644 --- a/subcmds/info.py +++ b/subcmds/info.py | |||
@@ -163,7 +163,7 @@ class Info(PagedCommand): | |||
163 | all_branches = [] | 163 | all_branches = [] |
164 | for project in self.GetProjects(args): | 164 | for project in self.GetProjects(args): |
165 | br = [project.GetUploadableBranch(x) | 165 | br = [project.GetUploadableBranch(x) |
166 | for x in project.GetBranches().keys()] | 166 | for x in project.GetBranches()] |
167 | br = [x for x in br if x] | 167 | br = [x for x in br if x] |
168 | if self.opt.current_branch: | 168 | if self.opt.current_branch: |
169 | br = [x for x in br if x.name == project.CurrentBranch] | 169 | br = [x for x in br if x.name == project.CurrentBranch] |
diff --git a/subcmds/overview.py b/subcmds/overview.py index 418459ae..eed8cf20 100644 --- a/subcmds/overview.py +++ b/subcmds/overview.py | |||
@@ -42,7 +42,7 @@ are displayed. | |||
42 | all_branches = [] | 42 | all_branches = [] |
43 | for project in self.GetProjects(args): | 43 | for project in self.GetProjects(args): |
44 | br = [project.GetUploadableBranch(x) | 44 | br = [project.GetUploadableBranch(x) |
45 | for x in project.GetBranches().keys()] | 45 | for x in project.GetBranches()] |
46 | br = [x for x in br if x] | 46 | br = [x for x in br if x] |
47 | if opt.current_branch: | 47 | if opt.current_branch: |
48 | br = [x for x in br if x.name == project.CurrentBranch] | 48 | br = [x for x in br if x.name == project.CurrentBranch] |
diff --git a/subcmds/status.py b/subcmds/status.py index cce00c81..9810337f 100644 --- a/subcmds/status.py +++ b/subcmds/status.py | |||
@@ -21,10 +21,15 @@ except ImportError: | |||
21 | import dummy_threading as _threading | 21 | import dummy_threading as _threading |
22 | 22 | ||
23 | import glob | 23 | import glob |
24 | try: | ||
25 | # For python2 | ||
26 | import StringIO as io | ||
27 | except ImportError: | ||
28 | # For python3 | ||
29 | import io | ||
24 | import itertools | 30 | import itertools |
25 | import os | 31 | import os |
26 | import sys | 32 | import sys |
27 | import StringIO | ||
28 | 33 | ||
29 | from color import Coloring | 34 | from color import Coloring |
30 | 35 | ||
@@ -142,7 +147,7 @@ the following meanings: | |||
142 | for project in all_projects: | 147 | for project in all_projects: |
143 | sem.acquire() | 148 | sem.acquire() |
144 | 149 | ||
145 | class BufList(StringIO.StringIO): | 150 | class BufList(io.StringIO): |
146 | def dump(self, ostream): | 151 | def dump(self, ostream): |
147 | for entry in self.buflist: | 152 | for entry in self.buflist: |
148 | ostream.write(entry) | 153 | ostream.write(entry) |
@@ -182,7 +187,7 @@ the following meanings: | |||
182 | try: | 187 | try: |
183 | os.chdir(self.manifest.topdir) | 188 | os.chdir(self.manifest.topdir) |
184 | 189 | ||
185 | outstring = StringIO.StringIO() | 190 | outstring = io.StringIO() |
186 | self._FindOrphans(glob.glob('.*') + \ | 191 | self._FindOrphans(glob.glob('.*') + \ |
187 | glob.glob('*'), \ | 192 | glob.glob('*'), \ |
188 | proj_dirs, proj_dirs_parents, outstring) | 193 | proj_dirs, proj_dirs_parents, outstring) |
diff --git a/subcmds/sync.py b/subcmds/sync.py index 42c5f915..8fb94885 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
@@ -24,8 +24,24 @@ import socket | |||
24 | import subprocess | 24 | import subprocess |
25 | import sys | 25 | import sys |
26 | import time | 26 | import time |
27 | import urlparse | 27 | try: |
28 | import xmlrpclib | 28 | # For python3 |
29 | import urllib.parse | ||
30 | except ImportError: | ||
31 | # For python2 | ||
32 | import imp | ||
33 | import urlparse | ||
34 | urllib = imp.new_module('urllib') | ||
35 | urllib.parse = urlparse | ||
36 | try: | ||
37 | # For python3 | ||
38 | import xmlrpc.client | ||
39 | except ImportError: | ||
40 | # For python2 | ||
41 | import imp | ||
42 | import xmlrpclib | ||
43 | xmlrpc = imp.new_module('xmlrpc') | ||
44 | xmlrpc.client = xmlrpclib | ||
29 | 45 | ||
30 | try: | 46 | try: |
31 | import threading as _threading | 47 | import threading as _threading |
@@ -498,7 +514,7 @@ later is required to fix a server side protocol bug. | |||
498 | file=sys.stderr) | 514 | file=sys.stderr) |
499 | else: | 515 | else: |
500 | try: | 516 | try: |
501 | parse_result = urlparse.urlparse(manifest_server) | 517 | parse_result = urllib.parse(manifest_server) |
502 | if parse_result.hostname: | 518 | if parse_result.hostname: |
503 | username, _account, password = \ | 519 | username, _account, password = \ |
504 | info.authenticators(parse_result.hostname) | 520 | info.authenticators(parse_result.hostname) |
@@ -516,7 +532,7 @@ later is required to fix a server side protocol bug. | |||
516 | 1) | 532 | 1) |
517 | 533 | ||
518 | try: | 534 | try: |
519 | server = xmlrpclib.Server(manifest_server) | 535 | server = xmlrpc.client.Server(manifest_server) |
520 | if opt.smart_sync: | 536 | if opt.smart_sync: |
521 | p = self.manifest.manifestProject | 537 | p = self.manifest.manifestProject |
522 | b = p.GetBranch(p.CurrentBranch) | 538 | b = p.GetBranch(p.CurrentBranch) |
@@ -525,8 +541,7 @@ later is required to fix a server side protocol bug. | |||
525 | branch = branch[len(R_HEADS):] | 541 | branch = branch[len(R_HEADS):] |
526 | 542 | ||
527 | env = os.environ.copy() | 543 | env = os.environ.copy() |
528 | if (env.has_key('TARGET_PRODUCT') and | 544 | if 'TARGET_PRODUCT' in env and 'TARGET_BUILD_VARIANT' in env: |
529 | env.has_key('TARGET_BUILD_VARIANT')): | ||
530 | target = '%s-%s' % (env['TARGET_PRODUCT'], | 545 | target = '%s-%s' % (env['TARGET_PRODUCT'], |
531 | env['TARGET_BUILD_VARIANT']) | 546 | env['TARGET_BUILD_VARIANT']) |
532 | [success, manifest_str] = server.GetApprovedManifest(branch, target) | 547 | [success, manifest_str] = server.GetApprovedManifest(branch, target) |
@@ -554,11 +569,11 @@ later is required to fix a server side protocol bug. | |||
554 | else: | 569 | else: |
555 | print('error: %s' % manifest_str, file=sys.stderr) | 570 | print('error: %s' % manifest_str, file=sys.stderr) |
556 | sys.exit(1) | 571 | sys.exit(1) |
557 | except (socket.error, IOError, xmlrpclib.Fault) as e: | 572 | except (socket.error, IOError, xmlrpc.client.Fault) as e: |
558 | print('error: cannot connect to manifest server %s:\n%s' | 573 | print('error: cannot connect to manifest server %s:\n%s' |
559 | % (self.manifest.manifest_server, e), file=sys.stderr) | 574 | % (self.manifest.manifest_server, e), file=sys.stderr) |
560 | sys.exit(1) | 575 | sys.exit(1) |
561 | except xmlrpclib.ProtocolError as e: | 576 | except xmlrpc.client.ProtocolError as e: |
562 | print('error: cannot connect to manifest server %s:\n%d %s' | 577 | print('error: cannot connect to manifest server %s:\n%d %s' |
563 | % (self.manifest.manifest_server, e.errcode, e.errmsg), | 578 | % (self.manifest.manifest_server, e.errcode, e.errmsg), |
564 | file=sys.stderr) | 579 | file=sys.stderr) |
diff --git a/subcmds/upload.py b/subcmds/upload.py index 48ee685c..a34938e5 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py | |||
@@ -23,6 +23,11 @@ from editor import Editor | |||
23 | from error import HookError, UploadError | 23 | from error import HookError, UploadError |
24 | from project import RepoHook | 24 | from project import RepoHook |
25 | 25 | ||
26 | try: | ||
27 | input = raw_input | ||
28 | except NameError: | ||
29 | pass | ||
30 | |||
26 | UNUSUAL_COMMIT_THRESHOLD = 5 | 31 | UNUSUAL_COMMIT_THRESHOLD = 5 |
27 | 32 | ||
28 | def _ConfirmManyUploads(multiple_branches=False): | 33 | def _ConfirmManyUploads(multiple_branches=False): |
@@ -33,7 +38,7 @@ def _ConfirmManyUploads(multiple_branches=False): | |||
33 | print('ATTENTION: You are uploading an unusually high number of commits.') | 38 | print('ATTENTION: You are uploading an unusually high number of commits.') |
34 | print('YOU PROBABLY DO NOT MEAN TO DO THIS. (Did you rebase across ' | 39 | print('YOU PROBABLY DO NOT MEAN TO DO THIS. (Did you rebase across ' |
35 | 'branches?)') | 40 | 'branches?)') |
36 | answer = raw_input("If you are sure you intend to do this, type 'yes': ").strip() | 41 | answer = input("If you are sure you intend to do this, type 'yes': ").strip() |
37 | return answer == "yes" | 42 | return answer == "yes" |
38 | 43 | ||
39 | def _die(fmt, *args): | 44 | def _die(fmt, *args): |