commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r9934 - in trunk/gnue-common: . src src/base src/setup src/utils


From: reinhard
Subject: [gnue] r9934 - in trunk/gnue-common: . src src/base src/setup src/utils
Date: Tue, 6 Oct 2009 08:01:37 -0500 (CDT)

Author: reinhard
Date: 2009-10-06 08:01:35 -0500 (Tue, 06 Oct 2009)
New Revision: 9934

Added:
   trunk/gnue-common/src/base/setup.py
   trunk/gnue-common/src/base/version.py
Removed:
   trunk/gnue-common/src/utils/setup.py
Modified:
   trunk/gnue-common/setup.py
   trunk/gnue-common/src/__init__.py
   trunk/gnue-common/src/setup/GSetup.py
   trunk/gnue-common/src/utils/version.py
Log:
Some work on setup and version control.


Modified: trunk/gnue-common/setup.py
===================================================================
--- trunk/gnue-common/setup.py  2009-10-06 06:34:50 UTC (rev 9933)
+++ trunk/gnue-common/setup.py  2009-10-06 13:01:35 UTC (rev 9934)
@@ -205,10 +205,10 @@
 
     def make_release_tree(self, base_dir, files):
         distutils.command.sdist.sdist.make_release_tree(self, base_dir, files)
-        self.process_templates(base_dir)
+        self.__process_templates(base_dir)
         build_svnrev(os.path.join(base_dir, 'src', 'svnrev.py'))
 
-    def process_templates(self, target):
+    def __process_templates(self, target):
 
         # Build list of files to be processed.
         filelist = FileList()
@@ -216,29 +216,24 @@
                 # Nothing to do.
             return
 
-        # FIXME: For compatibility with old packages not yet using the version
-        # module. Change to unconditional import in gnue-common 0.8.
-        try:
-            from src import version
-        except:
-            return
+        from src import __version__
 
         # List of keywords to replace.
         keywords = {
                 ':PACKAGE:': self.distribution.get_name(),
                 ':TITLE:': self.distribution.get_description(),
                 ':VERSION:': self.distribution.get_version(),
-                ':MAJOR:': str(version.major),
-                ':MINOR:': str(version.minor),
-                ':PHASE:': str(version.phase),
-                ':BUILD:': str(version.build),
-                ':SVN:': str(version.svn),
+                ':MAJOR:': str(__version__.major),
+                ':MINOR:': str(__version__.minor),
+                ':PHASE:': str(__version__.phase),
+                ':BUILD:': str(__version__.build),
+                ':SVN:': str(__version__.svn),
                 ':DATE_ISO:': time.strftime('%Y-%m-%d', time.gmtime()),
                 ':DATE_RFC:': time.strftime('%a, %d %b %Y', time.gmtime()),
                 ':TIME:': time.strftime('%H:%M:%S', time.gmtime())}
         # Hack for version numbering schemes that are limited to x.y.z.
-        if version.phase == 'final':
-            keywords[':FINAL:'] = str(version.build)
+        if __version__.phase == 'final':
+            keywords[':FINAL:'] = str(__version__.build)
         else:
             keywords[':FINAL:'] = '0'
 

Modified: trunk/gnue-common/src/__init__.py
===================================================================
--- trunk/gnue-common/src/__init__.py   2009-10-06 06:34:50 UTC (rev 9933)
+++ trunk/gnue-common/src/__init__.py   2009-10-06 13:01:35 UTC (rev 9934)
@@ -25,23 +25,19 @@
 of the modules can also be used outside GNUe.
 """
 
-from utils import version
+from utils.version import Version
 
 try:
     import svnrev
-    svn_revision = svnrev.svnrev
+    __svn_revision__ = svnrev.svnrev
 except ImportError:
-    svn_revision = None
+    __svn_revision__ = None
 
+__version__ = Version(0, 7, 'alpha', 0, __svn_revision__)
+
 PACKAGE = "GNUe-Common"
 TITLE = "GNUe Common Library"
+VERSION = __version__.get_version()
+HEXVERSION = __version__.get_hexversion()
 
-version = version.Version(0, 7, 'alpha', 0, svn_revision)
-
-VERSION = version.get_version()
-HEXVERSION = version.get_hexversion()
-
-__version__ = VERSION
-__hexversion__ = HEXVERSION
-
 __gettext_domain__ = "gnue-common"

Copied: trunk/gnue-common/src/base/setup.py (from rev 9928, 
trunk/gnue-common/src/utils/setup.py)
===================================================================
--- trunk/gnue-common/src/base/setup.py                         (rev 0)
+++ trunk/gnue-common/src/base/setup.py 2009-10-06 13:01:35 UTC (rev 9934)
@@ -0,0 +1,622 @@
+# GNU Enterprise Common Library - Installation Helper For Tools
+#
+# Copyright 2001-2009 Free Software Foundation
+#
+# This file is part of GNU Enterprise.
+#
+# GNU Enterprise 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, or (at your option) any later version.
+#
+# GNU Enterprise 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 program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id$
+"""
+GNU Enterprise specific extensions to distutils.
+
+Installation procedures in GNU Enterprise
+=========================================
+
+Each GNU Enterprise package contains a setup.py script used to create scource
+distribution from Subversion checkouts and to install from a source
+distribution. The script is based on distutils, but it uses this module to add
+some additional features.
+
+Automatic target directory determination
+----------------------------------------
+
+Upon installation, the setup script checks where GNUe-Common was installed, and
+automatically selects the installation target directories matching the existing
+GNUe-Common installation.
+
+Template processing
+-------------------
+
+A package can contain files with the ending in ".dist_template". The
+build/install process will process these templates by replacing some
+placeholders and storing the result in a file without the ending
+".dist_template".
+
+The following placeholders are available for use in templates:
+
+  - :PACKAGE:  Name of the package, i.e. 'gnue-forms'
+  - :TITLE:    Title of the package, i.e. 'GNU Enterprise Forms'
+  - :VERSION:  Full version of the package, i.e. '0.6.9+svn.9794'
+  - :MAJOR:    The major version, i.e. '0'
+  - :MINOR:    The minor version, i.e. '6'
+  - :PHASE:    The phase, i.e. 'final'
+  - :BUILD:    The build, i.e. '1'
+  - :SVN:      The current SubVersion revision
+  - :DATE_ISO: The date of the package formatted as YYYY-MM-DD
+  - :DATE_RFC: The date of the package formatted according to RFC 822
+  - :TIME:     The time of the package formattes as HH:MM:SS
+  - :FINAL:    If the build is final it contains the build number,
+               otherwise '0'
+
+Creation of svnrev.py
+---------------------
+
+A module named "svnrev.py" is created upon creation of a source distribution.
+This module only contains a single variable C{svnrev} which contains the
+revision number of the subversion checkout the source distribution was built
+from, or C{'0'} if the environment variable GNUE_BUILD was set during source
+distribution creation.
+
+This is later used by the C{gnue.common.base.version} infrastructure to display
+the full version number including the Subversion revision for snapshots.
+
+How to write a setup script
+---------------------------
+
+A setup script using this module follows this pattern::
+
+    from gnue.common.base import setup
+
+    class Setup(setup.Setup):
+
+        package_dir = {"gnue.foo": "src"}
+        scripts     = ["scripts/gnue-foo"]
+        data_files  = [
+                ("share/man/man1", self.allfiles("doc/man")),
+                ("share/gnue/foo", self.allfiles("foo))]
+
+        def build_files(self, action):
+            :
+            Some code to dynamically build files to be included in the source
+            distribution
+            :
+
+        def check_dependencies(self):
+            :
+            Some code to check install dependencies
+            :
+
+    if __name__ == "__main__":
+      Setup().run()
+"""
+
+import sys
+import time
+import os
+
+from distutils import log
+from distutils.core import setup
+from distutils.filelist import FileList
+
+import distutils.command.sdist
+import distutils.command.build
+import distutils.command.install
+
+import gnue.paths
+
+from gnue.common.base import version
+
+__all__ = ['Setup']
+
+# -----------------------------------------------------------------------------
+# Import the package root module
+# -----------------------------------------------------------------------------
+
+import src as package_info
+
+# -----------------------------------------------------------------------------
+# Check Python version
+# -----------------------------------------------------------------------------
+
+try:
+    if sys.hexversion < 0x02030000:
+        raise AttributeError
+
+except AttributeError:
+    print "-" * 70
+    print """
+You are running Python %s.
+
+GNU Enterprise requires at least Python 2.3.
+If you have a later version installed, you should run setup.py
+against that version. For example, if you have Python 2.3
+installed, you may need to run:
+
+python2.3 setup.py
+""" % sys.version.split()[0]
+    print "-" * 70
+    sys.exit(1)
+
+# -----------------------------------------------------------------------------
+# Global Setup instance
+# -----------------------------------------------------------------------------
+
+_setup = None
+
+# =============================================================================
+# Create a source distribution
+# =============================================================================
+
+class SDist(distutils.command.sdist.sdist):
+    """
+    Create a source distribution.
+
+    This is a specialized version of distutil's C{sdist} command, with the
+    following additions:
+
+      * The L{Setup} instance can define files to be built dynamically.
+      * Files with the name "*.dist_template" are processed and converted to
+        the target file.
+      * svnrev.py is created.
+    """
+
+    # -------------------------------------------------------------------------
+    # Run the sdist command
+    # -------------------------------------------------------------------------
+
+    def run(self):
+        """
+        Run the sdist command.
+        """
+
+        _setup.build_files('sdist')
+        distutils.command.sdist.sdist.run(self)
+
+
+    # -------------------------------------------------------------------------
+    # Remove files not used
+    # -------------------------------------------------------------------------
+
+    def prune_file_list(self):
+        """
+        Prune the list of files to be included in the source distribution.
+        """
+
+        distutils.command.sdist.sdist.prune_file_list(self)
+        self.filelist.exclude_pattern('*.dist_template', anchor=0)
+
+
+    # -------------------------------------------------------------------------
+    # Create the directory tree that will become the source distribution arch.
+    # -------------------------------------------------------------------------
+
+    def make_release_tree(self, base_dir, files):
+        """
+        Create the directory tree that will become the source distribution
+        archive.
+        """
+
+        distutils.command.sdist.sdist.make_release_tree(self, base_dir, files)
+        self.__process_templates(base_dir)
+        _setup.build_svnrev(os.path.join(base_dir, 'src', 'svnrev.py'))
+
+
+    # -------------------------------------------------------------------------
+    # Process all template files 
+    # -------------------------------------------------------------------------
+
+    def __process_templates(self, target):
+
+        # Build list of files to be processed.
+        filelist = FileList()
+        if filelist.include_pattern('*.dist_template', anchor=0) == 0:
+            # Nothing to do.
+            return
+
+        # For compatibility, remove with 0.8
+        try:
+            if isinstance(package_info.__version__, str):
+                package_info.__version__ = package_info.version
+        except:
+            return
+
+        # List of keywords to replace.
+        keywords = {
+                ':PACKAGE:': self.distribution.get_name(),
+                ':TITLE:': self.distribution.get_description(),
+                ':VERSION:': self.distribution.get_version(),
+                ':MAJOR:': str(package_info.__version__.major),
+                ':MINOR:': str(package_info.__version__.minor),
+                ':PHASE:': str(package_info.__version__.phase),
+                ':BUILD:': str(package_info.__version__.build),
+                ':SVN:': str(package_info.__version__.svn),
+                ':DATE_ISO:': time.strftime('%Y-%m-%d', time.gmtime()),
+                ':DATE_RFC:': time.strftime('%a, %d %b %Y', time.gmtime()),
+                ':TIME:': time.strftime('%H:%M:%S', time.gmtime())}
+        
+        # Hack for version numbering schemes that are limited to x.y.z.
+        if package_info.__version__.phase == 'final':
+            keywords[':FINAL:'] = str(package_info.__version__.build)
+        else:
+            keywords[':FINAL:'] = '0'
+
+        for src in filelist.files:
+            dst = os.path.join(target, src[:-14])
+            args = (src, dst, keywords)
+            self.execute(self.__process_template, args,
+                    "generating %s from %s" % (dst, src))
+
+
+    # -------------------------------------------------------------------------
+    # Process a single template
+    # -------------------------------------------------------------------------
+
+    def __process_template(self, src, dst, keywords):
+
+        infile = open(src, 'r')
+        content = infile.read()
+        infile.close()
+
+        for keyword, value in keywords.iteritems():
+            content = content.replace(keyword, value)
+
+        outfile = open(dst, 'w')
+        outfile.write(content)
+        outfile.close()
+
+        # Let destination file have the same mode than the source file.
+        os.chmod(dst, os.stat(src).st_mode)
+
+
+# =============================================================================
+# Build files to be installed
+# =============================================================================
+
+class Build(distutils.command.build.build):
+    """
+    Build files to be installed.
+
+    This is a specialized version of distutil's C{build} command, with the
+    following additions:
+
+      * The L{Setup} instance can define files to be built dynamically.
+      * svnrev.py is created.
+
+    Both items are only executed if the build is done from a Subversion
+    checkout rather than from a source distribution.
+    """
+
+    # -------------------------------------------------------------------------
+    # Run the command
+    # -------------------------------------------------------------------------
+
+    def run(self):
+        """
+        Run the build command.
+        """
+
+        if not os.path.isfile("PKG-INFO"):         # downloaded from SVN?
+            _setup.build_files('build')
+
+        distutils.command.build.build.run(self)
+
+        if not os.path.isfile("PKG-INFO"):
+            _setup.build_svnrev(os.path.join(self.build_lib, 'gnue',
+                  _setup.name[5:].lower(), 'svnrev.py'))
+
+
+# =============================================================================
+# Install the package
+# =============================================================================
+
+class Install(distutils.command.install.install):
+    """
+    Install the package.
+
+    This is a specialized version of distutil's C{install} command, with the
+    following additions:
+
+      * A new user option C{--install-config} is available.
+      * All installation target directories not explicitly given on the command
+        line default to the targets where gnue-common was installed.
+      * Before installation, dependencies defined in the L{Setup} instance are
+        checked.
+      * Translation catalogs are installed automatically.
+    """
+
+    user_options = distutils.command.install.install.user_options
+    i = 0
+    for option in user_options:
+        i = i + 1
+        if option[0] == "install-data=":
+            user_options.insert(i, ("install-config=", None,
+                             "installation directory for configuration files"))
+            break
+
+
+    # -------------------------------------------------------------------------
+    # Initalize options
+    # -------------------------------------------------------------------------
+
+    def initialize_options(self):
+        """
+        Initialize options.
+        """
+
+        distutils.command.install.install.initialize_options(self)
+        self.install_config = None
+
+
+    # -------------------------------------------------------------------------
+    # Finalize options - set all install targets
+    # -------------------------------------------------------------------------
+
+    def finalize_options(self):
+        """
+        Finalize options and set all install targets.
+        """
+
+        if self.install_lib is None:
+            self.install_lib = gnue.paths.lib
+        if self.install_scripts is None:
+            self.install_scripts = gnue.paths.scripts
+        if self.install_data is None:
+            self.install_data = gnue.paths.data
+        if self.install_config is None:
+            self.install_config = gnue.paths.config
+
+        distutils.command.install.install.finalize_options(self)
+
+
+    # -------------------------------------------------------------------------
+    # Run the install command
+    # -------------------------------------------------------------------------
+
+    def run(self):
+        """
+        Run the install command.
+        """
+
+        _setup.check_dependencies()
+
+        self.__outputs = []
+
+        # install translations
+        if os.path.isdir('po'):
+            # copy files
+            for fname in os.listdir('po'):
+                if fname[-4:] == '.gmo':
+                    src = os.path.join('po', fname)
+                    dst = os.path.join(self.install_data, 'share', 'locale',
+                            fname[:-4], 'LC_MESSAGES')
+                    self.mkpath(dst)
+                    dst = os.path.join(dst, _setup.name + '.mo')
+                    self.copy_file(src, dst)
+                    self.__outputs.append(dst)
+
+        distutils.command.install.install.run(self)
+
+
+    # -------------------------------------------------------------------------
+    # install.get_outputs: list all installed files
+    # -------------------------------------------------------------------------
+
+    def get_outputs(self):
+        """
+        List all installed files.
+        """
+
+        return distutils.command.install.install.get_outputs(self) \
+               + self.__outputs
+
+
+# =============================================================================
+# Basic class for setup scripts of GNUe packages
+# =============================================================================
+
+class Setup:
+    """
+    Base class for setup scripts of GNU Enterprise packages.
+
+    Each package creates a descendant of this class and defines some class
+    variables and overwrites the L{build_files} and L{check_dependencies}
+    methods to define the exact parameters for this class.
+
+    @cvar name: Name of the package. Taken from the root module's PACKAGE
+        variable by default.
+    @cvar version: Version of the package. Taken from the root module's VERSION
+        variable by default.
+    @cvar description: Short description of the package. Taken from the root
+        module's TITLE by default.
+    @cvar long_description: Long description of the package. Defaults to an
+        empty string.
+    @cvar author: Author of the package. Defaults to "GNU Enterprise Team".
+    @cvar author_email: E-Mail-Address of the package author. Defaults to
+        "address@hidden".
+    @cvar url: Web address of the package. Defaults to
+        "http://www.gnuenterprise.org";.
+    @cvar license: License of the package. Defaults to "GPL".
+    @cvar packages: List of all Python packages in this GNUe package. Defaults
+        to None, which means the list is automatically determined.
+    @cvar package_dir: Dictionary with the Python package destination as key
+        and the source as value, like {'gnue.forms': 'src'}. Defaults to an
+        empty dictionary and must be overwritten by descendants.
+    @cvar scripts: List of executable scripts to install. Defaults to an empty
+        list.
+    @cvar data_files: List of data files to install, where each list item is a
+        tuple with the target directory and the list of files to install there.
+        Defaults to an empty list.
+    """
+
+    name             = package_info.PACKAGE.lower()
+    version          = package_info.VERSION
+    description      = package_info.TITLE
+    long_description = ""
+    author           = "GNU Enterprise Team"
+    author_email     = "address@hidden"
+    url              = "http://www.gnuenterprise.org";
+    license          = "GPL"
+    packages         = None
+    package_dir      = {}
+    scripts          = []
+    data_files       = []
+
+    # -------------------------------------------------------------------------
+    # Build list of file
+    # -------------------------------------------------------------------------
+
+    def build_files(self, action):
+        """
+        Build a list of files depending on a given action.
+
+        This method can be overwritten by descendants to dynamically build
+        files during creation of the source distribution.
+
+        @param action: C{'sdist'} means a source distribution is created,
+            C{'build'} means a build/install is run from a Subversion checkout.
+        """
+        pass
+
+
+    # -------------------------------------------------------------------------
+    # Check if all dependencies are met
+    # -------------------------------------------------------------------------
+
+    def check_dependencies(self):
+        """
+        Check all dependencies needed to install the package.
+
+        This method can be overwritten by descendants to check whether all
+        dependencies are installed. This function must raise an exception if
+        any check fails.
+        """
+        pass
+
+
+    # -------------------------------------------------------------------------
+    # Create the svnrev.py file
+    # -------------------------------------------------------------------------
+
+    def build_svnrev(self, filename):
+        """
+        Create the file 'svnrev.py' which contains the current Subversion
+        revision.
+
+        Only used internally, do not use this function externally.
+        """
+
+        log.info("building svnrev.py")
+        output = open(filename, 'w')
+        output.write('svnrev = %r' % version.get_svn_revision('src'))
+        output.close()
+
+
+    # -------------------------------------------------------------------------
+    # Helper methods for descendants
+    # -------------------------------------------------------------------------
+
+    def allfiles(self, directory):
+        """
+        Get a list of files in a given directory, excluding some specials like
+        Makefile, .svn, CSV and so on.
+
+        Descendants can use this function to build the C{data_files} parameter.
+        """
+
+        directory = os.path.normpath(directory)
+        exclude = [".svn", "CVS", "README.cvs", ".cvsignore", "Makefile"]
+        return [directory + "/" + fname for fname in os.listdir(directory) \
+                if not fname in exclude and
+                   not os.path.isdir(os.path.join(directory, fname))]
+
+
+    # -------------------------------------------------------------------------
+    # Get all packages in a directory
+    # -------------------------------------------------------------------------
+
+    def __get_packages(self, directory, package):
+
+        content = os.listdir(directory)
+        result = []
+        if "__init__.py" in content:
+            result = [package]
+            for name in content:
+                fullname = os.path.join(directory, name)
+                if os.path.isdir(fullname):
+                    result = result + self.__get_packages(fullname, package +
+                            "." + name)
+        return result
+
+
+    # -------------------------------------------------------------------------
+    # Call the actual setup routine
+    # -------------------------------------------------------------------------
+
+    def run(self):
+        """
+        Run the setup routine.
+        """
+
+        # Set global variable.
+        global _setup
+        _setup = self
+
+        # Decprecated method to set parameters in a dictionary.
+        if self.__class__.__dict__.has_key('set_params'):
+            setup_params = {}
+            self.set_params(setup_params)
+            for key in ['name', 'version', 'description', 'long_description',
+                    'author', 'author_email', 'url', 'license', 'packages',
+                    'package_dir', 'scripts', 'data_files']:
+                if setup_params.has_key(key):
+                    self.__dict__[key] = setup_params[key]
+
+        # Find out all packages automatically.
+        if self.packages is None:
+            self.packages = []
+            for module, directory in self.package_dir.items():
+                self.packages.extend(self.__get_packages(directory, module))
+
+        # Remove data files that are not available.
+        for target, files in self.data_files:
+            i = 0
+            while i < len(files):
+                fname = files[i]
+                if os.path.isfile(fname):
+                    i += 1
+                else:
+                    log.warn("warning: did not find file %s" % fname)
+                    files.remove(fname)
+
+        # Now call setup.
+        setup(name             = self.name,
+              version          = self.version,
+              description      = self.description,
+              long_description = self.long_description,
+              author           = self.author,
+              author_email     = self.author_email,
+              url              = self.url,
+              license          = self.license,
+              packages         = self.packages,
+              package_dir      = self.package_dir,
+              scripts          = self.scripts,
+              data_files       = self.data_files,
+
+              # Override certain command classes with our own ones
+              cmdclass = {"sdist":   SDist,
+                          "build":   Build,
+                          "install": Install})


Property changes on: trunk/gnue-common/src/base/setup.py
___________________________________________________________________
Name: svn:keywords
   + Id

Copied: trunk/gnue-common/src/base/version.py (from rev 9928, 
trunk/gnue-common/src/utils/version.py)
===================================================================
--- trunk/gnue-common/src/base/version.py                               (rev 0)
+++ trunk/gnue-common/src/base/version.py       2009-10-06 13:01:35 UTC (rev 
9934)
@@ -0,0 +1,267 @@
+# GNU Enterprise Common Library - Utilities - Version handling
+#
+# Copyright 2001-2009 Free Software Foundation
+#
+# This file is part of GNU Enterprise
+#
+# GNU Enterprise 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, or (at your option) any later version.
+#
+# GNU Enterprise 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 program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id$
+"""
+Helper functions for version handling.
+
+Version numbers in GNU Enterprise
+=================================
+
+Releases
+--------
+
+GNU Enterprise is under ongoing development, and once a new set of functions is
+ready to be used, a release is made.
+
+Releases are numbered with a two-part release number, like 0.6 or 1.0 or 2.4.
+
+Builds
+------
+
+A build is a specific version of the software. For every release, several
+builds are made.
+
+Before the release, so called "prerelease" or "unstable" builds are made. The
+version number of these builds consist of the release number of the upcoming
+release, a dash, the name of the phase of the release cycle, and the build
+number within the phase.
+
+The first phase of the release cycle is "alpha", in which the software is
+expected to have bugs, and new features usually are freshly (and probably
+incompletely) implemented. As soon as the software is deemed feature-complete,
+it switches to "beta" phase, in which the bug hunting season starts. Once the
+developers feel that no serious bugs should be left over, the "pre" phase
+begins. In the last phase before the release, the versions are named "rc"
+(meaning "release candidate").
+
+Then the software goes into the stable (read: end user suitable) phase. The
+first stable version of each release ends in ".0", but people will still find
+bugs or major improvements, and there will be further bug fix builds within the
+same release cycle, where the last number is incremented.
+
+Snapshots
+---------
+
+Some people want to be on the bleeding edge of development and use Subversion
+snapshots. The version number of such a snapshot is the version number of the
+last build, a "+" sign, the text "svn", a dot, and the Subversion revision.
+
+Defining the version number
+---------------------------
+
+To define the version number of a package, create a L{Version} object and
+assign it to a variable named __version__ in the __init__.py file in the
+package root::
+    try:
+        import svnrev
+        svn_revision = svnrev.svnrev
+    except ImportError:
+        svn_revision = None
+    from gnue.common.base import version
+    __version__ = version.Version(0, 1, 'alpha', 1, svn_revision)
+
+The above example supports a file "svnrev.py" which defines the Subversion
+snapshot.  This makes it possible to show the full version number of a snapshot
+even if the snapshot was installed from a tarball, if the tarball contains this
+file.  The L{gnue.common.base.setup} infrastructure automatically builds this
+file when necessary.
+"""
+
+import os
+import sys
+
+__all__ = ['get_svn_revision', 'Version']
+
+
+# =============================================================================
+# Find out current SVN revision
+# =============================================================================
+
+def get_svn_revision(directory):
+    """
+    Find out the SVN revision of the last change in the current directory.
+
+    The current directory must be an SVN checkout, and the "svn" command must
+    be available.
+
+    This function only works on POSIX systems. On other systems, it returns
+    C{'unknown'}.
+
+    If the environment variable C{GNUE_BUILD} is set, the function returns 0.
+
+    @param directory: Source directory to check the revision for.
+    """
+
+    if os.environ.has_key('GNUE_BUILD'):
+        return 0
+
+    if os.name != 'posix':
+        return 'unknown'
+
+    if os.path.islink(directory):
+        directory = os.readlink(directory)
+
+    cmd = ("LANG=C svn info %s | grep 'Last Changed Rev:' " + \
+            "| sed -e 's/Last Changed Rev: //'") % directory
+
+    import commands
+    # Unfortunately, svn does not set an exit status on all errors, so there's
+    # no use in testing the status.
+    output = commands.getoutput(cmd)
+    try:
+        return int(output)
+    except ValueError:
+        return 'unknown'
+
+
+# =============================================================================
+# Version class
+# =============================================================================
+
+class Version:
+    """
+    A version number consisting of several parts.
+
+    A version number defined by this class can be one of 4 types:
+
+    Unstable Build
+    ==============
+        A version number for an unstable build follows the format
+        <major>.<minor>-<phase><build> (e.g. "1.5-pre2").
+
+    Unstable Snapshot
+    =================
+        A version number for an unstable SVN snapshot follows the format
+        <major>.<minor>-<phase><build>+svn.<svn> (e.g. "1.5-pre2+svn.9876).
+
+    Stable Build
+    ============
+        A version number for a stable build follows the format
+        <major>.<minor>.<build> (e.g. 1.5.2).
+
+    Stable Snapshot
+    ===============
+        A version number for a stable snapshot follows the format
+        <major>.<minor>.<build>+svn.<svn> (e.g. 1.5.2+svn.9876).
+
+    @ivar major: Major release number
+    @ivar minor: Minor release number
+    @ivar phase: Phase of the release process. Can be C{'alpha'}, C{'beta'},
+        C{'pre'}, C{'rc'}, or C{'final'}. If the phase is C{'final'}, it is a
+        stable version, otherwise it is an unstable version.
+    @ivar build: Build number within the phase.
+    @ivar svn: SVN revision number. If this parameter is 0, the version is an
+        explicit build, otherwise it is an SVN snapshot.
+    """
+
+    __phases = {
+            'alpha': 'a',
+            'beta': 'b',
+            'pre': 'd',
+            'rc': 'e',
+            'final': 'f'}
+
+    # -------------------------------------------------------------------------
+    # Constructor
+    # -------------------------------------------------------------------------
+
+    def __init__(self, major, minor, phase, build, svn):
+        """
+        Create a new Version object instance.
+
+        @param major: Major release number.
+        @param minor: Minor release number.
+        @param phase: Phase of the release process. Can be C{'alpha'},
+            C{'beta'}, C{'pre'}, C{'rc'}, or C{'final'}. If the phase is
+            C{'final'}, it is a stable version, otherwise it is an unstable
+            version.
+        @param build: Build number within the phase.
+        @param svn: SVN revision number. If this parameter is 0, the version is
+            an explicit build, otherwise it is an SVN snapshot. If this
+            parameter is C{None}, the SVN revision is determined automatically.
+        """
+
+        assert isinstance(major, int) and major >= 0 and major < 100
+        assert isinstance(minor, int) and minor >= 0 and minor < 100
+        assert phase in self.__phases.keys()
+        assert isinstance(build, int) and build >= 0 and build < 10
+
+        self.major = major
+        self.minor = minor
+        self.phase = phase
+        self.build = build
+        self.svn = svn
+
+        if self.svn is None:
+            caller_file = sys._getframe(1).f_code.co_filename
+            self.svn = get_svn_revision(os.path.dirname(caller_file))
+
+
+    # -------------------------------------------------------------------------
+    # Get version number
+    # -------------------------------------------------------------------------
+
+    def get_version(self):
+        """
+        Return the version number as a human readable string.
+        """
+
+        if self.phase == 'final':
+            result = '%s.%s.%s' % (self.major, self.minor, self.build)
+        else:
+            result = '%s.%s-%s%s' % (self.major, self.minor, self.phase,
+                    self.build)
+
+        if self.svn:
+            result += '+svn.%s' % self.svn
+
+        return result
+
+
+    # -------------------------------------------------------------------------
+    # Get hexversion number
+    # -------------------------------------------------------------------------
+
+    def get_hexversion(self):
+        """
+        Return the version number as an eight character hexadecimal number.
+
+        Later versions will always result in higher numbers.
+        """
+
+        if not self.svn:
+            svn = '00'
+        else:
+            svn = '80'
+
+        return '%02d%02d%s%01d%s' % (self.major, self.minor,
+                self.__phases[self.phase], self.build, svn)
+
+
+# =============================================================================
+# Self test code
+# =============================================================================
+
+if __name__ == '__main__':
+    version = Version(1, 5, 'beta', 3, None)
+    print version.get_version()
+    print version.get_hexversion()

Modified: trunk/gnue-common/src/setup/GSetup.py
===================================================================
--- trunk/gnue-common/src/setup/GSetup.py       2009-10-06 06:34:50 UTC (rev 
9933)
+++ trunk/gnue-common/src/setup/GSetup.py       2009-10-06 13:01:35 UTC (rev 
9934)
@@ -21,9 +21,7 @@
 #
 # $Id: GSetup.py,v 1.4 2003/10/06 18:33:16 reinhard Exp $
 """
-Base classes for package setup based on distutils
-
-This module is deprecated.  Please use gnue.common.utils.setup instead.
+Deprecated module.  Use L{gnue.common.base.setup} instead.
 """
 
-from gnue.common.utils.setup import GSetup
+from gnue.common.base.setup import Setup as GSetup

Deleted: trunk/gnue-common/src/utils/setup.py
===================================================================
--- trunk/gnue-common/src/utils/setup.py        2009-10-06 06:34:50 UTC (rev 
9933)
+++ trunk/gnue-common/src/utils/setup.py        2009-10-06 13:01:35 UTC (rev 
9934)
@@ -1,517 +0,0 @@
-# GNU Enterprise Common Library - Installation Helper For Tools
-#
-# This file is part of GNU Enterprise.
-#
-# GNU Enterprise 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, or (at your option) any later version.
-#
-# GNU Enterprise 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 program; see the file COPYING. If not,
-# write to the Free Software Foundation, Inc., 59 Temple Place
-# - Suite 330, Boston, MA 02111-1307, USA.
-#
-# Copyright 2001-2009 Free Software Foundation
-#
-# $Id: GSetup.py,v 1.4 2003/10/06 18:33:16 reinhard Exp $
-"""
-Base classes for package setup based on distutils
-"""
-
-import sys
-import time
-import os
-
-from distutils import log
-from distutils.core import setup
-from distutils.filelist import FileList
-
-import distutils.command.sdist
-import distutils.command.build
-import distutils.command.install
-
-import gnue.paths
-
-from gnue.common.utils import version
-
-__all__ = ['GSetup']
-
-# -----------------------------------------------------------------------------
-# Check Python version
-# -----------------------------------------------------------------------------
-
-try:
-    if sys.hexversion < 0x02030000:
-        raise AttributeError
-
-except AttributeError:
-    print "-" * 70
-    print """
-You are running Python %s.
-
-GNU Enterprise requires at least Python 2.3.
-If you have a later version installed, you should run setup.py
-against that version. For example, if you have Python 2.3
-installed, you may need to run:
-
-python2.3 setup.py
-""" % sys.version.split()[0]
-    print "-" * 70
-    sys.exit(1)
-
-# -----------------------------------------------------------------------------
-# Global GSetup instance
-# -----------------------------------------------------------------------------
-
-_setup = None
-
-# =============================================================================
-# SDist: build files to be distributed first
-# =============================================================================
-
-class SDist(distutils.command.sdist.sdist):
-    """
-    Build files to be distributed
-    """
-
-    # -------------------------------------------------------------------------
-    # Run the sdist command
-    # -------------------------------------------------------------------------
-
-    def run(self):
-        """
-        Run the sdist command
-        """
-        global _setup
-
-        _setup.do_build_files('sdist')
-        distutils.command.sdist.sdist.run(self)
-
-
-    # -------------------------------------------------------------------------
-    # Remove files not used
-    # -------------------------------------------------------------------------
-
-    def prune_file_list(self):
-        """
-        Prune the list of files included
-        """
-        distutils.command.sdist.sdist.prune_file_list(self)
-        self.filelist.exclude_pattern('*.dist_template', anchor=0)
-
-
-    # -------------------------------------------------------------------------
-    # Create the directory tree that will become the source distribution arch.
-    # -------------------------------------------------------------------------
-
-    def make_release_tree(self, base_dir, files):
-        """
-        Create the directory tree that will become the source distribution
-        archive.
-        """
-        distutils.command.sdist.sdist.make_release_tree(self, base_dir, files)
-        self.process_templates(base_dir)
-
-        _setup.do_build_svnrev(os.path.join(base_dir, 'src', 'svnrev.py'))
-
-
-    # -------------------------------------------------------------------------
-    # Process all template files 
-    # -------------------------------------------------------------------------
-
-    def process_templates(self, target):
-        """
-        Process all distribution template files.  Such a template file is
-        called "<filename>.dist_template" and will be stored as "<filename>"
-        after processing.  This method replaces the following strings by their
-        corresponding values:
-
-          - :PACKAGE:  Name of the package, i.e. 'gnue-forms'
-          - :TITLE:    Title of the package, i.e. 'GNU Enterprise Forms'
-          - :VERSION:  Full version of the package, i.e. '0.6.9+svn.9794'
-          - :MAJOR:    The major version, i.e. '0'
-          - :MINOR:    The minor version, i.e. '6'
-          - :PHASE:    The phase, i.e. 'final'
-          - :BUILD:    The build, i.e. '1'
-          - :SVN:      The current SubVersion revision
-          - :DATE_ISO: The date of the package formatted as YYYY-MM-DD
-          - :DATE_RFC: The date of the package formatted according to RFC 822
-          - :TIME:     The time of the package formattes as HH:MM:SS
-          - :FINAL:    If the build is final it contains the build number,
-                       otherwise '0'
-        """
-
-        # Build list of files to be processed.
-        filelist = FileList()
-        if filelist.include_pattern('*.dist_template', anchor=0) == 0:
-            # Nothing to do.
-            return
-
-        # FIXME: For compatibility with old packages not yet using the version
-        # module. Change to unconditional import in gnue-common 0.8.
-        try:
-            from src import version
-
-        except:
-            return
-
-        # List of keywords to replace.
-        keywords = {
-                ':PACKAGE:': self.distribution.get_name(),
-                ':TITLE:': self.distribution.get_description(),
-                ':VERSION:': self.distribution.get_version(),
-                ':MAJOR:': str(version.major),
-                ':MINOR:': str(version.minor),
-                ':PHASE:': str(version.phase),
-                ':BUILD:': str(version.build),
-                ':SVN:': str(version.svn),
-                ':DATE_ISO:': time.strftime('%Y-%m-%d', time.gmtime()),
-                ':DATE_RFC:': time.strftime('%a, %d %b %Y', time.gmtime()),
-                ':TIME:': time.strftime('%H:%M:%S', time.gmtime())}
-        
-        # Hack for version numbering schemes that are limited to x.y.z.
-        if version.phase == 'final':
-            keywords[':FINAL:'] = str(version.build)
-        else:
-            keywords[':FINAL:'] = '0'
-
-        for src in filelist.files:
-            dst = os.path.join(target, src[:-14])
-            args = (src, dst, keywords)
-            self.execute(self.__process_template, args,
-                    "generating %s from %s" % (dst, src))
-
-
-    # -------------------------------------------------------------------------
-    # Process a single template
-    # -------------------------------------------------------------------------
-
-    def __process_template(self, src, dst, keywords):
-
-        infile = open(src, 'r')
-        content = infile.read()
-        infile.close()
-
-        for keyword, value in keywords.iteritems():
-            content = content.replace(keyword, value)
-
-        outfile = open(dst, 'w')
-        outfile.write(content)
-        outfile.close()
-
-        # Let destination file have the same mode than the source file.
-        os.chmod(dst, os.stat(src).st_mode)
-
-
-# =============================================================================
-# build: if done from SVN, build files to be installed first
-# =============================================================================
-
-class Build(distutils.command.build.build):
-    """
-    Build files to be installed
-    """
-
-    # -------------------------------------------------------------------------
-    # Run the command
-    # -------------------------------------------------------------------------
-
-    def run(self):
-        """
-        Run the build command
-        """
-        global _setup
-
-        if not os.path.isfile("PKG-INFO"):         # downloaded from SVN?
-            _setup.do_build_files('build')
-
-        distutils.command.build.build.run(self)
-
-        if not os.path.isfile("PKG-INFO"):
-            _setup.do_build_svnrev(os.path.join(self.build_lib, 'gnue',
-                  _setup.package[5:].lower(), 'svnrev.py'))
-
-
-# =============================================================================
-# install: Some user_options are no longer allowed
-# =============================================================================
-
-class Install(distutils.command.install.install):
-    """
-    Install the package
-    """
-
-    # Commented out because sometimes, to create packages, we want to install
-    # other tools in a different target directory than common is installed
-    #user_options = distutils.command.install.install.user_options
-
-    #allowed_options = ["root=", "compile", "no-compile", "optimize=", "force",
-    #                   "skip-build", "record="]
-
-    #user_options = [opt for opt in user_options if opt [0] in allowed_options]
-
-
-    # TODO: this code is executed as soon as this module get's importet.
-    # Need to check wether this is really what we want here.
-    user_options = distutils.command.install.install.user_options
-    i = 0
-    for option in user_options:
-        i = i + 1
-        if option[0] == "install-data=":
-            user_options.insert(i, ("install-config=", None,
-                             "installation directory for configuration files"))
-            break
-
-
-    # -------------------------------------------------------------------------
-    # Initalize options
-    # -------------------------------------------------------------------------
-
-    def initialize_options(self):
-        """
-        Initialize options
-        """
-
-        distutils.command.install.install.initialize_options(self)
-        self.install_config = None
-
-
-    # -------------------------------------------------------------------------
-    # Finalize options - set all install targets
-    # -------------------------------------------------------------------------
-
-    def finalize_options(self):
-        """
-        Finalize options and set all install targets
-        """
-
-        if self.install_lib is None:
-            self.install_lib = gnue.paths.lib
-        if self.install_scripts is None:
-            self.install_scripts = gnue.paths.scripts
-        if self.install_data is None:
-            self.install_data = gnue.paths.data
-        if self.install_config is None:
-            self.install_config = gnue.paths.config
-
-        distutils.command.install.install.finalize_options(self)
-
-
-    # -------------------------------------------------------------------------
-    # install.run: generate and install path dependent files afterwards
-    # -------------------------------------------------------------------------
-
-    def run(self):
-        """
-        Run the install command
-        """
-
-        global _setup
-
-        _setup.check_dependencies()
-
-        self.__outputs = []
-
-        # install translations
-        if os.path.isdir('po'):
-            # copy files
-            for fname in os.listdir('po'):
-                if fname[-4:] == '.gmo':
-                    src = os.path.join('po', fname)
-                    dst = os.path.join(self.install_data, 'share', 'locale',
-                            fname[:-4], 'LC_MESSAGES')
-                    self.mkpath(dst)
-                    dst = os.path.join(dst, _setup.package + '.mo')
-                    self.copy_file(src, dst)
-                    self.__outputs.append(dst)
-
-        distutils.command.install.install.run(self)
-
-
-    # -------------------------------------------------------------------------
-    # install.get_outputs: list all installed files
-    # -------------------------------------------------------------------------
-
-    def get_outputs(self):
-        """
-        List all installed files
-        """
-
-        return distutils.command.install.install.get_outputs(self) \
-               + self.__outputs
-
-
-# =============================================================================
-# GSetup: Basic class for setup scripts of GNUe packages
-# =============================================================================
-
-class GSetup:
-    """
-    Base class for setup scripts of GNU Enterprise packages
-    """
-
-    # -------------------------------------------------------------------------
-    # Abstract methods: setup.py scripts generally override these
-    # -------------------------------------------------------------------------
-
-    def set_params(self, params):
-        """
-        Define setup paramters
-        """
-        pass
-
-
-    # -------------------------------------------------------------------------
-    # Build list of file
-    # -------------------------------------------------------------------------
-
-    def build_files(self, action):
-        """
-        Build a list of files depending on a given action
-        """
-        pass
-
-
-    # -------------------------------------------------------------------------
-    # Check if all dependencies are met
-    # -------------------------------------------------------------------------
-
-    def check_dependencies(self):
-        """
-        Check all dependencies
-        """
-        pass
-
-
-    # -------------------------------------------------------------------------
-    # Build files if called from SVN
-    # -------------------------------------------------------------------------
-
-    def do_build_files(self, action):
-        """
-        Build all files if called from SVN
-        """
-
-        # do package specific stuff
-        self.build_files(action)
-
-
-    # -------------------------------------------------------------------------
-    # Create the svnrev.py file
-    # -------------------------------------------------------------------------
-
-    def do_build_svnrev(self, filename):
-        """
-        Create the file 'svnrev.py' which contains the current SubVersion
-        revision.
-        """
-
-        log.info("building svnrev.py")
-        output = open(filename, 'w')
-        output.write('svnrev = %r' % version.get_svn_revision('src'))
-        output.close()
-
-
-    # -------------------------------------------------------------------------
-    # Helper methods for descendants
-    # -------------------------------------------------------------------------
-
-    def allfiles(self, directory):
-        """
-        Get a list of files in a given directory, excluding some specials like
-        Makefile, .svn, CSV and so on
-        """
-
-        directory = os.path.normpath(directory)
-        exclude = [".svn", "CVS", "README.cvs", ".cvsignore", "Makefile"]
-        return [directory + "/" + fname for fname in os.listdir(directory) \
-                if not fname in exclude and
-                   not os.path.isdir(os.path.join(directory, fname))]
-
-
-    # -------------------------------------------------------------------------
-    # Get all packages in a directory
-    # -------------------------------------------------------------------------
-
-    def __get_packages(self, directory, package):
-
-        content = os.listdir(directory)
-        result = []
-        if "__init__.py" in content:
-            result = [package]
-            for name in content:
-                fullname = os.path.join(directory, name)
-                if os.path.isdir(fullname):
-                    result = result + self.__get_packages(fullname, package +
-                            "." + name)
-        return result
-
-
-    # -------------------------------------------------------------------------
-    # Call the actual setup routine
-    # -------------------------------------------------------------------------
-
-    def run(self):
-        """
-        Run the setup routine
-        """
-
-        global _setup
-
-        # set global variable
-        _setup = self
-
-        setup_params = {"cmdclass_sdist": SDist,
-                        "cmdclass_build": Build,
-                        "cmdclass_install": Install
-                        }
-
-        _setup.set_params(setup_params)
-
-        # make package available
-        self.package = setup_params["name"]
-
-        # find out all packages
-        if not setup_params.has_key("packages"):
-            packages = []
-
-            for module, directory in setup_params["package_dir"].items():
-                packages = packages + self.__get_packages(directory, module)
-
-            setup_params["packages"] = packages
-
-        # remove data files that are not available
-        for target, files in setup_params["data_files"]:
-            i = 0
-            while i < len(files):
-                fname = files[i]
-                if os.path.isfile(fname):
-                    i += 1
-                else:
-                    log.warn("warning: did not find file %s" % fname)
-                    files.remove(fname)
-
-        # now call setup
-        setup(name             = setup_params["name"],
-              version          = setup_params["version"],
-              description      = setup_params["description"],
-              long_description = setup_params["long_description"],
-              author           = setup_params["author"],
-              author_email     = setup_params["author_email"],
-              url              = setup_params["url"],
-              license          = setup_params["license"],
-              packages         = setup_params["packages"],
-              package_dir      = setup_params["package_dir"],
-              scripts          = setup_params["scripts"],
-              data_files       = setup_params["data_files"],
-
-              # Override certain command classes with our own ones
-              cmdclass = {"sdist":   setup_params["cmdclass_sdist"],
-                          "build":   setup_params["cmdclass_build"],
-                          "install": setup_params["cmdclass_install"]})

Modified: trunk/gnue-common/src/utils/version.py
===================================================================
--- trunk/gnue-common/src/utils/version.py      2009-10-06 06:34:50 UTC (rev 
9933)
+++ trunk/gnue-common/src/utils/version.py      2009-10-06 13:01:35 UTC (rev 
9934)
@@ -21,227 +21,7 @@
 #
 # $Id$
 """
-Helper functions for version handling.
-
-About the release process in GNU Enterprise
-===========================================
-
-Releases
---------
-
-GNU Enterprise is under ongoing development, and once a new set of functions is
-ready to be used, a release is made.
-
-Releases are numbered with a two-part release number, like 0.6 or 1.0 or 2.4.
-
-Builds
-------
-
-A build is a specific version of the software. For every release, several
-builds are made.
-
-Before the release, so called "prerelease" or "unstable" builds are made. The
-version number of these builds consist of the release number of the upcoming
-release, a dash, the name of the phase of the release cycle, and the build
-number within the phase.
-
-The first phase of the release cycle is "alpha", in which the software is
-expected to have bugs, and new features usually are freshly (and probably
-incompletely) implemented. As soon as the software is deemed feature-complete,
-it switches to "beta" phase, in which the bug hunting season starts. Once the
-developers feel that no serious bugs should be left over, the "pre" phase
-begins. In the last phase before the release, the versions are named "rc"
-(meaning "release candidate").
-
-Then the software goes into the stable (read: end user suitable) phase. The
-first stable version of each release ends in ".0", but people will still find
-bugs or major improvements, and there will be further bug fix builds within the
-same release cycle, where the last number is incremented.
-
-Snapshots
----------
-
-Some people want to be on the bleeding edge of development and use Subversion
-snapshots. The version number of such a snapshot is the version number of the
-last build, a "+" sign, the text "svn", a dot, and the Subversion revision.
+Deprecated module.  Use L{gnue.common.base.version} instead.
 """
 
-import os
-import sys
-
-__all__ = ['get_svn_revision', 'Version']
-
-
-# =============================================================================
-# Find out current SVN revision
-# =============================================================================
-
-def get_svn_revision(directory):
-    """
-    Find out the SVN revision of the last change in the current directory.
-
-    The current directory must be an SVN checkout, and the "svn" command must
-    be available.
-
-    This function only works on POSIX systems. On other systems, it returns
-    C{'unknown'}.
-
-    If the environment variable C{GNUE_BUILD} is set, the function returns 0.
-
-    @param directory: Source directory to check the revision for.
-    """
-
-    if os.environ.has_key('GNUE_BUILD'):
-        return 0
-
-    if os.name != 'posix':
-        return 'unknown'
-
-    if os.path.islink(directory):
-        directory = os.readlink(directory)
-
-    cmd = ("LANG=C svn info %s | grep 'Last Changed Rev:' " + \
-            "| sed -e 's/Last Changed Rev: //'") % directory
-
-    import commands
-    # Unfortunately, svn does not set an exit status on all errors, so there's
-    # no use in testing the status.
-    output = commands.getoutput(cmd)
-    try:
-        return int(output)
-    except ValueError:
-        return 'unknown'
-
-
-# =============================================================================
-# Version class
-# =============================================================================
-
-class Version:
-    """
-    A version number consisting of several parts.
-
-    A version number defined by this class can be one of 4 types:
-
-    Unstable Build
-    ==============
-        A version number for an unstable build follows the format
-        <major>.<minor>-<phase><build> (e.g. "1.5-pre2").
-
-    Unstable Snapshot
-    =================
-        A version number for an unstable SVN snapshot follows the format
-        <major>.<minor>-<phase><build>+svn.<svn> (e.g. "1.5-pre2+svn.9876).
-
-    Stable Build
-    ============
-        A version number for a stable build follows the format
-        <major>.<minor>.<build> (e.g. 1.5.2).
-
-    Stable Snapshot
-    ===============
-        A version number for a stable snapshot follows the format
-        <major>.<minor>.<build>+svn.<svn> (e.g. 1.5.2+svn.9876).
-
-    @ivar major: Major release number
-    @ivar minor: Minor release number
-    @ivar phase: Phase of the release process. Can be C{'alpha'}, C{'beta'},
-        C{'pre'}, C{'rc'}, or C{'final'}. If the phase is C{'final'}, it is a
-        stable version, otherwise it is an unstable version.
-    @ivar build: Build number within the phase.
-    @ivar svn: SVN revision number. If this parameter is 0, the version is an
-        explicit build, otherwise it is an SVN snapshot.
-    """
-
-    __phases = {
-            'alpha': 'a',
-            'beta': 'b',
-            'pre': 'd',
-            'rc': 'e',
-            'final': 'f'}
-
-    # -------------------------------------------------------------------------
-    # Constructor
-    # -------------------------------------------------------------------------
-
-    def __init__(self, major, minor, phase, build, svn):
-        """
-        Create a new Version object instance.
-
-        @param major: Major release number.
-        @param minor: Minor release number.
-        @param phase: Phase of the release process. Can be C{'alpha'},
-            C{'beta'}, C{'pre'}, C{'rc'}, or C{'final'}. If the phase is
-            C{'final'}, it is a stable version, otherwise it is an unstable
-            version.
-        @param build: Build number within the phase.
-        @param svn: SVN revision number. If this parameter is 0, the version is
-            an explicit build, otherwise it is an SVN snapshot. If this
-            parameter is C{None}, the SVN revision is determined automatically.
-        """
-
-        assert isinstance(major, int) and major >= 0 and major < 100
-        assert isinstance(minor, int) and minor >= 0 and minor < 100
-        assert phase in self.__phases.keys()
-        assert isinstance(build, int) and build >= 0 and build < 10
-
-        self.major = major
-        self.minor = minor
-        self.phase = phase
-        self.build = build
-        self.svn = svn
-
-        if self.svn is None:
-            caller_file = sys._getframe(1).f_code.co_filename
-            self.svn = get_svn_revision(os.path.dirname(caller_file))
-
-
-    # -------------------------------------------------------------------------
-    # Get version number
-    # -------------------------------------------------------------------------
-
-    def get_version(self):
-        """
-        Return the version number as a human readable string.
-        """
-
-        if self.phase == 'final':
-            result = '%s.%s.%s' % (self.major, self.minor, self.build)
-        else:
-            result = '%s.%s-%s%s' % (self.major, self.minor, self.phase,
-                    self.build)
-
-        if self.svn:
-            result += '+svn.%s' % self.svn
-
-        return result
-
-
-    # -------------------------------------------------------------------------
-    # Get hexversion number
-    # -------------------------------------------------------------------------
-
-    def get_hexversion(self):
-        """
-        Return the version number as an eight character hexadecimal number.
-
-        Later versions will always result in higher numbers.
-        """
-
-        if not self.svn:
-            svn = '00'
-        else:
-            svn = '80'
-
-        return '%02d%02d%s%01d%s' % (self.major, self.minor,
-                self.__phases[self.phase], self.build, svn)
-
-
-# =============================================================================
-# Self test code
-# =============================================================================
-
-if __name__ == '__main__':
-    version = Version(1, 5, 'beta', 3, None)
-    print version.get_version()
-    print version.get_hexversion()
+from gnue.common.base.version import *





reply via email to

[Prev in Thread] Current Thread [Next in Thread]