forget the past. default tip
authorroot
Wed, 26 Apr 2006 10:48:09 +0000
changeset 0 c04c74ffb90e
forget the past. forget the past.
.hgignore
check_conformity.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Wed Apr 26 10:48:09 2006 +0000
@@ -0,0 +1,4 @@
+(^|/)\.svn($|/)
+(^|/)\.hg($|/)
+(^|/)\.hgtags($|/)
+^log$
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/check_conformity.py	Wed Apr 26 10:48:09 2006 +0000
@@ -0,0 +1,441 @@
+#!/usr/bin/python
+# -*- coding: ISO-8859-1 -*-
+
+# Copyright (c) 2005 LOGILAB (Paris, FRANCE).
+# Copyright (c) 2005 EDF R&D (Clamart, FRANCE).
+
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc.,
+# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+# TODO use optparse to provide --help and --version options
+# TODO generate system upgrade commands according to distribution
+#      and packaging tool
+
+__revision__ = "$Id: check_conformity.py,v 1.7 2005-04-08 08:39:19 nico Exp $"
+
+__log__ = """
+$Log: check_conformity.py,v $
+Revision 1.7  2005-04-08 08:39:19  nico
+changement pour version gnuplot
+
+Revision 1.6  2005/04/05 14:01:21  nico
+* ajout tests tkinter et tcl.
+* mise à jour versions ipython, psyco, pygtk, xmltools
+
+Revision 1.5  2005/03/29 15:10:17  nico
+ajout test pmwcontrib et test psyco. change version matplotlib et paida.
+
+Revision 1.4  2005/03/22 15:06:37  nico
+correction vérification version psyco
+
+Revision 1.3  2005/03/22 13:18:54  nico
+ai inclut corrections de JP Argaud concernant psyco, pmw, gnuplot et numarray.
+ai ajouté licence GPL en tête de fichier et (c) Logilab et EDF R&D.
+
+Revision 1.2  2005/03/22 11:46:05  nico
+ai pris en compte toutes les remarques de JP Argaud.
+
+"""
+import sys
+
+# taken from logilab.common.textutils #########################################
+# Ansi colorization ###########################################################
+
+ANSI_PREFIX = '\033['
+ANSI_END = 'm'
+ANSI_RESET = '\033[0m'
+ANSI_STYLES = {
+    'reset'     : "0",
+    'bold'      : "1",
+    'italic'    : "3",
+    'underline' : "4",
+    'blink'     : "5",
+    'inverse'   : "7",
+    'strike'    : "9",
+}
+ANSI_COLORS = {
+    'reset'   : "0",
+    'black'   : "30",
+    'red'     : "31",
+    'green'   : "32",
+    'yellow'  : "33",
+    'blue'    : "34",
+    'magenta' : "35",
+    'cyan'    : "36",
+    'white'   : "37",
+}
+
+
+def get_csv(string, sep=','):
+    """return a list of string in from a csv formatted line
+
+    >>> get_csv('a, b, c   ,  4')
+    ['a', 'b', 'c', '4']
+    >>> get_csv('a')
+    ['a']
+    >>>
+
+    :type string: str or unicode
+    :param string: a csv line
+
+    :type sep: str or unicode
+    :param sep: field separator, default to the comma (',')
+
+    :rtype: str or unicode
+    :return: the unquoted string (or the input string if it wasn't quoted)    
+    """
+    return [word.strip() for word in string.split(sep) if word.strip()]
+
+def _get_ansi_code(color=None, style=None):
+    """return ansi escape code corresponding to color and style
+    
+    :type color: str or None
+    :param color:
+      the color identifier (see `ANSI_COLORS` for available values)
+
+    :type style: str or None
+    :param style:
+      style string (see `ANSI_COLORS` for available values). To get
+      several style effects at the same time, use a coma as separator.
+
+    :raise KeyError: if an unexistant color or style identifier is given
+    
+    :rtype: str
+    :return: the built escape code
+    """
+    ansi_code = []
+    if style:
+        style_attrs = get_csv(style)
+        for effect in style_attrs:
+            ansi_code.append(ANSI_STYLES[effect])
+    if color:
+        ansi_code.append(ANSI_COLORS[color])
+    if ansi_code:
+        return ANSI_PREFIX + ';'.join(ansi_code) + ANSI_END
+    return ''
+
+def colorize_ansi(msg, color=None, style=None):
+    """colorize message by wrapping it with ansi escape codes
+
+    :type msg: str or unicode
+    :param msg: the message string to colorize
+
+    :type color: str or None
+    :param color:
+      the color identifier (see `ANSI_COLORS` for available values)
+
+    :type style: str or None
+    :param style:
+      style string (see `ANSI_COLORS` for available values). To get
+      several style effects at the same time, use a coma as separator.
+
+    :raise KeyError: if an unexistant color or style identifier is given
+
+    :rtype: str or unicode
+    :return: the ansi escaped string
+    """
+    # If both color and style are not defined, then leave the text as is
+    if color is None and style is None:
+        return msg
+    escape_code = _get_ansi_code(color, style)
+    # If invalid (or unknown) color, don't wrap msg with ansi codes
+    if escape_code:
+        return '%s%s%s' % (escape_code, msg, ANSI_RESET)
+    return msg
+
+
+# plapys ######################################################################
+
+# la version renvoyée doit toujours être un n-uplet
+# d'entiers
+
+MAXCOL = 72 # 79 chars per line and [xxxx] at then end
+
+def _text_to_version(version) :
+    return tuple(map(int, str(version).split('.')))
+    
+def get_version_tkinter() :
+     """Tkinter"""
+     from Tkinter import __version__
+     return _text_to_version(__version__.split()[1])
+
+def get_version_tk() :
+    """Tk"""
+    import Tkinter
+    return _text_to_version(Tkinter.TkVersion)
+
+def get_version_tcl() :
+    """Tcl"""
+    import Tkinter
+    return _text_to_version(Tkinter.TclVersion)
+
+def get_version_python() :
+    """Python"""
+    import sys
+    return tuple(sys.version_info[0:3])
+
+def get_version_constraint() :
+    """logilab's constraint"""
+    import logilab.constraint.__pkginfo__
+    return logilab.constraint.__pkginfo__.numversion
+
+def get_version_4suite() :
+    """4suite"""
+    import Ft
+    if Ft.__version__.startswith('1.0a') :
+        return (1,0,-2)
+    elif Ft.__version__.startswith('1.0b') :
+        return (1,0,-1)
+    else :
+        return _text_to_version(Ft.__version__)
+
+def get_version_egenix_mx_base() :
+    """Egenix-mx-base"""
+    import mx
+    return _text_to_version(mx.__version__)
+
+def get_version_gnome_python() :
+    """Gnome-Python"""
+    import gnome
+    return gnome.gnome_python_version
+
+def get_version_imaging() :
+    """Imaging Library"""
+    import PIL.Image
+    return _text_to_version(PIL.Image.VERSION)
+
+def get_version_ipython() :
+    """ipython"""
+    import IPython
+    return _text_to_version(IPython.__version__)
+
+def get_version_matplotlib() :
+    """matplotlib"""
+    import matplotlib
+    return _text_to_version(matplotlib.__version__)
+
+def get_version_netcdf() :
+    """Netcdf"""
+    from Scientific.IO import NetCDF
+    raise NotImplementedError()
+
+def get_version_numarray() :
+    """numarray"""
+    import numarray
+    return _text_to_version(numarray.__version__)
+
+def get_version_numeric() :
+    """numeric"""
+    import Numeric
+    return _text_to_version(Numeric.__version__)
+
+def get_version_aida() :
+    """aida"""
+    from paida.paida_core import IConstants
+    return _text_to_version(IConstants.IConstants.AIDA_VERSION)
+
+def get_version_paida() :
+    """paida"""
+    from paida.paida_core import IConstants
+    return _text_to_version(IConstants.IConstants.PAIDA_VERSION)
+
+def get_version_pmw() :
+    """pmw"""
+    import Pmw
+    return _text_to_version(Pmw.version())
+
+def get_version_pmwcontrib() :
+    """pmwcontrib"""
+    from PmwContribD.cvsversion import cvs_product_version
+    return _text_to_version(cvs_product_version()[1:].replace('_','.'))
+
+def get_version_psyco() :
+    """psyco"""
+    import psyco
+    ver = hex(psyco.__version__)
+    return tuple(map(int,(ver[2],ver[4],ver[6])))
+
+def get_version_pysablot() :
+    """pysablot"""
+    raise NotImplementedError()
+
+def get_version_pyxml() :
+    """pyxml"""
+    import xml
+    return _text_to_version(xml.__version__)
+
+def get_version_pygtk() :
+    """pygtk"""
+    import gtk
+    return gtk.pygtk_version
+
+def get_version_pyorbit() :
+    """pyorbit"""
+    raise NotImplementedError()
+
+def get_version_pyro() :
+    """pyro"""
+    import Pyro
+    return _text_to_version(Pyro.constants.VERSION)
+
+
+def get_version_reportlab() :
+    """reportlab"""
+    import reportlab
+    return _text_to_version(reportlab.Version)
+
+def get_version_scientificpython() :
+    """scientificpython"""
+    import Scientific
+    raise NotImplementedError()
+
+def get_version_wxpython() :
+    """wxpython"""
+    import wxPython
+    return _text_to_version(wxPython.__version__)
+
+def get_version_xmltools() :
+    """xmltools"""
+    from logilab.xmltools.__pkginfo__ import numversion
+    return tuple(numversion)
+
+def get_version_gnuplot() :
+    """gnuplot"""
+    import Gnuplot
+    return _text_to_version(Gnuplot.__version__)
+
+def get_version_win32all() :
+    """win32all"""
+    import win32all
+    raise NotImplementedError()
+
+def get_version_py2exe() :
+    """py2exe"""
+    raise NotImplementedError()
+
+def get_version_isetup() :
+    """inno setup"""
+    raise NotImplementedError()
+
+        
+class Plapys :
+
+    def __init__(self, version, desc, checks, checks_linux=None, checks_win=None) :
+        self.version = version
+        self.description = desc
+        self.checks = checks
+        self.checks_linux = checks_linux or []
+        self.checks_win = checks_win or []
+        self.ok = []
+        self.nok = []
+        self.noinstall = []
+
+
+    def check(self) :
+        for chk in self.checks :
+            self._check(chk[0], chk[1:])
+        if sys.platform.startswith('linux') :
+            for chk in self.checks_linux :
+                self._check(chk[0], chk[1:])
+        elif sys.platform.startswith('win') :
+            for chk in self.checks_linux :
+                self._check(chk[0], chk[1:])
+            
+            
+        
+    def _check(self, get_version, versions) :
+        line = '%s ver %s...' % (colorize_ansi(get_version.__doc__,style='bold'), str(versions))
+        #line = '%s ver %s...' % (get_version.__doc__, str(versions))
+        LINELEN=MAXCOL+8
+        if len(versions) == 1 :
+            min_ver = max_ver = versions[0]
+        else :
+            min_ver, max_ver = versions
+        try:
+            installed_ver = get_version()
+            line += ' found %s' % str(installed_ver)
+            line += ' '*LINELEN
+            if min_ver <= installed_ver <= max_ver :
+                self.ok.append( (get_version, installed_ver) )
+                print '[ %s ]'%colorize_ansi('OK','green'), line[:LINELEN]
+            else :
+                self.nok.append( (get_version, installed_ver) )
+                print '[%s]'%colorize_ansi('FAIL','red'), line[:LINELEN]
+        except NotImplementedError, e :
+            self.noinstall.append( (get_version, str(e)) )
+            line += ' missing test'
+            line += ' '*LINELEN
+            print '[%s]'%colorize_ansi('WARN','yellow'), line[:LINELEN]
+        except ImportError, e :
+            self.noinstall.append( (get_version, str(e)) )
+            line += ' not installed'
+            line += ' '*LINELEN
+            print '[%s]'%colorize_ansi('FAIL','red'), line[:LINELEN]
+
+CHECKS = [
+    (get_version_python,           (2,3,3),  (2,3,5)  ),
+    (get_version_tkinter,          (1,177),           ),
+    (get_version_tk,               (8,4),             ),
+    (get_version_tcl,              (8,4),             ),
+    (get_version_4suite,           (1,0,-2),          ),
+    (get_version_constraint,       (0,2,3),  (0,2,5)  ),
+    (get_version_egenix_mx_base,   (2,0),             ),
+    (get_version_gnome_python,     (1,4,4),  (2,6,2)  ),
+    (get_version_imaging,          (1,1,4),           ),
+    (get_version_ipython,          (0,6,4),  (0,6,11) ),
+    (get_version_matplotlib,       (0,52),   (0,73,1) ),
+    (get_version_netcdf,           (3,5,1),           ),
+    (get_version_numarray,         (1,0),    (1,1,1)  ),
+    (get_version_numeric,          (23,1),   (23,7)   ),
+    (get_version_aida,             (3,2),             ),
+    (get_version_paida,            (2,7),             ),
+    (get_version_pmw,              (1,2),             ),
+    (get_version_pmwcontrib,       (2,0,2),           ),
+    (get_version_psyco,            (1,1,1),  (1,4,0)  ),
+    (get_version_pysablot,         (0,1),             ),
+    (get_version_pyxml,            (0,8,3),  (0,8,4)  ),
+    (get_version_pygtk,            (0,6,11), (2,4,1)  ),
+    (get_version_pyorbit,          (2,0,1),           ),
+    (get_version_pyro,             (3,4),             ),
+    (get_version_reportlab,        (1,15),   (1,20)   ),
+    (get_version_scientificpython, (2,4,3),  (2,4,9)  ),
+    (get_version_wxpython,         (2,4,2,4),         ),
+    (get_version_xmltools,         (1,3,7),  (1,4,0)  ),
+    ]
+
+CHECKS_LINUX = [
+    (get_version_gnuplot,          (1,5),    (1,7)    ),
+    ]
+
+CHECKS_WIN = [
+    (get_version_win32all,	   (163,),           ),
+    (get_version_py2exe,           (0,5,4),          ),
+    (get_version_isetup,	   (4,2,7),          ),
+    ]
+
+plapys_0_0_1 = Plapys('0.0.1', "PLAte-forme PYthon Scientifique pour Python 2.3",
+                      CHECKS, CHECKS_LINUX, CHECKS_WIN)
+
+
+if __name__ == '__main__' :
+    print "check_conformity [revision %s]"%__revision__.split()[2]
+    platform = plapys_0_0_1
+    print "Checking %s version %s..." % (plapys_0_0_1.description, plapys_0_0_1.version) 
+    platform.check()
+    print 
+    if platform.nok or platform.noinstall :
+        msg = "Current install DOES NOT COMPLY with Plapys version %s" % platform.version
+        print colorize_ansi(msg, 'red')
+    else :
+        msg = "Current install complies with Plapys version %s" % platform.version
+        print colorize_ansi(msg, 'green')