1"""distutils.command.install_scripts 2 3Implements the Distutils 'install_scripts' command, for installing 4Python scripts.""" 5 6# contributed by Bastian Kleineidam 7 8import os 9from distutils.core import Command 10from distutils import log 11from stat import ST_MODE 12 13 14class install_scripts(Command): 15 16 description = "install scripts (Python or otherwise)" 17 18 user_options = [ 19 ('install-dir=', 'd', "directory to install scripts to"), 20 ('build-dir=','b', "build directory (where to install from)"), 21 ('force', 'f', "force installation (overwrite existing files)"), 22 ('skip-build', None, "skip the build steps"), 23 ] 24 25 boolean_options = ['force', 'skip-build'] 26 27 def initialize_options(self): 28 self.install_dir = None 29 self.force = 0 30 self.build_dir = None 31 self.skip_build = None 32 33 def finalize_options(self): 34 self.set_undefined_options('build', ('build_scripts', 'build_dir')) 35 self.set_undefined_options('install', 36 ('install_scripts', 'install_dir'), 37 ('force', 'force'), 38 ('skip_build', 'skip_build'), 39 ) 40 41 def run(self): 42 if not self.skip_build: 43 self.run_command('build_scripts') 44 self.outfiles = self.copy_tree(self.build_dir, self.install_dir) 45 if os.name == 'posix': 46 # Set the executable bits (owner, group, and world) on 47 # all the scripts we just installed. 48 for file in self.get_outputs(): 49 if self.dry_run: 50 log.info("changing mode of %s", file) 51 else: 52 mode = ((os.stat(file)[ST_MODE]) | 0o555) & 0o7777 53 log.info("changing mode of %s to %o", file, mode) 54 os.chmod(file, mode) 55 56 def get_inputs(self): 57 return self.distribution.scripts or [] 58 59 def get_outputs(self): 60 return self.outfiles or [] 61