Some python syntax updates for the WML tools

This commit is contained in:
Alexander van Gessel 2013-07-26 15:37:50 +02:00
parent 7d9cae09be
commit d394f27afb
3 changed files with 19 additions and 19 deletions

View file

@ -361,7 +361,7 @@ Important Attributes:
def ancestors(self):
"""Return a list of tags enclosing this location, outermost first."""
return tuple(map(lambda x: x.element, self.scopes))
return tuple([x.element for x in self.scopes])
def hasNext(self):
"""Some loops may wish to check this method instead of calling next()

View file

@ -84,7 +84,7 @@ class Forest:
subtree = []
if os.path.isdir(dir): # So we skip .cfgs in a UMC mirror
os.path.walk(dir,
lambda arg, dir, names: subtree.extend(map(lambda x: os.path.normpath(os.path.join(dir, x)), names)),
lambda arg, dir, names: subtree.extend([os.path.normpath(os.path.join(dir, x)) for x in names]),
None)
# Always look at _main.cfg first
subtree.sort(lambda x, y: cmp(x, y) - 2*int(x.endswith("_main.cfg")) + 2*int(y.endswith("_main.cfg")))
@ -92,12 +92,12 @@ class Forest:
for i in range(len(self.forest)):
# Ignore version-control subdirectories and Emacs tempfiles
for dirkind in vc_directories + l10n_directories:
self.forest[i] = filter(lambda x: dirkind not in x, self.forest[i])
self.forest[i] = filter(lambda x: '.#' not in x, self.forest[i])
self.forest[i] = filter(lambda x: not os.path.isdir(x), self.forest[i])
self.forest[i] = [x for x in self.forest[i] if dirkind not in x]
self.forest[i] = [x for x in self.forest[i] if '.#' not in x]
self.forest[i] = [x for x in self.forest[i] if not os.path.isdir(x)]
if exclude:
self.forest[i] = filter(lambda x: not re.search(exclude, x), self.forest[i])
self.forest[i] = filter(lambda x: not x.endswith("-bak"), self.forest[i])
self.forest[i] = [x for x in self.forest[i] if not re.search(exclude, x)]
self.forest[i] = [x for x in self.forest[i] if not x.endswith("-bak")]
# Compute cliques (will be used later for visibility checks)
self.clique = {}
counter = 0
@ -286,7 +286,7 @@ class Reference:
def dump_references(self):
"Dump all known references to this definition."
for (file, refs) in self.references.items():
print " %s: %s" % (file, repr(map(lambda x: x[0], refs))[1:-1])
print " %s: %s" % (file, repr([x[0] for x in refs])[1:-1])
def __cmp__(self, other):
"Compare two documentation objects for place in the sort order."
# Major sort by file, minor by line number. This presumes that the
@ -301,7 +301,7 @@ class Reference:
copy = Reference(self.namespace, self.filename, self.lineno, self.docstring, self.args)
copy.undef = self.undef
for filename in self.references:
mis = filter(lambda (ln, a): a is not None and not argmatch(self.args, a), self.references[filename])
mis = [(ln,a) for (ln,a) in self.references[filename] if a is not None and not argmatch(self.args, a)]
if mis:
copy.references[filename] = mis
return copy
@ -488,7 +488,7 @@ class CrossRef:
def __init__(self, dirpath=[], exclude="", warnlevel=0, progress=False):
"Build cross-reference object from the specified filelist."
self.filelist = Forest(dirpath, exclude)
self.dirpath = filter(lambda x: not re.search(exclude, x), dirpath)
self.dirpath = [x for x in dirpath if not re.search(exclude, x)]
self.warnlevel = warnlevel
self.xref = {}
self.fileref = {}
@ -794,7 +794,7 @@ class Translations:
if not t in self.translations:
try:
self.translations[t] = Translation(textdomain, isocode, self.topdir)
except TranslationError, e:
except TranslationError as e:
sys.stderr.write(str(e))
self.translations[t] = Translation(textdomain, "C", self.topdir)
result = self.translations[t].get(key, default)

View file

@ -180,10 +180,10 @@ class CrossRefLister(CrossRef):
if mismatched:
print "# Mismatched references:"
for (n, m) in mismatched:
print "%s: macro %s(%s) has mismatches:" % (m, n, ", ".join(map(lambda x: "%s=%s" % (x, formaltype(x)), m.args)))
print "%s: macro %s(%s) has mismatches:" % (m, n, ", ".join(["{}={}".format(x, formaltype(x)) for x in m.args]))
for (file, refs) in m.references.items():
for (ln, args) in refs:
print '"%s", line %d: %s(%s) with signature (%s)' % (file, ln, n, ", ".join(args), ", ".join(map(lambda f, a: "%s=%s" % (f, actualtype(a)), m.args, args)))
print '"%s", line %d: %s(%s) with signature (%s)' % (file, ln, n, ", ".join(args), ", ".join(["{}={}".format(f, actualtype(a)) for f,a in zip(m.args, args)]))
def undersized(self):
"Report undersized images that cannot be safely overlaid on a hex."
@ -205,7 +205,7 @@ class CrossRefLister(CrossRef):
duplicate_latch = False
for (key, value) in self.unit_ids.items():
if len(value) > 1:
if exportonly and not filter(lambda x: self.exports(x.namespace), value):
if exportonly and not [x for x in value if self.exports(x.namespace)]:
continue
if not duplicate_latch:
print "# Duplicate IDs"
@ -225,9 +225,9 @@ class CrossRefLister(CrossRef):
if filename.endswith(branch):
if name not in already_seen:
already_seen.append(name)
print "%s: macro %s(%s):" % (defn, name, ", ".join(map(lambda x: "%s=%s" % (x, formaltype(x)), defn.args)))
print "%s: macro %s(%s):" % (defn, name, ", ".join(["{}={}".format(x, formaltype(x)) for x in defn.args]))
for (ln, args) in refs:
print '"%s", line %d: %s(%s) with signature (%s)' % (filename, ln, name, ", ".join(args), ", ".join(map(lambda f, a: "%s=%s" % (f, actualtype(a)), defn.args, args)))
print '"%s", line %d: %s(%s) with signature (%s)' % (filename, ln, name, ", ".join(args), ", ".join(["{}={}".format(f, actualtype(a)) for f,a in zip(defn.args, args)]))
def deflist(self, pred=None):
"List all resource definitions."
sorted = self.xref.keys()
@ -235,7 +235,7 @@ class CrossRefLister(CrossRef):
for name in sorted:
for defn in self.xref[name]:
if not pred or pred(name, defn):
print "macro", name, " ".join(map(lambda x: "%s=%s" % (x, formaltype(x)), defn.args))
print "macro", name, " ".join(["{}={}".format(x, formaltype(x)) for x in defn.args])
sorted = self.fileref.keys()
sorted.sort()
for name in sorted:
@ -279,7 +279,7 @@ class CrossRefLister(CrossRef):
"Deliver all macro help comments in HTML form."
# Bug: finds only the first definition of each macro in scope.
doclist = self.xref.keys()
doclist = filter(lambda x: self.xref[x][0].docstring.count("\n") > 1, doclist)
doclist = [x for x in doclist if self.xref[x][0].docstring.count("\n") > 1]
doclist.sort(lambda x, y: cmp(self.xref[x][0], self.xref[y][0]))
outstr = ""
filename = None
@ -461,7 +461,7 @@ Usage: macroscope [options] dirpath
hashcounts = {}
for (n, h) in collisions:
hashcounts[h] = hashcounts.get(h, 0) + 1
collisions = filter(lambda (n, h): hashcounts[h] > 1, collisions)
collisions = [(n,h) for (n,h) in collisions if hashcounts[h] > 1]
collisions.sort(lambda (n1, h1), (n2, h2): cmp(h1, h2))
lasthash = None
for (n, h) in collisions: