commit-gnue
[Top][All Lists]
Advanced

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

[gnue] r9843 - in trunk/gnue-common/src: setup utils


From: johannes
Subject: [gnue] r9843 - in trunk/gnue-common/src: setup utils
Date: Fri, 7 Dec 2007 08:57:59 -0600 (CST)

Author: johannes
Date: 2007-12-07 08:57:58 -0600 (Fri, 07 Dec 2007)
New Revision: 9843

Added:
   trunk/gnue-common/src/utils/setup.py
Modified:
   trunk/gnue-common/src/setup/GSetup.py
Log:
Moved GSetup.py from src/setup into src/utils/setup.py



Modified: trunk/gnue-common/src/setup/GSetup.py
===================================================================
--- trunk/gnue-common/src/setup/GSetup.py       2007-12-07 14:46:25 UTC (rev 
9842)
+++ trunk/gnue-common/src/setup/GSetup.py       2007-12-07 14:57:58 UTC (rev 
9843)
@@ -22,559 +22,8 @@
 # $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.
 """
 
-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
-        """
-
-        if os.name == 'posix':
-
-            # First check if we have everything installed we need to build the
-            # distribution
-
-            if os.path.isdir('po'):
-                # xgettext
-                if os.system("pygettext --version > /dev/null") != 0:
-                    log.fatal("Could not find 'pygettext'. Strange.")
-                    log.fatal("It should be included in the Python " \
-                              "distribution.")
-                    sys.exit(1)
-
-                # msgmerge
-                if os.system("msgmerge --version > /dev/null") != 0:
-                    log.fatal("Could not find 'msgmerge'. Please install " \
-                              "Gettext.")
-                    sys.exit(1)
-
-                # msgfmt
-                if os.system("msgfmt --version > /dev/null") != 0:
-                    log.fatal("Could not find 'msgfmt'. Please install " \
-                              "Gettext.")
-                    sys.exit(1)
-
-            # -----------------------------------------------------------------
-
-            # build translations
-            if os.path.isdir('po'):
-                log.info("building translations")
-                if os.system("cd po && make gmo") != 0:
-                    sys.exit(1)
-
-        else:
-            # on non posix systems just run msgfmt on existing .po files
-            if os.path.isdir('po'):
-                # msgfmt.py
-                argv0_path = os.path.dirname(os.path.abspath(sys.executable))
-                sys.path.append(argv0_path + "\\tools\\i18n")
-
-                msgfmt_ok = 0
-                try:
-                    import msgfmt
-                    msgfmt_ok = 1
-                except:
-                    pass
-
-                if msgfmt_ok == 1:
-                    # pygettext.py exist in Python, but no msgmerge, so
-                    # just create a placeholder...
-                    potfile = open('po/'+ self.package +'.pot', 'w')
-                    potfile.write("#placeholder")
-                    potfile.close()
-
-                    # build translations
-                    log.info("building translations")
-                    for f in os.listdir('po'):
-                        if f[-3:] == '.po':
-                            msgfmt.make('po/'+f, 'po/'+f[:-3]+'.gmo')
-                            msgfmt.MESSAGES = {}
-
-        # ---------------------------------------------------------------------
-
-        # 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"]})
+from gnue.common.utils.setup import GSetup

Added: trunk/gnue-common/src/utils/setup.py
===================================================================
--- trunk/gnue-common/src/utils/setup.py        2007-12-07 14:46:25 UTC (rev 
9842)
+++ trunk/gnue-common/src/utils/setup.py        2007-12-07 14:57:58 UTC (rev 
9843)
@@ -0,0 +1,580 @@
+# 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-2007 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
+        """
+
+        if os.name == 'posix':
+
+            # First check if we have everything installed we need to build the
+            # distribution
+
+            if os.path.isdir('po'):
+                # xgettext
+                if os.system("pygettext --version > /dev/null") != 0:
+                    log.fatal("Could not find 'pygettext'. Strange.")
+                    log.fatal("It should be included in the Python " \
+                              "distribution.")
+                    sys.exit(1)
+
+                # msgmerge
+                if os.system("msgmerge --version > /dev/null") != 0:
+                    log.fatal("Could not find 'msgmerge'. Please install " \
+                              "Gettext.")
+                    sys.exit(1)
+
+                # msgfmt
+                if os.system("msgfmt --version > /dev/null") != 0:
+                    log.fatal("Could not find 'msgfmt'. Please install " \
+                              "Gettext.")
+                    sys.exit(1)
+
+            # -----------------------------------------------------------------
+
+            # build translations
+            if os.path.isdir('po'):
+                log.info("building translations")
+                if os.system("cd po && make gmo") != 0:
+                    sys.exit(1)
+
+        else:
+            # on non posix systems just run msgfmt on existing .po files
+            if os.path.isdir('po'):
+                # msgfmt.py
+                argv0_path = os.path.dirname(os.path.abspath(sys.executable))
+                sys.path.append(argv0_path + "\\tools\\i18n")
+
+                msgfmt_ok = 0
+                try:
+                    import msgfmt
+                    msgfmt_ok = 1
+                except:
+                    pass
+
+                if msgfmt_ok == 1:
+                    # pygettext.py exist in Python, but no msgmerge, so
+                    # just create a placeholder...
+                    potfile = open('po/'+ self.package +'.pot', 'w')
+                    potfile.write("#placeholder")
+                    potfile.close()
+
+                    # build translations
+                    log.info("building translations")
+                    for f in os.listdir('po'):
+                        if f[-3:] == '.po':
+                            msgfmt.make('po/'+f, 'po/'+f[:-3]+'.gmo')
+                            msgfmt.MESSAGES = {}
+
+        # ---------------------------------------------------------------------
+
+        # 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"]})





reply via email to

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