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