mirror of https://github.com/python/cpython.git
write(): A patch inspired by Tokio Kikuchi that sorts location entries
first by filename and then by line number. Closes SF patch #425821. Also, fixes a problem with duplicate entries.
This commit is contained in:
parent
8b0b8409ae
commit
6e972414be
|
@ -1,7 +1,7 @@
|
|||
#! /usr/bin/env python
|
||||
# Originally written by Barry Warsaw <bwarsaw@python.org>
|
||||
# Originally written by Barry Warsaw <barry@digicool.com>
|
||||
#
|
||||
# minimally patched to make it even more xgettext compatible
|
||||
# Minimally patched to make it even more xgettext compatible
|
||||
# by Peter Funk <pf@artcom-gmbh.de>
|
||||
|
||||
"""pygettext -- Python equivalent of xgettext(1)
|
||||
|
@ -313,7 +313,7 @@ def __addentry(self, msg, lineno=None):
|
|||
lineno = self.__lineno
|
||||
if not msg in self.__options.toexclude:
|
||||
entry = (self.__curfile, lineno)
|
||||
self.__messages.setdefault(msg, []).append(entry)
|
||||
self.__messages.setdefault(msg, {})[entry] = 1
|
||||
|
||||
def set_filename(self, filename):
|
||||
self.__curfile = filename
|
||||
|
@ -325,6 +325,11 @@ def write(self, fp):
|
|||
# generated by xgettext...
|
||||
print >> fp, pot_header % {'time': timestamp, 'version': __version__}
|
||||
for k, v in self.__messages.items():
|
||||
# k is the message string, v is a dictionary-set of (filename,
|
||||
# lineno) tuples. We want to sort the entries in v first by file
|
||||
# name and then by line number.
|
||||
v = v.keys()
|
||||
v.sort()
|
||||
if not options.writelocations:
|
||||
pass
|
||||
# location comments are different b/w Solaris and GNU:
|
||||
|
@ -444,8 +449,8 @@ class Options:
|
|||
options.toexclude = fp.readlines()
|
||||
fp.close()
|
||||
except IOError:
|
||||
sys.stderr.write(_("Can't read --exclude-file: %s") %
|
||||
options.excludefilename)
|
||||
print >> sys.stderr, _(
|
||||
"Can't read --exclude-file: %s") % options.excludefilename
|
||||
sys.exit(1)
|
||||
else:
|
||||
options.toexclude = []
|
||||
|
@ -468,8 +473,8 @@ class Options:
|
|||
try:
|
||||
tokenize.tokenize(fp.readline, eater)
|
||||
except tokenize.TokenError, e:
|
||||
sys.stderr.write('%s: %s, line %d, column %d\n' %
|
||||
(e[0], filename, e[1][0], e[1][1]))
|
||||
print >> sys.stderr, '%s: %s, line %d, column %d' % (
|
||||
e[0], filename, e[1][0], e[1][1])
|
||||
finally:
|
||||
if closep:
|
||||
fp.close()
|
||||
|
|
Loading…
Reference in New Issue