home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pykjb22.zip / install.cmd < prev    next >
OS/2 REXX Batch file  |  2001-12-25  |  4KB  |  125 lines

  1. extproc python -x
  2.  
  3. # Copyright 2001 by Andrew I MacIntyre.
  4. # All Rights Reserved.
  5.  
  6. # Permission to use, copy, modify, and distribute this software and its
  7. # documentation for any purpose and without fee is hereby granted,
  8. # provided that the above copyright notice appears in all copies and that
  9. # both that copyright notice and this permission notice appear in
  10. # supporting documentation.
  11.  
  12. # THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  13. # INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
  14. # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  15. # CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  16. # USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  17. # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  18. # PERFORMANCE OF THIS SOFTWARE.
  19.  
  20. # this script is intended only for use on OS/2 systems (hence the 
  21. # .cmd extension, and the above line).  Note however that there are 
  22. # limitations - the script must be started from the directory it lives in
  23. # (the "extproc" command appears not to pass directory information to 
  24. #  Python when attempting to start the script using a path name :-( )
  25.  
  26. # This is an installation script for prebuilt binary Python extensions/packages
  27. #
  28. # Using the Python interpreter to manage the installation achieves
  29. # several things:
  30. # - makes sure we have a working Python
  31. # - simplifies figuring out where to put things, as the Python
  32. #   interpreter already knows where many things should be
  33. #
  34. # Information not known to the Python interpreter are extracted from a
  35. # file called 'install.cnf' in the same directory as this script
  36. #
  37. # This script expects to find UNZIP.EXE on the path, and assumes what 
  38. # it is about to install is to be unpacked in $PYTHONHOME/Lib/site-packages.
  39.  
  40. import sys, os, string
  41.  
  42. # read the configuration settings
  43. config = { 'pkg_name': None,
  44.        'pkg_version': None,
  45.        'pkg_description': None,
  46.        'test_file_exists': [],
  47.        'test_file_not_exists': [] }
  48. try:
  49.     cfgfile = open('install.cnf', 'r')
  50. except:
  51.     print 'Could not open the configuration file "install.dat". Installation aborted.'
  52.     sys.exit(1)
  53. while 1:
  54.     line = cfgfile.readline()
  55.     if not line:
  56.         break
  57.  
  58.     # skip comments and blank lines
  59.     if line[:1] in '#;':
  60.         continue
  61.     if len(string.strip(line)) == 0:
  62.         continue
  63.  
  64.     # record the option settings
  65.     opt, value = string.split(line, '=', 1)
  66.     opt = string.lower(string.strip(opt))
  67.     value = string.strip(value)
  68.     if config.has_key(opt):
  69.         if opt[:5] == 'test_':
  70.             config[opt].append(value)
  71.         else:
  72.             config[opt] = value
  73. cfgfile.close()
  74.  
  75. # check that we have the package we're going to try and install...
  76. if not (config['pkg_name'] and config['pkg_version']):
  77.     print 'Package information incomplete. Installation aborted.'
  78.     sys.exit(1)
  79. pkg_archive = '%s-%s.zip' % (config['pkg_name'], config['pkg_version'])
  80. try:
  81.     test = open(pkg_archive, 'r')
  82. except IOError:
  83.     print 'Could not open package archive "%s". Installation aborted.' % pkg_archive
  84.     sys.exit(1)
  85. test.close()            # need to do this to avoid sharing violations
  86.  
  87. # do the specified checks
  88. for file in config['test_file_exists']:
  89.     f = file[:]
  90.     for subst in ('$PYTHONHOME', '${PYTHONHOME}', '%PYTHONHOME%'):
  91.         f = string.replace(f, subst, sys.prefix)
  92.     cnt_exist = 0
  93.     try:
  94.         test = open(os.path.normpath(f), 'r')
  95.     except IOError:
  96.         cnt_exist = cnt_exist + 1
  97.         print 'required file "%s" cannot be found' % file
  98.     else:
  99.         test.close()
  100. for file in config['test_file_not_exists']:
  101.     f = file[:]
  102.     for subst in ('$PYTHONHOME', '${PYTHONHOME}', '%PYTHONHOME%'):
  103.         f = string.replace(f, subst, sys.prefix)
  104.     cnt_nexist = 0
  105.     try:    
  106.         test = open(os.path.normpath(f), 'r')
  107.     except IOError:
  108.         pass            # desired result
  109.     else:
  110.         cnt_nexist = cnt_nexist + 1
  111.         print 'file "%s" found when not wanted' % file
  112.         test.close()
  113.  
  114. if cnt_exist > 0 or cnt_nexist > 0:
  115.     print 'File presence/absence checks failed. Installation aborted.'
  116.     sys.exit(1)
  117.  
  118. # OK, we got past that, so now lets see if we can actually do the install
  119. pkg = os.path.abspath(pkg_archive)
  120. os.chdir(sys.prefix)
  121. status = os.system('unzip %s' % pkg)
  122. if status > 0:
  123.     print 'UnZip failed with status code %d' % status
  124.     sys.exit(1)
  125.