[Checkins] SVN: bluebream/branches/ccomb-remove-bbkit/ Detect the latest version online and suggest it during project creation

Christophe Combelles ccomb at free.fr
Sat Jul 10 06:37:19 EDT 2010


Log message for revision 114493:
  Detect the latest version online and suggest it during project creation
  

Changed:
  U   bluebream/branches/ccomb-remove-bbkit/CHANGES.txt
  U   bluebream/branches/ccomb-remove-bbkit/src/bluebream/bluebream_base/template.py
  U   bluebream/branches/ccomb-remove-bbkit/src/bluebream/bluebream_base/tests/bluebream.txt

-=-
Modified: bluebream/branches/ccomb-remove-bbkit/CHANGES.txt
===================================================================
--- bluebream/branches/ccomb-remove-bbkit/CHANGES.txt	2010-07-10 10:24:32 UTC (rev 114492)
+++ bluebream/branches/ccomb-remove-bbkit/CHANGES.txt	2010-07-10 10:37:19 UTC (rev 114493)
@@ -7,6 +7,7 @@
 - Directly depend on the ZTK!
 - Removed the bbkit package
 - Ask the version of BlueBream at project creation
+- Automatically find and suggest the latest version online
 
 
 1.0b2 (2010-06-30)

Modified: bluebream/branches/ccomb-remove-bbkit/src/bluebream/bluebream_base/template.py
===================================================================
--- bluebream/branches/ccomb-remove-bbkit/src/bluebream/bluebream_base/template.py	2010-07-10 10:24:32 UTC (rev 114492)
+++ bluebream/branches/ccomb-remove-bbkit/src/bluebream/bluebream_base/template.py	2010-07-10 10:37:19 UTC (rev 114493)
@@ -11,12 +11,33 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-import re, os, sys, shutil
-import pkg_resources
+from HTMLParser import HTMLParser
 from paste.script import templates
 from paste.script.templates import var
+from urllib2 import urlopen
+import pkg_resources
+import re, os, sys
 
+DOWNLOAD_URL = 'http://download.zope.org/bluebream/'
 
+class FindLatest(HTMLParser):
+    """html parser used to find the latest version file on download.zope.org
+    """
+    def reset(self):
+        """initialize a regexp and a version set"""
+        HTMLParser.reset(self)
+        self.regexp = re.compile('.*bluebream-(.*).cfg$')
+        self.versions = set()
+
+    def handle_starttag(self, tag, attrs):
+        """extract the version from each link"""
+        if tag != 'a':
+            return
+        for attr in attrs:
+            if attr[0] == 'href' and self.regexp.match(attr[1]):
+                self.versions.add(self.regexp.sub('\\1', attr[1]))
+
+
 class BlueBream(templates.Template):
 
     _template_dir = 'project_template'
@@ -28,8 +49,8 @@
         var('interpreter',
             u'Name of custom Python interpreter',
             default='breampy'),
-        var('bluebream', u'Which version of BlueBream?',
-            default=pkg_resources.get_distribution('bluebream').version),
+        var('bluebream', (u'Which version of BlueBream?\n'
+                          u'Check on %s' % DOWNLOAD_URL)),
         var('version', u'Version of your project', default='0.1'),
         var('description', u'One-line description of the package'),
         var('long_description', u'Multi-line description (in reST)'),
@@ -43,10 +64,27 @@
     def check_vars(self, vars, cmd):
         """This method checks the variables and ask for missing ones
         """
-        # todo: detect available versions online, and suggest the latest
+        # Find the latest versions.cfg online
+        latest = pkg_resources.get_distribution('bluebream').version
+        try:
+            if 'offline' not in vars:  #offline is used in tests
+                print 'Searching the latest version...'
+                # parse the download html page and store versions
+                parser = FindLatest()
+                parser.feed(urlopen(DOWNLOAD_URL).read())
+                # return the highest version
+                latest = sorted(parser.versions,
+                              key=lambda v: pkg_resources.parse_version(v))[-1]
+                print 'Latest version found: %s' % latest
+        except IOError:
+            # if something wrong occurs, we keep the current version
+            print u'Error while getting the latest version online'
+            print u'Please check that you can access %s' % DOWNLOAD_URL
 
         # suggest what Paste chose
         for var in self.vars:
+            if var.name == 'bluebream':
+                var.default = latest
             if var.name == 'python_package':
                 var.default = vars['package']
                 # but keep the user's input if there are dots in the middle
@@ -64,7 +102,7 @@
         if vars['package'] in ('bluebream', 'bream', 'zope'):
             print
             print "Error: The chosen project name results in an invalid " \
-                "package name: %s." % name
+                "package name: %s." % vars['package']
             print "Please choose a different project name."
             sys.exit(1)
         vars['zip_safe'] = False

Modified: bluebream/branches/ccomb-remove-bbkit/src/bluebream/bluebream_base/tests/bluebream.txt
===================================================================
--- bluebream/branches/ccomb-remove-bbkit/src/bluebream/bluebream_base/tests/bluebream.txt	2010-07-10 10:24:32 UTC (rev 114492)
+++ bluebream/branches/ccomb-remove-bbkit/src/bluebream/bluebream_base/tests/bluebream.txt	2010-07-10 10:37:19 UTC (rev 114493)
@@ -33,6 +33,7 @@
 ...            "author_email=test_author_email",
 ...            "url=http://example.com",
 ...            "license_name=Test Public License",
+...            "offline=1",
 ...            ]
 >>> exit_code = runner.run(option_args + ['-t', 'bluebream', project] + extra_args)
 Selected and implied templates:
@@ -48,6 +49,7 @@
   keywords:          test_keyword
   license_name:      Test Public License
   long_description:  test_long_description
+  offline:           1
   package:           sample
   project:           sample
   python_package:    sample
@@ -114,6 +116,7 @@
   keywords:          test_keyword
   license_name:      Test Public License
   long_description:  test_long_description
+  offline:           1
   package:           samplemain
   project:           sample.main
   python_package:    sample.main
@@ -185,6 +188,7 @@
   keywords:          test_keyword
   license_name:      Test Public License
   long_description:  test_long_description
+  offline:           1
   package:           sampleappmain
   project:           sample.app.main
   python_package:    sample.app.main
@@ -256,6 +260,7 @@
   keywords:          test_keyword
   license_name:      Test Public License
   long_description:  test_long_description
+  offline:           1
   package:           foobarfoobar
   project:           foobar.foobar
   python_package:    foobar.foobar
@@ -324,6 +329,7 @@
   keywords:          test_keyword
   license_name:      Test Public License
   long_description:  test_long_description
+  offline:           1
   package:           sampleproject
   project:           sampleproject
   python_package:    sample.main



More information about the checkins mailing list