/[gnue]/gnue-common/setup.py
ViewVC logotype

Diff of /gnue-common/setup.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.62 by siesel, Mon Sep 22 23:27:18 2003 UTC revision 1.63 by reinhard, Tue Sep 23 14:22:08 2003 UTC
# Line 1  Line 1 
1  #!/usr/bin/env python  #!/usr/bin/env python
2  #  #
3    # GNU Enterprise Common Library - Installation Procedure
4    #
5  # This file is part of GNU Enterprise.  # This file is part of GNU Enterprise.
6  #  #
7  # GNU Enterprise is free software; you can redistribute it  # GNU Enterprise is free software; you can redistribute it
# Line 24  import sys Line 26  import sys
26  import string  import string
27  import os  import os
28    
29  from src import VERSION  from distutils.core import setup
30    from distutils.command.build import build
31    from distutils.command.install import install
32    from setupext import Data_Files, install_Data_Files
33    
34    from src import PACKAGE, VERSION
35    
36    # -----------------------------------------------------------------------------
37    # Check Python version
38    # -----------------------------------------------------------------------------
39    
 # First of all, make sure this is a current enough Python release.  
40  try:  try:
41    if sys.hexversion < 0x02000000:    if sys.hexversion < 0x02000000:
42      raise AttributeError      raise AttributeError
# Line 43  except AttributeError: Line 53  except AttributeError:
53         python2.2 setup.py         python2.2 setup.py
54  """ % string.split(sys.version)[0]  """ % string.split(sys.version)[0]
55    print "-" * 70    print "-" * 70
56    sys.exit()    sys.exit (1)
57    
58  #  # -----------------------------------------------------------------------------
59  # hack to deal w/ fact distutils won't  # Find out whether or not to use our setup.cfg
60  # allow us to set absolute path prefix  # -----------------------------------------------------------------------------
61  # on windows  
62  #  have_prefix = 0
63    
64    for arg in sys.argv:
65      if arg == "--prefix" or arg [:9] == "--prefix=" or \
66         arg == "--home"   or arg [:7] == "--home=":
67        have_prefix = 1
68    
69    # Was setup.cfg specified on the command line?
70    setupcfg = "setup.cfg.in"
71    have_setupcfg = 0
72    try:
73      index = sys.argv.index ('--setup-cfg')
74      setupcfg = sys.argv [index + 1]
75      sys.argv.pop (index)
76      sys.argv.pop (index)
77      have_setupcfg = 1
78    
79  if not 'sdist' in sys.argv:  except ValueError:
80    setupcfg = "setup.cfg.in"    pass
   # 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)  
81    
82    except ValueError:  if (sys.platform != "win32" and not have_prefix) or have_setupcfg:
83      os.system ("cp %s setup.cfg" % setupcfg)
84    else:
85      try:
86        os.remove ("setup.cfg")
87      except:
88      pass      pass
89    
90    if sys.platform != 'win32' and '--prefix' not in sys.argv and '--root' not in sys.argv:  # -----------------------------------------------------------------------------
91      os.system ("""cp %s setup.cfg""" % setupcfg)  # Build files to be distributed and installed
92    else:  # -----------------------------------------------------------------------------
     try:  
       os.remove('setup.cfg')  
     except:  
       pass  
93    
94  try:  def build_files ():
   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  
 """)  
95    
96      # First check if we have everything installed we need to build the
97      # distribution
98    
99  dfiles = [    # is gsscvs available (to build man pages)?
100    Data_Files(    if not os.path.isfile ("scripts/gsscvs"):
101               base_dir = 'install_data',      print "Could not find file 'scripts/gsscvs'.  Please run 'setup-cvs.py'."
102               copy_to = 'shared',      sys.exit (1)
              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)  
   ]  
103    
104  class my_build_scripts(build_scripts):    # ---------------------------------------------------------------------------
   def finalize_options(self):  
105    
106      build_scripts.finalize_options(self)    print "building man page"
107      if os.system ("mkdir -p man && cd man " \
108                     + " && ../scripts/gsscvs --generate-man-page") != 0:
109        sys.exit (1)
110    
111    # -----------------------------------------------------------------------------
112    # Source distribution: Build files to be distributed
113    # -----------------------------------------------------------------------------
114    
115    if "sdist" in sys.argv:
116      build_files ()
117    
118    # -----------------------------------------------------------------------------
119    # User can supply a path to the config file
120    # -----------------------------------------------------------------------------
121    
122    try:
123      index = sys.argv.index('--cfg-file')
124      site_config = os.path.join(os.path.abspath(sys.argv[index+1]))
125      sys.argv.pop(index)
126      sys.argv.pop(index)
127      config_line = "os.environ['GNUE_INSTALLED_SITE_CFG']='%s'\n" % site_config
128    
129    except ValueError:
130      site_config = None
131      config_line = ""
132    
133    # =============================================================================
134    # Before build: if done from CVS, build files to be installed
135    # =============================================================================
136    
137    class gnue_build (build):
138    
139      def finalize_options (self):
140        build.finalize_options (self)
141      if self.finalized:      if self.finalized:
142        return        return
143    
144      dict = self.distribution.get_option_dict("install")      if not os.path.isfile ("PKG-INFO"):         # downloaded from CVS?
145      options = []        build_files ()
146    
147      # This statement stops the "search path" error messages  # =============================================================================
148      try:  # Before installation: check dependencies and create real scripts
149        sys.path.append(dict['install_lib'][1])  # =============================================================================
     except KeyError:  
       if sys.platform == 'win32':  
         options.append('install_lib = r"%s"' % sys.prefix)  
150    
151    class gnue_install (install):
152    
153      # ---------------------------------------------------------------------------
154      # Check dependencies
155      # ---------------------------------------------------------------------------
156    
157      def _check_dependencies (self):
158    
159        # TODO!
160        pass
161    
162      # ---------------------------------------------------------------------------
163      # Create gnue_sys.py and site_config.cfg
164      # ---------------------------------------------------------------------------
165    
166      def _write_config (self):
167        dict = self.distribution.get_option_dict ("install")
168    
169        options = []
170      for key in dict.keys():      for key in dict.keys():
171        options.append('%s = "%s"' % (key, string.replace(str(dict[key][1]),'"','\\"')))        options.append('%s = "%s"' % (key, string.replace(str(dict[key][1]),'"','\\"')))
172    
# Line 234  common_appbase = install_prefix Line 249  common_appbase = install_prefix
249    
250      output.close()      output.close()
251    
252        # Copy site_config.cfg to the given destination
253        if site_config is not None:
254          input = open('site_config.cfg')
255          file = input.readlines()
256          input.close()
257          print "Writing site configuration to %s" % site_config
258          output = open(site_config,'w')
259          output.writelines(file)
260          output.close()
261    
262      # ---------------------------------------------------------------------------
263      # Build the commands to place into the scripts
264      # ---------------------------------------------------------------------------
265    
266      def _build_gnue_env (self, path_line, config_line)
267      if sys.platform != 'win32':      if sys.platform != 'win32':
268        gnue_env = \        gnue_env = \
269                 "#######\n" \          "#######\n" \
270                 + "# The following variable were set when GNUe was installed\n" \          + "# The following variable were set when GNUe was installed\n" \
271                 + "import os, sys\n" \          + "INST_GNUE_CONNECTIONS='%s/etc/connections.conf'\n" % self.prefix \
272                 + "sys.path.append('%s')\n" % dict['install_lib'][1] \          + path_line \
273                 + "INST_GNUE_CONNECTIONS='%s/etc/connections.conf'\n" % dict['prefix'][1] \          + "import os\n" \
274                 + "os.environ['INSTALL_LIB']='%s'\n" % dict['install_lib'][1] \          + "os.environ['INSTALL_LIB']='%s'\n" % self.install_lib \
275                 + "os.environ['INSTALL_PREFIX']='%s'\n" % dict['prefix'][1] \          + "os.environ['INSTALL_PREFIX']='%s'\n" % self.prefix \
276                 + config_line \          + config_line \
277                 + "#######\n"          + "#######\n"
278      else:      else:
279        gnue_env = \        gnue_env = \
280                 "#######\n" \          "#######\n" \
281               + "# The following variables were set when GNUe was installed\n"    \          + "# The following variables were set when GNUe was installed\n"    \
282               + "# (Generated for a Win32 system)\n" \          + "# (Generated for a Win32 system)\n" \
283               + "import os, sys\n" \          + "import os, sys\n" \
284               + "if __name__ == '__main__': \n" \          + "if __name__ == '__main__': \n" \
285               + "  _BASE = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),'..'))\n" \          + "  _BASE = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]),'..'))\n" \
286               + "  try:\n" \          + "  try:\n" \
287               + "    os.environ['PATH']= os.path.abspath(os.path.dirname(sys.argv[0])) + ';' + os.environ['PATH']\n" \          + "    os.environ['PATH']= os.path.abspath(os.path.dirname(sys.argv[0])) + ';' + os.environ['PATH']\n" \
288               + "  except KeyError:\n" \          + "  except KeyError:\n" \
289               + "    os.environ['PATH']= os.path.abspath(os.path.dirname(sys.argv[0]))\n" \          + "    os.environ['PATH']= os.path.abspath(os.path.dirname(sys.argv[0]))\n" \
290               + "else: \n" \          + "else: \n" \
291               + "  _BASE = os.path.abspath(os.path.join(os.path.dirname(__file__),'..'))\n" \          + "  _BASE = os.path.abspath(os.path.join(os.path.dirname(__file__),'..'))\n" \
292               + "INST_GNUE_CONNECTIONS=os.path.join(_BASE,'etc','connections.conf')\n" \          + "INST_GNUE_CONNECTIONS=os.path.join(_BASE,'etc','connections.conf')\n" \
293               + "os.environ['INSTALL_PREFIX']=_BASE\n"                \          + "os.environ['INSTALL_PREFIX']=_BASE\n"                \
294               + "os.environ['INSTALL_LIB']=_BASE\n"                   \          + "os.environ['INSTALL_LIB']=_BASE\n"                   \
295               + "os.putenv('PYTHONCASEOK','1')\n" \          + "os.putenv('PYTHONCASEOK','1')\n" \
296               + "if os.path.isdir(os.path.join(_BASE,'extras')):\n" \          + "if os.path.isdir(os.path.join(_BASE,'extras')):\n" \
297               + "  sys.path.append(os.path.join(_BASE,'extras'))\n" \          + "  sys.path.append(os.path.join(_BASE,'extras'))\n" \
298               + config_line \          + config_line \
299               + "#######\n\n"          + "#######\n\n"
300        return gnue_env
301    
302      # ---------------------------------------------------------------------------
303      # Generate the real scripts
304      # ---------------------------------------------------------------------------
305    
306      def _generate_scripts (self, path_line, config_line):
307        gnue_env = self._build_gnue_env (path_line, config_line)
308    
309      for script in self.scripts:      for script in self.distribution.scripts:
310          print "building script %s" & script
311    
312        fin = open(script+".in", "r")        fin = open(script+".in", "r")
313        fout = open(script, "w")        fout = open(script, "w")
314    
       print "Generating script %s from %s.in" % (script,script)  
   
315        lines = fin.readlines()        lines = fin.readlines()
316    
317        for i in range(0, len(lines)):        for i in range(0, len(lines)):
# Line 287  common_appbase = install_prefix Line 323  common_appbase = install_prefix
323        fin.close()        fin.close()
324        fout.close()        fout.close()
325    
326      # ---------------------------------------------------------------------------
327      # Do it all - this is called by setu () if option install is given
328      # ---------------------------------------------------------------------------
329    
330  # Site config stuff    def finalize_options (self):
331  try:      install.finalize_options (self)
332    index = sys.argv.index('--cfg-file')      if self.finalized:
333    site_config = os.path.join(os.path.abspath(sys.argv[index+1]))        return
   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  
334    
335  except ValueError:      # if install directory isn't in Python's search path, add it there
336    config_line = ""      if self.install_lib in sys.path:
337          path_line = ""
338        else:
339          path_line = "import sys\nsys.path.append('%s')\n" % self.install_lib
340    
341        self._check_dependencies ()
342    
343        self._generate_scripts (path_line, config_line)
344    
345    # -----------------------------------------------------------------------------
346    # GNUE_VERSION_SUFFIX handling
347    # -----------------------------------------------------------------------------
348    
 #  
349  # You can run:  # You can run:
350  #   $ GNUE_VERSION_SUFFIX=-pre1 ./setup.py sdist  #   $ GNUE_VERSION_SUFFIX=-pre1 ./setup.py sdist
351  # and the packages will be created as GNUe-App-0.x.x-pre1.tar.gz  # and the packages will be created as GNUe-App-0.x.x-pre1.tar.gz
352  #  
353  try:  try:
354    suffix = os.environ['GNUE_VERSION_SUFFIX']    suffix = os.environ['GNUE_VERSION_SUFFIX']
355  except KeyError:  except KeyError:
356    suffix = ""    suffix = ""
357    
358  distutils.core.setup (name = "GNUe-Common",  # -----------------------------------------------------------------------------
359    # Call the actual setup routine
360    # -----------------------------------------------------------------------------
361    
362    dfiles = [
363      Data_Files(
364                 base_dir = 'install_data',
365                 copy_to = 'shared',
366                 template = ['recursive-include images *.png',
367                             'recursive-include images *.xpm',
368                             'recursive-include images *.ico',
369                             'recursive-include images *.bmp',
370                             'prune images/CVS'],
371                 preserve_path = 1),
372      Data_Files(
373                 base_dir = 'install_data',
374                 copy_to = '',
375                 template = ['recursive-include etc *',
376                             'prune etc/CVS'],
377                 preserve_path = 1),
378      Data_Files(
379                 base_dir = 'install_data',
380                 copy_to = '',
381                 template = ['recursive-include translations *',
382                             'prune translations/CVS'],
383                 preserve_path = 1),
384      Data_Files(
385                 base_dir = 'install_data',
386                 copy_to = 'share/man/man1',
387                 template = ['recursive-include man *.1'],
388                 preserve_path = 1),
389      Data_Files(
390                 base_dir = 'install_data',
391                 copy_to = 'share/doc/gnue-common',
392                 template = ['recursive-include doc *',
393                             'prune doc/CVS'],
394                 strip_dirs = 1, # This is a number, not true/false
395                 preserve_path = 1)
396      ]
397    
398    setup (name = "GNUe-Common",
399         version = VERSION + suffix,         version = VERSION + suffix,
400         description = "Base files of a GNU Enterprise Tools install",         description = "Base files of a GNU Enterprise Tools install",
401         long_description = "",         long_description = "",
402         author = "GNUe Project",         author = "GNUe Team",
403         author_email = "info@gnue.org",         author_email = "gnue-dev@gnue.org",
404         url = "http://www.gnue.org",         url = "http://www.gnue.org",
405           license = "GPL",
406    
407         # Override certain command classes with our own ones         # Override certain command classes with our own ones
408         cmdclass = {'install_data':install_Data_Files,         cmdclass = {"build": gnue_build,
409                     'build_scripts':my_build_scripts},                     "install": gnue_install,
410         scripts = ["scripts/gnue-schema"],                     "install_data": install_Data_Files},
411    
412         data_files = dfiles,         data_files = dfiles,
413    
414         packages = ["gnue",         packages = ["gnue",
415                     "gnue.common",                     "gnue.common",
416                     "gnue.common.apps",                     "gnue.common.apps",
# Line 462  distutils.core.setup (name = "GNUe-Commo Line 542  distutils.core.setup (name = "GNUe-Commo
542                     "gnue.common.schema",                     "gnue.common.schema",
543                     "gnue.common.schema.scripter",                     "gnue.common.schema.scripter",
544                     "gnue.common.schema.scripter.processors",                     "gnue.common.schema.scripter.processors",
545                     "gnue.common.utils",                     "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 = "info@gnue.org",  
 #       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.  
   
   """  
546    
547           package_dir = {"gnue": "module/base",
548                          "gnue.common": "src",
549                          "gnue.common.installer": "installer"},
550    
551           scripts = ["scripts/gnue-schema"],
552           )

Legend:
Removed from v.1.62  
changed lines
  Added in v.1.63

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26