diff options
author | Barry Warsaw <barry@python.org> | 2001-05-21 19:35:20 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2001-05-21 19:35:20 (GMT) |
commit | 6e972414bec063ce953df9dea5a13239ac7e5604 (patch) | |
tree | 7ac6da434f15563e28f0704772c0ceaa7d79aeb2 | |
parent | 8b0b8409aedac3ca86648b685b773ae543f327e5 (diff) | |
download | cpython-6e972414bec063ce953df9dea5a13239ac7e5604.zip cpython-6e972414bec063ce953df9dea5a13239ac7e5604.tar.gz cpython-6e972414bec063ce953df9dea5a13239ac7e5604.tar.bz2 |
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.
-rwxr-xr-x | Tools/i18n/pygettext.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/Tools/i18n/pygettext.py b/Tools/i18n/pygettext.py index 275130f..41a0970 100755 --- a/Tools/i18n/pygettext.py +++ b/Tools/i18n/pygettext.py @@ -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 @@ class TokenEater: 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 @@ class TokenEater: # 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 @@ def main(): 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 @@ def main(): 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() |