[Checkins] SVN: zope.kgs/trunk/src/zope/kgs/ fleshed out the changes.txt parsing

Shane Hathaway shane at hathawaymix.org
Sat Dec 6 20:24:20 EST 2008


Log message for revision 93741:
  fleshed out the changes.txt parsing
  

Changed:
  U   zope.kgs/trunk/src/zope/kgs/README.txt
  U   zope.kgs/trunk/src/zope/kgs/change.py
  A   zope.kgs/trunk/src/zope/kgs/changes_tests.py
  U   zope.kgs/trunk/src/zope/kgs/tests.py

-=-
Modified: zope.kgs/trunk/src/zope/kgs/README.txt
===================================================================
--- zope.kgs/trunk/src/zope/kgs/README.txt	2008-12-07 01:02:22 UTC (rev 93740)
+++ zope.kgs/trunk/src/zope/kgs/README.txt	2008-12-07 01:24:19 UTC (rev 93741)
@@ -361,14 +361,106 @@
 Let's now produce the changes:
 
   >>> from zope.kgs import change
-  >>> #change.main((cfgFileReal, cfgFileRealOrig))
+  >>> change.main((cfgFileReal, cfgFileRealOrig))
+  ===                                                                               
+  PIL                                                                               
+  ===                                                                               
+  <BLANKLINE>                                                                       
+  <BLANKLINE>                                                                       
+  ============                                                                      
+  z3c.formdemo                                                                      
+  ============                                                                      
+  <BLANKLINE>                                                                       
+  1.1.0 (None)                                                                      
+  ------------                                                                      
+  <BLANKLINE>                                                                       
+  - Feature: New "SQL Message" demo shows how ``z3c.form`` can be used with         
+    non-object data. Specificically, this small application demonstrates using a    
+    Gadfly database using pure SQL calls without any ORM.                           
+  <BLANKLINE>                                                                       
+  - Feature: New "Address Book" demo that demonstrates more complex use cases,      
+    such as subforms, composite widgets, and mappings/lists
+  <BLANKLINE>
+  <BLANKLINE>
+  ==============
+  zope.component
+  ==============
+  <BLANKLINE>
+  3.4.0 (2007-09-29)
+  ------------------
+  <BLANKLINE>
+  No further changes since 3.4.0a1.
+  <BLANKLINE>
+  <BLANKLINE>
+  ==============
+  zope.interface
+  ==============
+  <BLANKLINE>
+  3.4.1 (None)
+  ------------
+  <BLANKLINE>
+  Fixed a setup bug that prevented installation from source on systems
+  without setuptools.
+  <BLANKLINE>
+  3.4.0 (None)
+  ------------
+  <BLANKLINE>
+  Final release for 3.4.0.
+  <BLANKLINE>
+  <BLANKLINE>
 
+
 You can also create the changes without an original file, in which case only
 the versions listed in the current KGS are considered.
 
   >>> change.main((cfgFileReal,))
+  ===                                                                               
+  PIL                                                                               
+  ===                                                                               
+  <BLANKLINE>                                                                       
+  <BLANKLINE>                                                                       
+  ============                                                                      
+  z3c.formdemo                                                                      
+  ============                                                                      
+  <BLANKLINE>                                                                       
+  1.1.0 (None)                                                                      
+  ------------                                                                      
+  <BLANKLINE>                                                                       
+  - Feature: New "SQL Message" demo shows how ``z3c.form`` can be used with         
+    non-object data. Specificically, this small application demonstrates using a    
+    Gadfly database using pure SQL calls without any ORM.                           
+  <BLANKLINE>                                                                       
+  - Feature: New "Address Book" demo that demonstrates more complex use cases,      
+    such as subforms, composite widgets, and mappings/lists
+  <BLANKLINE>
+  <BLANKLINE>
+  ==============
+  zope.component
+  ==============
+  <BLANKLINE>
+  3.4.0 (2007-09-29)
+  ------------------
+  <BLANKLINE>
+  No further changes since 3.4.0a1.
+  <BLANKLINE>
+  <BLANKLINE>
+  ==============
+  zope.interface
+  ==============
+  <BLANKLINE>
+  3.4.1 (None)
+  ------------
+  <BLANKLINE>
+  Fixed a setup bug that prevented installation from source on systems
+  without setuptools.
+  <BLANKLINE>
+  3.4.0 (None)
+  ------------
+  <BLANKLINE>
+  Final release for 3.4.0.
+  <BLANKLINE>
+  <BLANKLINE>
 
-
 Introduction Page
 -----------------
 

Modified: zope.kgs/trunk/src/zope/kgs/change.py
===================================================================
--- zope.kgs/trunk/src/zope/kgs/change.py	2008-12-07 01:02:22 UTC (rev 93740)
+++ zope.kgs/trunk/src/zope/kgs/change.py	2008-12-07 01:24:19 UTC (rev 93741)
@@ -27,15 +27,67 @@
 
 """
 import os
+import re
 import sys
 import xmlrpclib
+import pkg_resources
 import zope.kgs.kgs
 
 SERVER_URL = "http://cheeseshop.python.org/pypi"
 
+# version_line finds a version number and an optional date
+version_line = re.compile(
+    r"(version\s*|)([0-9.][0-9a-zA-Z.]*)(\s*[(]([0-9a-z?-]+)[)])?",
+    re.IGNORECASE)
+
+# decoration_line matches lines to ignore
+decoration_line = re.compile(r"---|===")
+
+def parseReleases(lines):
+    """Parse the list of releases from a CHANGES.txt file.
+
+    Yields (version, release_date, [line]) for each release listed in the
+    change log.
+    """
+    if isinstance(lines, basestring):
+        lines = lines.split('\n')
+
+    version = None
+    release_date = None
+    changes = None
+
+    for line in lines:
+        line = line.rstrip()
+        mo = version_line.match(line)
+        if mo is not None:
+            if changes is not None:
+                yield version, release_date, changes
+            changes = []
+            version = mo.group(2)
+            release_date = mo.group(4)
+        elif changes is not None and decoration_line.match(line) is None:
+            changes.append(line)
+
+    # include the last list of changes
+    if version is not None and changes is not None:
+        yield version, release_date, changes
+
 def extractChanges(text, firstVersion, lastVersion):
-    return text[text.find(lastVersion):text.find(firstVersion)]
+    """Parse the changes out of a CHANGES.txt in the given range.
 
+    For each release, yields (version, release_date, change text).
+    """
+    first = pkg_resources.parse_version(firstVersion)
+    last = pkg_resources.parse_version(lastVersion)
+    for version, release_date, changes in parseReleases(text):
+        try:
+            v = pkg_resources.parse_version(version)
+        except AttributeError:
+            import pdb; pdb.set_trace()
+            raise
+        if first <= v <= last:
+            yield version, release_date, '\n'.join(changes)
+
 def generateChanges(currentPath, origPath):
     kgs = zope.kgs.kgs.KGS(currentPath)
     server = xmlrpclib.Server(SERVER_URL)
@@ -52,21 +104,26 @@
         data = server.release_data(package.name, package.versions[-1])
         firstVersion = origVersions.get(package.name, package.versions[0])
         lastVersion = package.versions[-1]
-        changes.append(
-            (package.name, firstVersion, lastVersion,
-             extractChanges(data['description'], firstVersion, lastVersion))
-            )
+        versions = list(
+            extractChanges(data['description'], firstVersion, lastVersion))
+        changes.append((package.name, versions))
 
     return changes
 
 def printChanges(changes):
-    for name, firstVersion, lastVersion, changes in changes:
-        print '%s (%s - %s)' %(name, firstVersion, lastVersion)
-        print '='*(len(name+firstVersion+lastVersion)+6)
+    for name, versions in changes:
+        print '=' * len(name)
+        print name
+        print '=' * len(name)
         print
-        print changes
+        for version, release_date, text in versions:
+            s = '%s (%s)' % (version, release_date)
+            print s
+            print '-' * len(s)
+            print
+            print text.strip()
+            print
         print
-        print
 
 
 def main(args=None):

Added: zope.kgs/trunk/src/zope/kgs/changes_tests.py
===================================================================
--- zope.kgs/trunk/src/zope/kgs/changes_tests.py	                        (rev 0)
+++ zope.kgs/trunk/src/zope/kgs/changes_tests.py	2008-12-07 01:24:19 UTC (rev 93741)
@@ -0,0 +1,117 @@
+
+import unittest
+
+from zope.kgs.change import parseReleases
+
+class ChangesTests(unittest.TestCase):
+
+    kgs_changes = """
+=======
+CHANGES
+=======
+
+0.2.0 (2007-11-??)
+------------------
+
+- Initial version as ``zope.kgs``.
+
+  * A script that lists all versions of a package released after the latest
+    version lsited in the KGS.
+
+  * A script that manages the generation of the entire KGS site.
+
+  * Generate an intro page to the KGS.
+
+  * Generate `links.html` file which lists all controlled packages files.
+
+  * Features copied from ``zope.release``:
+
+    + Parser for KGS configuration files.
+
+    + Generate `versions.cfg` and `buildout.cfg` script.
+
+  * Features copied from ``zc.mirrorcheeseshopslashsimple``:
+
+    + Generate new index pages for the controlled packages.
+"""
+
+    def test_kgs_example(self):
+        releases = list(parseReleases(self.kgs_changes))
+        self.assertEqual(len(releases), 1)
+        version, release_date, changes = releases[0]
+        self.assertEqual(version, "0.2.0")
+        self.assertEqual(release_date, "2007-11-??")
+        self.assertEqual(len(changes), 22)
+
+    datagenerator_changes = """
+=======
+CHANGES
+=======
+
+0.0.3 (2008-12-03)
+------------------
+
+- Refined the seed generation further: zlib.crc32() in 32 bit Python can
+  generate negative hashes, while 64 bit Python does not.  Enforced
+  positive hashes.
+
+- Began a test suite.
+
+
+0.0.2 (2008-12-02)
+------------------
+
+- Use the crc32 function to hash random seeds so that the
+  same random sequences are generated on both 32 bit and 64 bit
+  builds of Python.
+
+
+0.0.1 (2008-02-14)
+------------------
+
+- Initial Release
+"""
+
+    def test_datagenerator_example(self):
+        releases = list(parseReleases(self.datagenerator_changes))
+        self.assertEqual(len(releases), 3)
+        version, release_date, changes = releases[1]
+        self.assertEqual(version, "0.0.2")
+        self.assertEqual(release_date, "2008-12-02")
+        self.assertEqual(len(changes), 6)
+
+    zope_proxy_changes = """
+=======
+CHANGES
+=======
+
+3.5.0 (unreleased)
+------------------
+
+- Added support to bootstrap on Jython.
+
+3.4.2 (2008/07/27)
+------------------
+
+- Made C code compatible with Python 2.5 on 64bit architectures.
+
+1.0
+---
+- fake changelog entry here
+"""
+    def test_zope_proxy_example(self):
+        releases = list(parseReleases(self.zope_proxy_changes))
+        self.assertEqual(len(releases), 3)
+        version, release_date, changes = releases[0]
+        self.assertEqual(version, "3.5.0")
+        self.assertEqual(release_date, "unreleased")
+        self.assertEqual(len(changes), 3)
+
+        version, release_date, changes = releases[2]
+        self.assertEqual(version, "1.0")
+        self.assertEqual(release_date, None)
+        self.assertEqual(changes, ["- fake changelog entry here", ""])
+
+
+if __name__ == '__main__':
+    unittest.main()

Modified: zope.kgs/trunk/src/zope/kgs/tests.py
===================================================================
--- zope.kgs/trunk/src/zope/kgs/tests.py	2008-12-07 01:02:22 UTC (rev 93740)
+++ zope.kgs/trunk/src/zope/kgs/tests.py	2008-12-07 01:24:19 UTC (rev 93741)
@@ -26,6 +26,7 @@
 from zope.testing import doctest
 from zope.testing.doctestunit import DocFileSuite
 
+from zope.kgs.changes_tests import ChangesTests
 
 class FakeServer(object):
     """Pretend Cheeseshop XML-RPC server."""
@@ -187,6 +188,7 @@
 
 def test_suite():
     return unittest.TestSuite((
+        unittest.makeSuite(ChangesTests),
         DocFileSuite('README.txt',
                      setUp=setUp,
                      tearDown=tearDown,



More information about the Checkins mailing list