From 6e972414bec063ce953df9dea5a13239ac7e5604 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Mon, 21 May 2001 19:35:20 +0000 Subject: [PATCH] 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. --- Tools/i18n/pygettext.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Tools/i18n/pygettext.py b/Tools/i18n/pygettext.py index 275130f23f3..41a0970647e 100755 --- a/Tools/i18n/pygettext.py +++ b/Tools/i18n/pygettext.py @@ -1,7 +1,7 @@ #! /usr/bin/env python -# Originally written by Barry Warsaw +# Originally written by Barry Warsaw # -# minimally patched to make it even more xgettext compatible +# Minimally patched to make it even more xgettext compatible # by Peter Funk """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()