Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Unified Diff: tools/pretty_vcproj.py

Issue 1454433002: Python 3 compatibility Base URL: https://chromium.googlesource.com/external/gyp.git@master
Patch Set: Rebase with master (4ec6c4e3a94bd04a6da2858163d40b2429b8aad1) Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« test/variables/commands/commands.gyp ('K') | « tools/pretty_sln.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/pretty_vcproj.py
diff --git a/tools/pretty_vcproj.py b/tools/pretty_vcproj.py
index 6099bd7cc4d8ccd61dd53f850f63f863189e576a..d6de73e34501722676eeb053e39ac8b5816f66f8 100755
--- a/tools/pretty_vcproj.py
+++ b/tools/pretty_vcproj.py
@@ -12,6 +12,8 @@
It outputs the resulting xml to stdout.
"""
+from __future__ import print_function
+
__author__ = 'nsylvain (Nicolas Sylvain)'
import os
@@ -24,44 +26,31 @@ REPLACEMENTS = dict()
ARGUMENTS = None
-class CmpTuple(object):
- """Compare function between 2 tuple."""
- def __call__(self, x, y):
- return cmp(x[0], y[0])
-
-
-class CmpNode(object):
- """Compare function between 2 xml nodes."""
-
- def __call__(self, x, y):
- def get_string(node):
- node_string = "node"
- node_string += node.nodeName
- if node.nodeValue:
- node_string += node.nodeValue
-
- if node.attributes:
- # We first sort by name, if present.
- node_string += node.getAttribute("Name")
-
- all_nodes = []
- for (name, value) in node.attributes.items():
- all_nodes.append((name, value))
+def GetNodeString(x):
+ node_string = "node"
+ node_string += node.nodeName
+ if node.nodeValue:
+ node_string += node.nodeValue
- all_nodes.sort(CmpTuple())
- for (name, value) in all_nodes:
- node_string += name
- node_string += value
+ if node.attributes:
+ # We first sort by name, if present.
+ node_string += node.getAttribute("Name")
- return node_string
+ all_nodes = []
+ for (name, value) in node.attributes.items():
+ all_nodes.append((name, value))
- return cmp(get_string(x), get_string(y))
+ all_nodes.sort(key=(lambda node: node[0]))
+ for (name, value) in all_nodes:
+ node_string += name
+ node_string += value
+ return node_string
def PrettyPrintNode(node, indent=0):
if node.nodeType == Node.TEXT_NODE:
if node.data.strip():
- print '%s%s' % (' '*indent, node.data.strip())
+ print('%s%s' % (' '*indent, node.data.strip()))
return
if node.childNodes:
@@ -73,23 +62,23 @@ def PrettyPrintNode(node, indent=0):
# Print the main tag
if attr_count == 0:
- print '%s<%s>' % (' '*indent, node.nodeName)
+ print('%s<%s>' % (' '*indent, node.nodeName))
else:
- print '%s<%s' % (' '*indent, node.nodeName)
+ print('%s<%s' % (' '*indent, node.nodeName))
all_attributes = []
for (name, value) in node.attributes.items():
all_attributes.append((name, value))
- all_attributes.sort(CmpTuple())
+ all_attributes.sort(key=(lambda attr: attr[0]))
for (name, value) in all_attributes:
- print '%s %s="%s"' % (' '*indent, name, value)
- print '%s>' % (' '*indent)
+ print('%s %s="%s"' % (' '*indent, name, value))
+ print('%s>' % (' '*indent))
if node.nodeValue:
- print '%s %s' % (' '*indent, node.nodeValue)
+ print('%s %s' % (' '*indent, node.nodeValue))
for sub_node in node.childNodes:
PrettyPrintNode(sub_node, indent=indent+2)
- print '%s</%s>' % (' '*indent, node.nodeName)
+ print('%s</%s>' % (' '*indent, node.nodeName))
def FlattenFilter(node):
@@ -186,7 +175,7 @@ def CleanupVcproj(node):
# Sort the list.
- node_array.sort(CmpNode())
+ node_array.sort(key=GetNodeString)
# Insert the nodes in the correct order.
for new_node in node_array:
« test/variables/commands/commands.gyp ('K') | « tools/pretty_sln.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698