diff -BurN --minimal --exclude=*.pyc distutils.orig/distutils/command/__init__.py distutils.patched/distutils/command/__init__.py --- distutils.orig/distutils/command/__init__.py Sat May 13 03:48:15 2000 +++ distutils.patched/distutils/command/__init__.py Wed May 24 10:11:54 2000 @@ -9,6 +9,7 @@ 'build_py', 'build_ext', 'build_clib', + 'build_scripts', 'install', 'install_lib', 'install_scripts', diff -BurN --minimal --exclude=*.pyc distutils.orig/distutils/command/build.py distutils.patched/distutils/command/build.py --- distutils.orig/distutils/command/build.py Fri May 12 02:33:14 2000 +++ distutils.patched/distutils/command/build.py Wed May 24 10:11:09 2000 @@ -24,6 +24,8 @@ ('build-lib=', None, "build directory for all distribution (defaults to either " + "build-purelib or build-platlib"), + ('build-scripts=', None, + "build directory for scripts"), ('build-temp=', 't', "temporary build directory"), ('compiler=', 'c', @@ -42,6 +44,7 @@ self.build_platlib = None self.build_lib = None self.build_temp = None + self.build_scripts = None self.compiler = None self.debug = None self.force = 0 @@ -76,6 +79,8 @@ if self.build_temp is None: self.build_temp = os.path.join (self.build_base, 'temp.' + self.plat) + if self.build_scripts is None: + self.build_scripts = os.path.join (self.build_base, 'scripts') # finalize_options () @@ -99,5 +104,8 @@ # into the build tree if self.distribution.has_ext_modules(): self.run_peer ('build_ext') + + if self.distribution.scripts: + self.run_peer ('build_scripts') # end class Build diff -BurN --minimal --exclude=*.pyc distutils.orig/distutils/command/build_scripts.py distutils.patched/distutils/command/build_scripts.py --- distutils.orig/distutils/command/build_scripts.py Thu Jan 1 01:00:00 1970 +++ distutils.patched/distutils/command/build_scripts.py Wed May 24 10:10:06 2000 @@ -0,0 +1,71 @@ +"""distutils.command.build_scripts + +Implements the Distutils 'build_scripts' command.""" + +# created 2000/05/23, Bastian Kleineidam + +__revision__ = "$Id$" + +import sys,os,re +from distutils.core import Command + +# check if Python is called on the first line with this expression +first_line_re = re.compile(r"^#!.+python(\s-\w+)*") + +class build_scripts (Command): + + description = "\"build\" scripts" + + user_options = [ + ('build-dir=', 'd', "directory to \"build\" (copy) to"), + ('force', 'f', "forcibly build everything (ignore file timestamps"), + ] + + + def initialize_options (self): + self.build_dir = None + self.scripts = None + self.force = None + self.outfiles = None + + def finalize_options (self): + self.set_undefined_options ('build', + ('build_scripts', 'build_dir'), + ('force', 'force')) + self.scripts = self.distribution.scripts + + + def run (self): + if not self.scripts: + return + self._copy_files() + self._adjust_files() + + def _copy_files(self): + """Copy all the scripts to the build dir""" + self.outfiles = [] + self.mkpath(self.build_dir) + for f in self.scripts: + print self.build_dir + if self.copy_file(f, self.build_dir): + self.outfiles.append(os.path.join(self.build_dir, f)) + + def _adjust_files(self): + """If the first line begins with #! and ends with python + replace it with the current python interpreter""" + for f in self.outfiles: + if not self.dry_run: + data = open(f, "r").readlines() + if not data: + self.warn("%s is an empty file!" % f) + continue + mo = first_line_re.match(data[0]) + if mo: + self.announce("Adjusting first line of file %s" % f) + data[0] = "#!"+sys.executable + # add optional command line options + if mo.group(1): + data[0] = data[0] + mo.group(1) + else: + data[0] = data[0] + "\n" + open(f, "w").writelines(data) diff -BurN --minimal --exclude=*.pyc distutils.orig/distutils/command/install_data.py distutils.patched/distutils/command/install_data.py --- distutils.orig/distutils/command/install_data.py Sat May 13 05:09:50 2000 +++ distutils.patched/distutils/command/install_data.py Wed May 24 10:41:51 2000 @@ -7,17 +7,52 @@ __revision__ = "$Id: install_data.py,v 1.5 2000/05/13 03:09:50 greg Exp $" -from distutils.cmd import install_misc +import os +from types import StringType +from distutils.core import Command -class install_data (install_misc): +class install_data (Command): description = "install data files" + user_options = [ + ('install-dir=', 'd', + "directory to install the files to"), + ('root=', None, + "install everything relative to this alternate root directory"), + ] + + def initialize_options (self): + self.install_dir = None + self.outfiles = None + self.root = None + self.data_files = self.distribution.data_files + def finalize_options (self): - self._install_dir_from('install_data') + self.set_undefined_options('install', + ('install_data', 'install_dir'), + ('root', 'root'), + ) def run (self): - self._copy_files(self.distribution.data_files) + self.mkpath(self.install_dir) + for f in self.data_files: + if type(f) == StringType: + # its a simple file, so copy it + self.copy_file(f, self.install_dir) + else: + # its a tuple with path to install to and a list of files + dir = f[0] + if not os.path.isabs(dir): + dir = os.path.join(self.install_dir, dir) + elif self.root: + dir = os.path.join(self.root, dir[1:]) + self.mkpath(dir) + for data in f[1]: + self.copy_file(data, dir) def get_inputs (self): - return self.distribution.data_files or [] + return self.data_files or [] + + def get_outputs (self): + return self.outfiles diff -BurN --minimal --exclude=*.pyc distutils.orig/distutils/command/install_scripts.py distutils.patched/distutils/command/install_scripts.py --- distutils.orig/distutils/command/install_scripts.py Sat May 13 05:07:53 2000 +++ distutils.patched/distutils/command/install_scripts.py Wed May 24 10:10:48 2000 @@ -8,23 +8,39 @@ __revision__ = "$Id: install_scripts.py,v 1.4 2000/05/13 03:07:53 greg Exp $" import os -from distutils.cmd import install_misc +from distutils.core import Command from stat import ST_MODE -class install_scripts(install_misc): +class install_scripts(Command): description = "install scripts" + user_options = [ + ('install-dir=', 'd', "directory to install to"), + ('build-dir=','b', "build directory (where to install from)"), + ('skip-build', None, "skip the build steps"), + ] + + def initialize_options (self): + self.install_dir = None + self.build_dir = None + self.skip_build = None + def finalize_options (self): - self._install_dir_from('install_scripts') + self.set_undefined_options('build', ('build_scripts', 'build_dir')) + self.set_undefined_options ('install', + ('install_scripts', 'install_dir'), + ('skip_build', 'skip_build'), + ) def run (self): - self._copy_files(self.distribution.scripts) + if not self.skip_build: + self.run_peer('build_scripts') + self.outfiles = self.copy_tree (self.build_dir, self.install_dir) if os.name == 'posix': # Set the executable bits (owner, group, and world) on # all the scripts we just installed. - files = self.get_outputs() - for file in files: + for file in self.get_outputs(): if self.dry_run: self.announce("changing mode of %s" % file) else: @@ -34,5 +50,8 @@ def get_inputs (self): return self.distribution.scripts or [] + + def get_outputs(self): + return self.outfiles or [] # class install_scripts