]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/distutils/command/build_scripts.py
1 """distutils.command.build_scripts
3 Implements the Distutils 'build_scripts' command."""
5 # This module should be kept compatible with Python 1.5.2.
10 from stat
import ST_MODE
11 from distutils
import sysconfig
12 from distutils
.core
import Command
13 from distutils
.dep_util
import newer
14 from distutils
.util
import convert_path
15 from distutils
import log
17 # check if Python is called on the first line with this expression
18 first_line_re
= re
.compile('^#!.*python[0-9.]*([ \t].*)?$')
20 class build_scripts (Command
):
22 description
= "\"build\" scripts (copy and fixup #! line)"
25 ('build-dir=', 'd', "directory to \"build\" (copy) to"),
26 ('force', 'f', "forcibly build everything (ignore file timestamps"),
29 boolean_options
= ['force']
32 def initialize_options (self
):
38 def finalize_options (self
):
39 self
.set_undefined_options('build',
40 ('build_scripts', 'build_dir'),
42 self
.scripts
= self
.distribution
.scripts
51 def copy_scripts (self
):
52 """Copy each script listed in 'self.scripts'; if it's marked as a
53 Python script in the Unix way (first line matches 'first_line_re',
54 ie. starts with "\#!" and contains "python"), then adjust the first
55 line to refer to the current Python interpreter as we copy.
57 self
.mkpath(self
.build_dir
)
59 for script
in self
.scripts
:
61 script
= convert_path(script
)
62 outfile
= os
.path
.join(self
.build_dir
, os
.path
.basename(script
))
63 outfiles
.append(outfile
)
65 if not self
.force
and not newer(script
, outfile
):
66 log
.debug("not copying %s (up-to-date)", script
)
69 # Always open the file, but ignore failures in dry-run mode --
70 # that way, we'll get accurate feedback if we can read the
79 first_line
= f
.readline()
81 self
.warn("%s is an empty file (skipping)" % script
)
84 match
= first_line_re
.match(first_line
)
87 post_interp
= match
.group(1) or ''
90 log
.info("copying and adjusting %s -> %s", script
,
93 outf
= open(outfile
, "w")
94 if not sysconfig
.python_build
:
95 outf
.write("#!%s%s\n" %
96 (os
.path
.normpath(sys
.executable
),
99 outf
.write("#!%s%s\n" %
101 sysconfig
.get_config_var("BINDIR"),
102 "python" + sysconfig
.get_config_var("EXE")),
104 outf
.writelines(f
.readlines())
110 self
.copy_file(script
, outfile
)
112 if os
.name
== 'posix':
113 for file in outfiles
:
115 log
.info("changing mode of %s", file)
117 oldmode
= os
.stat(file)[ST_MODE
] & 07777
118 newmode
= (oldmode |
0555) & 07777
119 if newmode
!= oldmode
:
120 log
.info("changing mode of %s from %o to %o",
121 file, oldmode
, newmode
)
122 os
.chmod(file, newmode
)
126 # class build_scripts