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