commit-gnue
[Top][All Lists]
Advanced

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

gnue-common setup.py


From: Reinhard Mueller
Subject: gnue-common setup.py
Date: Tue, 23 Sep 2003 10:22:09 -0400

CVSROOT:        /cvsroot/gnue
Module name:    gnue-common
Branch:         
Changes by:     Reinhard Mueller <address@hidden>       03/09/23 10:22:09

Modified files:
        .              : setup.py 

Log message:
        First try of an improved setup.py.

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue-common/setup.py.diff?tr1=1.62&tr2=1.63&r1=text&r2=text

Patches:
Index: gnue-common/setup.py
diff -c gnue-common/setup.py:1.62 gnue-common/setup.py:1.63
*** gnue-common/setup.py:1.62   Mon Sep 22 19:27:18 2003
--- gnue-common/setup.py        Tue Sep 23 10:22:08 2003
***************
*** 1,5 ****
--- 1,7 ----
  #!/usr/bin/env python
  #
+ # GNU Enterprise Common Library - Installation Procedure
+ #
  # This file is part of GNU Enterprise.
  #
  # GNU Enterprise is free software; you can redistribute it
***************
*** 24,32 ****
  import string
  import os
  
! from src import VERSION
  
- # First of all, make sure this is a current enough Python release.
  try:
    if sys.hexversion < 0x02000000:
      raise AttributeError
--- 26,42 ----
  import string
  import os
  
! from distutils.core import setup
! from distutils.command.build import build
! from distutils.command.install import install
! from setupext import Data_Files, install_Data_Files
! 
! from src import PACKAGE, VERSION
! 
! # 
-----------------------------------------------------------------------------
! # Check Python version
! # 
-----------------------------------------------------------------------------
  
  try:
    if sys.hexversion < 0x02000000:
      raise AttributeError
***************
*** 43,157 ****
         python2.2 setup.py
  """ % string.split(sys.version)[0]
    print "-" * 70
!   sys.exit()
  
! #
! # hack to deal w/ fact distutils won't
! # allow us to set absolute path prefix
! # on windows
! #
  
! if not 'sdist' in sys.argv:
!   setupcfg = "setup.cfg.in"
!   # Was setup.cfg specified on the command line?
!   try:
!     index = sys.argv.index('--setup-cfg')
!     setupcfg = sys.argv[index+1]
!     sys.argv.pop(index)
!     sys.argv.pop(index)
  
!   except ValueError:
      pass
  
!   if sys.platform != 'win32' and '--prefix' not in sys.argv and '--root' not 
in sys.argv:
!     os.system ("""cp %s setup.cfg""" % setupcfg)
!   else:
!     try:
!       os.remove('setup.cfg')
!     except:
!       pass
  
! try:
!   import distutils
!   from distutils.command.build_scripts import build_scripts
!   from distutils.command.build import build
!   from setupext import Data_Files, install_Data_Files
! except ImportError:
!   print """
! Setup requires that python's distutils be
! installed.  You can get a copy of it from
! http://www.python.org/sigs/distutils-sig/
!     """
!   sys.exit()
! 
! 
! if 'sdist' in sys.argv:
! 
!   print "We are going to create the man pages for our tools."
!   os.system( """
! if [ ! -e man ]
! then
! mkdir man
! fi
! cd man
! ../scripts/gsscvs --generate-man-page
! """)
  
  
! dfiles = [
!   Data_Files(
!              base_dir = 'install_data',
!              copy_to = 'shared',
!              template = ['recursive-include images *.png',
!                          'recursive-include images *.xpm',
!                          'recursive-include images *.ico',
!                          'recursive-include images *.bmp',
!                          'prune images/CVS'],
!              preserve_path = 1),
!   Data_Files(
!              base_dir = 'install_data',
!              copy_to = '',
!              template = ['recursive-include etc *',
!                          'prune etc/CVS'],
!              preserve_path = 1),
!   Data_Files(
!              base_dir = 'install_data',
!              copy_to = '',
!              template = ['recursive-include translations *',
!                          'prune translations/CVS'],
!              preserve_path = 1),
!   Data_Files(
!              base_dir = 'install_data',
!              copy_to = 'man/man1',
!              template = ['recursive-include man *.1'],
!              preserve_path = 1),
!   Data_Files(
!              base_dir = 'install_data',
!              copy_to = 'doc/common',
!              template = ['recursive-include doc *',
!                          'prune doc/CVS'],
!              strip_dirs = 1, # This is a number, not true/false
!              preserve_path = 1)
!   ]
  
! class my_build_scripts(build_scripts):
!   def finalize_options(self):
  
!     build_scripts.finalize_options(self)
  
      if self.finalized:
        return
  
!     dict = self.distribution.get_option_dict("install")
!     options = []
  
!     # This statement stops the "search path" error messages
!     try:
!       sys.path.append(dict['install_lib'][1])
!     except KeyError:
!       if sys.platform == 'win32':
!         options.append('install_lib = r"%s"' % sys.prefix)
  
      for key in dict.keys():
        options.append('%s = "%s"' % (key, 
string.replace(str(dict[key][1]),'"','\\"')))
  
--- 53,172 ----
         python2.2 setup.py
  """ % string.split(sys.version)[0]
    print "-" * 70
!   sys.exit (1)
  
! # 
-----------------------------------------------------------------------------
! # Find out whether or not to use our setup.cfg
! # 
-----------------------------------------------------------------------------
! 
! have_prefix = 0
! 
! for arg in sys.argv:
!   if arg == "--prefix" or arg [:9] == "--prefix=" or \
!      arg == "--home"   or arg [:7] == "--home=":
!     have_prefix = 1
! 
! # Was setup.cfg specified on the command line?
! setupcfg = "setup.cfg.in"
! have_setupcfg = 0
! try:
!   index = sys.argv.index ('--setup-cfg')
!   setupcfg = sys.argv [index + 1]
!   sys.argv.pop (index)
!   sys.argv.pop (index)
!   have_setupcfg = 1
  
! except ValueError:
!   pass
  
! if (sys.platform != "win32" and not have_prefix) or have_setupcfg:
!   os.system ("cp %s setup.cfg" % setupcfg)
! else:
!   try:
!     os.remove ("setup.cfg")
!   except:
      pass
  
! # 
-----------------------------------------------------------------------------
! # Build files to be distributed and installed
! # 
-----------------------------------------------------------------------------
  
! def build_files ():
  
+   # First check if we have everything installed we need to build the
+   # distribution
  
!   # is gsscvs available (to build man pages)?
!   if not os.path.isfile ("scripts/gsscvs"):
!     print "Could not find file 'scripts/gsscvs'.  Please run 'setup-cvs.py'."
!     sys.exit (1)
  
!   # 
---------------------------------------------------------------------------
  
!   print "building man page"
!   if os.system ("mkdir -p man && cd man " \
!                  + " && ../scripts/gsscvs --generate-man-page") != 0:
!     sys.exit (1)
  
+ # 
-----------------------------------------------------------------------------
+ # Source distribution: Build files to be distributed
+ # 
-----------------------------------------------------------------------------
+ 
+ if "sdist" in sys.argv:
+   build_files ()
+ 
+ # 
-----------------------------------------------------------------------------
+ # User can supply a path to the config file
+ # 
-----------------------------------------------------------------------------
+ 
+ try:
+   index = sys.argv.index('--cfg-file')
+   site_config = os.path.join(os.path.abspath(sys.argv[index+1]))
+   sys.argv.pop(index)
+   sys.argv.pop(index)
+   config_line = "os.environ['GNUE_INSTALLED_SITE_CFG']='%s'\n" % site_config
+ 
+ except ValueError:
+   site_config = None
+   config_line = ""
+ 
+ # 
=============================================================================
+ # Before build: if done from CVS, build files to be installed
+ # 
=============================================================================
+ 
+ class gnue_build (build):
+ 
+   def finalize_options (self):
+     build.finalize_options (self)
      if self.finalized:
        return
  
!     if not os.path.isfile ("PKG-INFO"):         # downloaded from CVS?
!       build_files ()
  
! # 
=============================================================================
! # Before installation: check dependencies and create real scripts
! # 
=============================================================================
  
+ class gnue_install (install):
+ 
+   # 
---------------------------------------------------------------------------
+   # Check dependencies
+   # 
---------------------------------------------------------------------------
+ 
+   def _check_dependencies (self):
+ 
+     # TODO!
+     pass
+ 
+   # 
---------------------------------------------------------------------------
+   # Create gnue_sys.py and site_config.cfg
+   # 
---------------------------------------------------------------------------
+ 
+   def _write_config (self):
+     dict = self.distribution.get_option_dict ("install")
+ 
+     options = []
      for key in dict.keys():
        options.append('%s = "%s"' % (key, 
string.replace(str(dict[key][1]),'"','\\"')))
  
***************
*** 234,281 ****
  
      output.close()
  
      if sys.platform != 'win32':
        gnue_env = \
!                "#######\n" \
!                + "# The following variable were set when GNUe was 
installed\n" \
!                + "import os, sys\n" \
!                + "sys.path.append('%s')\n" % dict['install_lib'][1] \
!                + "INST_GNUE_CONNECTIONS='%s/etc/connections.conf'\n" % 
dict['prefix'][1] \
!                + "os.environ['INSTALL_LIB']='%s'\n" % dict['install_lib'][1] \
!                + "os.environ['INSTALL_PREFIX']='%s'\n" % dict['prefix'][1] \
!                + config_line \
!                + "#######\n"
      else:
        gnue_env = \
!                "#######\n" \
!              + "# The following variables were set when GNUe was installed\n" 
   \
!              + "# (Generated for a Win32 system)\n" \
!              + "import os, sys\n" \
!              + "if __name__ == '__main__': \n" \
!              + "  _BASE = 
os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),'..'))\n" \
!              + "  try:\n" \
!              + "    os.environ['PATH']= 
os.path.abspath(os.path.dirname(sys.argv[0])) + ';' + os.environ['PATH']\n" \
!              + "  except KeyError:\n" \
!              + "    os.environ['PATH']= 
os.path.abspath(os.path.dirname(sys.argv[0]))\n" \
!              + "else: \n" \
!              + "  _BASE = 
os.path.abspath(os.path.join(os.path.dirname(__file__),'..'))\n" \
!              + 
"INST_GNUE_CONNECTIONS=os.path.join(_BASE,'etc','connections.conf')\n" \
!              + "os.environ['INSTALL_PREFIX']=_BASE\n"                \
!              + "os.environ['INSTALL_LIB']=_BASE\n"                   \
!              + "os.putenv('PYTHONCASEOK','1')\n" \
!              + "if os.path.isdir(os.path.join(_BASE,'extras')):\n" \
!              + "  sys.path.append(os.path.join(_BASE,'extras'))\n" \
!              + config_line \
!              + "#######\n\n"
  
  
!     for script in self.scripts:
  
        fin = open(script+".in", "r")
        fout = open(script, "w")
  
-       print "Generating script %s from %s.in" % (script,script)
- 
        lines = fin.readlines()
  
        for i in range(0, len(lines)):
--- 249,317 ----
  
      output.close()
  
+     # Copy site_config.cfg to the given destination
+     if site_config is not None:
+       input = open('site_config.cfg')
+       file = input.readlines()
+       input.close()
+       print "Writing site configuration to %s" % site_config
+       output = open(site_config,'w')
+       output.writelines(file)
+       output.close()
+ 
+   # 
---------------------------------------------------------------------------
+   # Build the commands to place into the scripts
+   # 
---------------------------------------------------------------------------
+ 
+   def _build_gnue_env (self, path_line, config_line)
      if sys.platform != 'win32':
        gnue_env = \
!         "#######\n" \
!         + "# The following variable were set when GNUe was installed\n" \
!         + "INST_GNUE_CONNECTIONS='%s/etc/connections.conf'\n" % self.prefix \
!         + path_line \
!         + "import os\n" \
!         + "os.environ['INSTALL_LIB']='%s'\n" % self.install_lib \
!         + "os.environ['INSTALL_PREFIX']='%s'\n" % self.prefix \
!         + config_line \
!         + "#######\n"
      else:
        gnue_env = \
!         "#######\n" \
!         + "# The following variables were set when GNUe was installed\n"    \
!         + "# (Generated for a Win32 system)\n" \
!         + "import os, sys\n" \
!         + "if __name__ == '__main__': \n" \
!         + "  _BASE = 
os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),'..'))\n" \
!         + "  try:\n" \
!         + "    os.environ['PATH']= 
os.path.abspath(os.path.dirname(sys.argv[0])) + ';' + os.environ['PATH']\n" \
!         + "  except KeyError:\n" \
!         + "    os.environ['PATH']= 
os.path.abspath(os.path.dirname(sys.argv[0]))\n" \
!         + "else: \n" \
!         + "  _BASE = 
os.path.abspath(os.path.join(os.path.dirname(__file__),'..'))\n" \
!         + 
"INST_GNUE_CONNECTIONS=os.path.join(_BASE,'etc','connections.conf')\n" \
!         + "os.environ['INSTALL_PREFIX']=_BASE\n"                \
!         + "os.environ['INSTALL_LIB']=_BASE\n"                   \
!         + "os.putenv('PYTHONCASEOK','1')\n" \
!         + "if os.path.isdir(os.path.join(_BASE,'extras')):\n" \
!         + "  sys.path.append(os.path.join(_BASE,'extras'))\n" \
!         + config_line \
!         + "#######\n\n"
!     return gnue_env
! 
!   # 
---------------------------------------------------------------------------
!   # Generate the real scripts
!   # 
---------------------------------------------------------------------------
  
+   def _generate_scripts (self, path_line, config_line):
+     gnue_env = self._build_gnue_env (path_line, config_line)
  
!     for script in self.distribution.scripts:
!       print "building script %s" & script
  
        fin = open(script+".in", "r")
        fout = open(script, "w")
  
        lines = fin.readlines()
  
        for i in range(0, len(lines)):
***************
*** 287,336 ****
        fin.close()
        fout.close()
  
  
! # Site config stuff
! try:
!   index = sys.argv.index('--cfg-file')
!   site_config = os.path.join(os.path.abspath(sys.argv[index+1]))
!   sys.argv.pop(index)
!   sys.argv.pop(index)
!   if 'install' in sys.argv:
!     input = open('site_config.cfg')
!     file = input.readlines()
!     input.close()
!     print "Writing site configuration to %s" % site_config
!     output = open(site_config,'w')
!     output.writelines(file)
!     output.close()
!   config_line = "os.environ['GNUE_INSTALLED_SITE_CFG']='%s'\n" % site_config
  
! except ValueError:
!   config_line = ""
  
  
  
- #
  # You can run:
  #   $ GNUE_VERSION_SUFFIX=-pre1 ./setup.py sdist
  # and the packages will be created as GNUe-App-0.x.x-pre1.tar.gz
! #
  try:
    suffix = os.environ['GNUE_VERSION_SUFFIX']
  except KeyError:
    suffix = ""
  
! distutils.core.setup (name = "GNUe-Common",
         version = VERSION + suffix,
         description = "Base files of a GNU Enterprise Tools install",
         long_description = "",
!        author = "GNUe Project",
!        author_email = "address@hidden",
         url = "http://www.gnue.org";,
         # Override certain command classes with our own ones
!        cmdclass = {'install_data':install_Data_Files,
!                    'build_scripts':my_build_scripts},
!        scripts = ["scripts/gnue-schema"],
         data_files = dfiles,
         packages = ["gnue",
                     "gnue.common",
                     "gnue.common.apps",
--- 323,416 ----
        fin.close()
        fout.close()
  
+   # 
---------------------------------------------------------------------------
+   # Do it all - this is called by setu () if option install is given
+   # 
---------------------------------------------------------------------------
  
!   def finalize_options (self):
!     install.finalize_options (self)
!     if self.finalized:
!       return
  
!     # if install directory isn't in Python's search path, add it there
!     if self.install_lib in sys.path:
!       path_line = ""
!     else:
!       path_line = "import sys\nsys.path.append('%s')\n" % self.install_lib
  
+     self._check_dependencies ()
  
+     self._generate_scripts (path_line, config_line)
+ 
+ # 
-----------------------------------------------------------------------------
+ # GNUE_VERSION_SUFFIX handling
+ # 
-----------------------------------------------------------------------------
  
  # You can run:
  #   $ GNUE_VERSION_SUFFIX=-pre1 ./setup.py sdist
  # and the packages will be created as GNUe-App-0.x.x-pre1.tar.gz
! 
  try:
    suffix = os.environ['GNUE_VERSION_SUFFIX']
  except KeyError:
    suffix = ""
  
! # 
-----------------------------------------------------------------------------
! # Call the actual setup routine
! # 
-----------------------------------------------------------------------------
! 
! dfiles = [
!   Data_Files(
!              base_dir = 'install_data',
!              copy_to = 'shared',
!              template = ['recursive-include images *.png',
!                          'recursive-include images *.xpm',
!                          'recursive-include images *.ico',
!                          'recursive-include images *.bmp',
!                          'prune images/CVS'],
!              preserve_path = 1),
!   Data_Files(
!              base_dir = 'install_data',
!              copy_to = '',
!              template = ['recursive-include etc *',
!                          'prune etc/CVS'],
!              preserve_path = 1),
!   Data_Files(
!              base_dir = 'install_data',
!              copy_to = '',
!              template = ['recursive-include translations *',
!                          'prune translations/CVS'],
!              preserve_path = 1),
!   Data_Files(
!              base_dir = 'install_data',
!              copy_to = 'share/man/man1',
!              template = ['recursive-include man *.1'],
!              preserve_path = 1),
!   Data_Files(
!              base_dir = 'install_data',
!              copy_to = 'share/doc/gnue-common',
!              template = ['recursive-include doc *',
!                          'prune doc/CVS'],
!              strip_dirs = 1, # This is a number, not true/false
!              preserve_path = 1)
!   ]
! 
! setup (name = "GNUe-Common",
         version = VERSION + suffix,
         description = "Base files of a GNU Enterprise Tools install",
         long_description = "",
!        author = "GNUe Team",
!        author_email = "address@hidden",
         url = "http://www.gnue.org";,
+        license = "GPL",
+ 
         # Override certain command classes with our own ones
!        cmdclass = {"build": gnue_build,
!                    "install": gnue_install,
!                    "install_data": install_Data_Files},
! 
         data_files = dfiles,
+ 
         packages = ["gnue",
                     "gnue.common",
                     "gnue.common.apps",
***************
*** 462,498 ****
                     "gnue.common.schema",
                     "gnue.common.schema.scripter",
                     "gnue.common.schema.scripter.processors",
!                    "gnue.common.utils",
!                  ],
! 
!        package_dir = {"gnue": 'module/base',
!                       "gnue.common" : "src",
!                       "gnue.common.installer" : "installer"},
!        )
! 
! #distutils.core.setup (name = "GNUe-Common",
! #       version = VERSION,
! #       description = "Base files of a GNU Enterprise Tools install",
! #       long_description = "",
! #       author = "GNUe Project",
! #       author_email = "address@hidden",
! #       url = "http://www.gnue.org";,
! #       # Override certain command classes with our own ones
! #       py_modules = ['gnue_sys'],
! #       scripts = [],
! #       data_files = None,
! #       packages = []
! #       )
! 
! 
! if 'install' in sys.argv:
!   print """
!   Note:
!   Warnings about the files not being installed in pythons search path can be
!   ignored. You must now go to gnue install area (typically /usr/local/gnue )
!   and create an etc/gnue.conf file if you do not already have one.  A sample
!   is located in that directory that you can typically just rename.
! 
!   """
  
  
--- 542,552 ----
                     "gnue.common.schema",
                     "gnue.common.schema.scripter",
                     "gnue.common.schema.scripter.processors",
!                    "gnue.common.utils"],
  
+        package_dir = {"gnue": "module/base",
+                       "gnue.common": "src",
+                       "gnue.common.installer": "installer"},
  
+        scripts = ["scripts/gnue-schema"],
+        )




reply via email to

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