[Checkins] SVN: z3c.checkversions/trunk/ Added a blacklist option to remove bad versions given by the buildbot

Christophe Combelles ccomb at free.fr
Sun Jul 25 07:11:55 EDT 2010


Log message for revision 115075:
  Added a blacklist option to remove bad versions given by the buildbot
  

Changed:
  U   z3c.checkversions/trunk/CHANGELOG.txt
  U   z3c.checkversions/trunk/README.txt
  U   z3c.checkversions/trunk/z3c/checkversions/base.py
  U   z3c.checkversions/trunk/z3c/checkversions/buildout.txt
  U   z3c.checkversions/trunk/z3c/checkversions/main.py

-=-
Modified: z3c.checkversions/trunk/CHANGELOG.txt
===================================================================
--- z3c.checkversions/trunk/CHANGELOG.txt	2010-07-25 11:11:29 UTC (rev 115074)
+++ z3c.checkversions/trunk/CHANGELOG.txt	2010-07-25 11:11:54 UTC (rev 115075)
@@ -4,7 +4,9 @@
 0.4 (unreleased)
 ----------------
 
-- ...
+- added a `blacklist` option for versions to avoid
+  (possibly coming from a buildbot)
+- remove a temporary file during tests
 
 0.3 (2010-07-09)
 ----------------

Modified: z3c.checkversions/trunk/README.txt
===================================================================
--- z3c.checkversions/trunk/README.txt	2010-07-25 11:11:29 UTC (rev 115074)
+++ z3c.checkversions/trunk/README.txt	2010-07-25 11:11:54 UTC (rev 115075)
@@ -38,21 +38,24 @@
 ::
 
     $ checkversions -h
-    Usage: checkversions [-v] [-l LEVEL] [-i INDEX] [buildout_file]
+    Usage: checkversions [-v] [-l LEVEL] [-i INDEX] [-b BLACKLIST] [buildout_file]
     
     This script will check new package versions of either your current installed
     distributions or a buildout file if provided. It can detect major or minor
     versions availability: level 0 gets the highest version (X.y.z), level 1 gets
     the highest intermediate version (x.Y.z), level 2 gets the highest minor
     version (x.y.Z).  Using level 2, you can automatically retrieve all bugfix
-    versions of a buildout.
+    versions of a buildout.  If you provide a blacklist file with bad versions,
+    these versions won't be suggested.
     
     Options:
       -h, --help            show this help message and exit
       -l LEVEL, --level=LEVEL
                             Version level to check
       -i INDEX, --index=INDEX
-                            Alternative package index URL
+                            Provide and alternative package index URL
+      -b BLACKLIST, --blacklist=BLACKLIST
+                            Provide a blacklist file with bad versions
       -v, --verbose         Verbose mode (prints old versions too)
 
 
@@ -78,13 +81,33 @@
 Here is a sample `versions.cfg` file::
 
     [versions]
-    pip=0.6.3
+    somepackage=0.5.3
 
-You can create a new versions.cfg with the output ::
+You can create a new versions.cfg by retrieving the output ::
 
     $ checkversions -v -l 1 versions.cfg
     # Checking buildout file versions.cfg
-    pip=0.7.1 # was: 0.6.3
+    somepackage=0.6.2 # was: 0.5.0
 
+If you provide a blacklist file, such as `blacklist.cfg` containing bad
+versions, such as::
 
+    somepackage=0.6.2
+    somepackage=0.6.1
 
+Then these versions won't be suggested::
+
+    $ checkversions -v -l 1 versions.cfg
+    # Checking buildout file versions.cfg
+    somepackage=0.6.0 # was: 0.5.0
+
+
+Run tests
+=========
+
+Uncompress the archive, then run::
+
+    $ python setup.py test
+
+
+

Modified: z3c.checkversions/trunk/z3c/checkversions/base.py
===================================================================
--- z3c.checkversions/trunk/z3c/checkversions/base.py	2010-07-25 11:11:29 UTC (rev 115074)
+++ z3c.checkversions/trunk/z3c/checkversions/base.py	2010-07-25 11:11:54 UTC (rev 115075)
@@ -30,8 +30,14 @@
     """Base class for version checkers
     """
     __custom_url = False
-    def __init__(self, index_url=None, verbose=False):
+    def __init__(self, index_url=None, verbose=False, blacklist=None):
         self.verbose = verbose
+        if blacklist:
+            # create a set of tuples with bad versions
+            self.blacklist = set([tuple(map(lambda x: x.strip(), line.split('=')))
+                        for line in open(blacklist).readlines() if '=' in line])
+        else:
+            self.blacklist = set()
         self.pi = package_index.PackageIndex()
         self._set_index_url(index_url)
         if index_url is not None:
@@ -67,7 +73,10 @@
             # loop all index versions until we find the 1st newer version
             # that keeps the major versions (below level)
             # and is a final version
+            # and is not in the blacklist
             for dist in self.pi[req.key]:
+                if (dist.project_name, dist.version) in self.blacklist:
+                    continue
                 if not _final_version(dist.parsed_version):
                     continue
                 if dist.parsed_version[:level] > parsed_version[:level]:

Modified: z3c.checkversions/trunk/z3c/checkversions/buildout.txt
===================================================================
--- z3c.checkversions/trunk/z3c/checkversions/buildout.txt	2010-07-25 11:11:29 UTC (rev 115074)
+++ z3c.checkversions/trunk/z3c/checkversions/buildout.txt	2010-07-25 11:11:54 UTC (rev 115075)
@@ -68,6 +68,7 @@
 
 The old comments are removed:
 
+>>> os.remove(buildout_path)
 >>> buildout_fd, buildout_path = mkstemp()
 >>> buildout_file = os.fdopen(buildout_fd, 'w')
 >>> buildout_file.write("""
@@ -88,8 +89,29 @@
 Reading file:///.../zope.component/
 zope.component=3.9.4 # was: 3.4.0
 
+We can provide a blacklist file, containing versions to not suggest.
+This file may come from a buildbot remembering failures.
 
+>>> blacklist_fd, blacklist_path = mkstemp()
+>>> blacklist_file = os.fdopen(blacklist_fd, 'w')
+>>> blacklist_file.write("""
+... zope.component =3.9.4  
+... zope.component = 3.9.3""")
+>>> blacklist_file.close()
 
+>>> checker = buildout.Checker(filename=buildout_path,
+...                            verbose=True,
+...                            blacklist=blacklist_path)
+>>> checker.check()
+# Checking buildout file ...
+Reading file:///.../zope.interface/
+zope.interface=3.6.1 # was: 3.4.1
+Reading file:///.../zope.component/
+zope.component=3.9.2 # was: 3.4.0
+
+>>> os.remove(blacklist_path)
+>>> os.remove(buildout_path)
+
 console script
 --------------
 
@@ -101,12 +123,10 @@
 >>> from subprocess import Popen, PIPE
 >>> p = Popen([sys.executable, main.__file__, '-h'],
 ...           stdout=PIPE, stdin=PIPE, stderr=PIPE)
->>> print p.stdout.read()
-Usage: ...
-...
 
+# the "usage" attribute of optparse is inconsistent between python versions
+>>> p.stdout.read().lower().startswith('usage: ')
+True
 
-Clean the tmp file:
 
->>> os.remove(buildout_path)
 

Modified: z3c.checkversions/trunk/z3c/checkversions/main.py
===================================================================
--- z3c.checkversions/trunk/z3c/checkversions/main.py	2010-07-25 11:11:29 UTC (rev 115074)
+++ z3c.checkversions/trunk/z3c/checkversions/main.py	2010-07-25 11:11:54 UTC (rev 115075)
@@ -19,13 +19,17 @@
 level 2 gets the highest minor version (x.y.Z).
 
 Using level 2, you can automatically retrieve all bugfix versions of a buildout.
+
+If you provide a blacklist file with bad versions, these versions won't be
+suggested.
 """
 
 from optparse import OptionParser
+import os
 
 def main():
 
-    usage = u"Usage: %prog [-v] [-l LEVEL] [-i INDEX] [buildout_file]"
+    usage = u"Usage: %prog [-v] [-l LEVEL] [-i INDEX] [-b BLACKLIST] [buildout_file]"
     parser = OptionParser(description=__doc__, usage=usage)
 
     parser.add_option('-l', '--level',
@@ -36,8 +40,13 @@
 
     parser.add_option('-i', '--index',
                       dest='index',
-                      help=u"Alternative package index URL")
+                      help=u"Provide and alternative package index URL")
 
+    parser.add_option('-b', '--blacklist',
+                      dest='blacklist',
+                      default="",
+                      help=u"Provide a blacklist file with bad versions")
+
     parser.add_option('-v', '--verbose',
                       dest='verbose',
                       action='store_true',
@@ -48,6 +57,9 @@
     if len(args) > 1:
         parser.error("You must specify only one argument")
 
+    if options.blacklist != "" and not os.path.exists(options.blacklist):
+        parser.error('The blacklist file "%s" does not exist!' % options.blacklist)
+
     buildoutcfg = False
     if len(args) == 1:
         buildoutcfg = args[0]
@@ -59,11 +71,13 @@
     if buildoutcfg:
         import buildout
         checker = buildout.Checker(filename=buildoutcfg,
+                                   blacklist=options.blacklist,
                                    verbose=options.verbose,
                                    **kw)
     else:
         import installed
-        checker = installed.Checker(verbose=options.verbose)
+        checker = installed.Checker(blacklist=options.blacklist,
+                                    verbose=options.verbose)
 
     checker.check(level=options.level)
 



More information about the checkins mailing list