[Checkins] SVN: zope.app.locales/trunk/src/zope/app/locales/ Sort filenames properly, not within filetype (py/zcml/pt) groups.
Marius Gedminas
marius at pov.lt
Mon Dec 12 15:11:31 UTC 2011
Log message for revision 123777:
Sort filenames properly, not within filetype (py/zcml/pt) groups.
Changed:
U zope.app.locales/trunk/src/zope/app/locales/extract.py
U zope.app.locales/trunk/src/zope/app/locales/tests.py
-=-
Modified: zope.app.locales/trunk/src/zope/app/locales/extract.py
===================================================================
--- zope.app.locales/trunk/src/zope/app/locales/extract.py 2011-12-12 15:09:59 UTC (rev 123776)
+++ zope.app.locales/trunk/src/zope/app/locales/extract.py 2011-12-12 15:11:31 UTC (rev 123777)
@@ -113,19 +113,21 @@
def __init__(self, msgid, comments=None):
self.msgid = msgid
self.comments = comments or ''
- self._location = []
+ self.locations = []
def addComment(self, comment):
self.comments += comment + '\n'
def addLocationComment(self, filename, line):
filename = filename.replace(os.sep, '/')
- self.comments += '#: %s:%s\n' % (filename, line)
- self._location.append((filename, line))
+ self.locations.append((filename, line))
+ self.locations.sort()
def write(self, file):
if self.comments:
file.write(self.comments)
+ for filename, line in self.locations:
+ file.write('#: %s:%s\n' % (filename, line))
if (isinstance(self.msgid, Message) and
self.msgid.default is not None):
default = self.msgid.default.strip().encode(DEFAULT_CHARSET)
@@ -139,8 +141,8 @@
file.write('\n')
def __cmp__(self, other):
- return cmp((self._location, self.msgid),
- (other._location, other.msgid))
+ return cmp((self.locations, self.msgid),
+ (other.locations, other.msgid))
def __repr__(self):
return '<POTEntry: %r>' % self.msgid
@@ -163,10 +165,9 @@
if msgid not in self.catalog:
self.catalog[msgid] = POTEntry(msgid)
- if base_dir:
- locations = [(strip_base_dir(filename, base_dir), lineno)
- for filename, lineno in locations]
- for filename, lineno in sorted(locations):
+ for filename, lineno in locations:
+ if base_dir:
+ filename = strip_base_dir(filename, base_dir)
self.catalog[msgid].addLocationComment(filename, lineno)
def _getProductVersion(self):
Modified: zope.app.locales/trunk/src/zope/app/locales/tests.py
===================================================================
--- zope.app.locales/trunk/src/zope/app/locales/tests.py 2011-12-12 15:09:59 UTC (rev 123776)
+++ zope.app.locales/trunk/src/zope/app/locales/tests.py 2011-12-12 15:11:31 UTC (rev 123777)
@@ -103,7 +103,7 @@
def doctest_POTMaker_add():
- """Test for POTMaker.add
+ r"""Test for POTMaker.add
>>> from zope.app.locales.extract import POTMaker
>>> pm = POTMaker('/dev/null', 'path')
@@ -121,24 +121,17 @@
The locations have been sorted
- >>> print pm.catalog['msgid1'].comments
- #: file1.py:3
- #: file2.py:2
- <BLANKLINE>
+ >>> pm.catalog['msgid1'].locations
+ [('file1.py', 3), ('file2.py', 2)]
You can call add multiple times and it will merge the entries
>>> pm.add({'msgid1': [('file1.zcml', 4)],
... 'msgid3': [('file2.zcml', 5)]})
- >>> print pm.catalog['msgid1'].comments
- #: file1.py:3
- #: file2.py:2
- #: file1.zcml:4
- <BLANKLINE>
+ >>> pm.catalog['msgid1'].locations
+ [('file1.py', 3), ('file1.zcml', 4), ('file2.py', 2)]
- Unfortunately it doesn't re-sort the locations, which is arguably a bug.
- Please feel free to fix and update this test.
"""
@@ -163,11 +156,8 @@
... ('file1.py', 3),
... ('notbasedir/file3.py', 5)]},
... 'basedir/')
- >>> print pm.catalog['msgid1'].comments
- #: file1.py:3
- #: file2.py:2
- #: notbasedir/file3.py:5
- <BLANKLINE>
+ >>> pm.catalog['msgid1'].locations
+ [('file1.py', 3), ('file2.py', 2), ('notbasedir/file3.py', 5)]
"""
More information about the checkins
mailing list