diff options
Diffstat (limited to 'manifest_xml.py')
-rw-r--r-- | manifest_xml.py | 64 |
1 files changed, 32 insertions, 32 deletions
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 |