5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
13 The above copyright notice and this permission notice shall be included
14 in all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 There is a common set of simple tasks that many build configurations rely
28 on as they become more complex. Most build tools have special
29 purpose constructs for performing these tasks, but since &SConscript;
30 files are &Python; scripts, you can use more flexible built-in &Python;
31 services to perform these tasks. This appendix lists a number of these
32 tasks and how to implement them in &Python;.
36 <title>Wildcard globbing to create a list of filenames</title>
39 files = glob.glob(wildcard)
44 <title>Filename extension substitution</title>
47 filename = os.path.splitext(filename)[0]+extension
52 <title>Appending a path prefix to a list of filenames</title>
55 filenames = [os.path.join(prefix, x) for x in filenames]
58 <simpara>or in Python 1.5.2:</simpara>
64 new_filenames.append(os.path.join(prefix, x))
69 <title>Substituting a path prefix with another one</title>
71 if filename.find(old_prefix) == 0:
72 filename = filename.replace(old_prefix, new_prefix)
75 <simpara>or in Python 1.5.2:</simpara>
79 if string.find(filename, old_prefix) == 0:
80 filename = string.replace(filename, old_prefix, new_prefix)
85 <title>Filtering a filename list to exclude/retain only a specific set
89 filenames = [x for x in filenames if os.path.splitext(x)[1] in extensions]
92 <simpara>or in Python 1.5.2:</simpara>
98 if os.path.splitext(x)[1] in extensions:
99 new_filenames.append(x)
104 <title>The "backtick function": run a shell command and capture the
106 <programlisting>import os
107 output = os.popen(command).read()