From: stevenknight Date: Tue, 17 Feb 2004 04:58:13 +0000 (+0000) Subject: Add a common tasks appendix to the user's guide. (Anthony Roach) X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4abf70569ccb856fb4f06da66443edf132fbe49b;p=scons.git Add a common tasks appendix to the user's guide. (Anthony Roach) git-svn-id: http://scons.tigris.org/svn/scons/trunk@904 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/doc/user/MANIFEST b/doc/user/MANIFEST index c9af4a4a..9e3f7bf9 100644 --- a/doc/user/MANIFEST +++ b/doc/user/MANIFEST @@ -28,5 +28,6 @@ scanners.sgml separate.sgml simple.sgml sourcecode.sgml +tasks.sgml troubleshoot.sgml variants.sgml diff --git a/doc/user/main.in b/doc/user/main.in index 1a017d33..0fcf95cc 100644 --- a/doc/user/main.in +++ b/doc/user/main.in @@ -60,6 +60,7 @@ + @@ -242,6 +243,11 @@ Tools() --> + + Handling Common Tasks + &tasks; + + + + Handling Common Tasks + &tasks; + + + + +There is a common set of simple tasks that many build configurations rely +on as they become more complex. Most build tools have special +purpose constructs for performing these tasks, but since &SConscript; +files are &Python; scripts, you can use more flexible built-in &Python; +services to perform these tasks. This appendix lists a number of these +tasks and how to implement them in &Python;. + + + +Wildcard globbing to create a list of filenames + +import glob +files = glob.glob(wildcard) + + + + +Filename extension substitution + +import os.path +filename = os.path.splitext(filename)[0]+extension + + + + +Appending a path prefix to a list of filenames + +import os.path +filenames = [os.path.join(prefix, x) for x in filenames] + + +or in Python 1.5.2: + + +import os.path +new_filenames = [] +for x in filenames: + new_filenames.append(os.path.join(prefix, x)) + + + + +Substituting a path prefix with another one + +if filename.find(old_prefix) == 0: + filename = filename.replace(old_prefix, new_prefix) + + +or in Python 1.5.2: + + +import string +if string.find(filename, old_prefix) == 0: + filename = string.replace(filename, old_prefix, new_prefix) + + + + +Filtering a filename list to exclude/retain only a specific set +of extensions + +import os.path +filenames = [x for x in filenames if os.path.splitext(x)[1] in extensions] + + +or in Python 1.5.2: + + +import os.path +new_filenames = [] +for x in filenames: + if os.path.splitext(x)[1] in extensions: + new_filenames.append(x) + + + + +The "backtick function": run a shell command and capture the +output +import os +output = os.popen(command).read() + + diff --git a/doc/user/tasks.sgml b/doc/user/tasks.sgml new file mode 100644 index 00000000..29299ab0 --- /dev/null +++ b/doc/user/tasks.sgml @@ -0,0 +1,109 @@ + + + +There is a common set of simple tasks that many build configurations rely +on as they become more complex. Most build tools have special +purpose constructs for performing these tasks, but since &SConscript; +files are &Python; scripts, you can use more flexible built-in &Python; +services to perform these tasks. This appendix lists a number of these +tasks and how to implement them in &Python;. + + + +Wildcard globbing to create a list of filenames + +import glob +files = glob.glob(wildcard) + + + + +Filename extension substitution + +import os.path +filename = os.path.splitext(filename)[0]+extension + + + + +Appending a path prefix to a list of filenames + +import os.path +filenames = [os.path.join(prefix, x) for x in filenames] + + +or in Python 1.5.2: + + +import os.path +new_filenames = [] +for x in filenames: + new_filenames.append(os.path.join(prefix, x)) + + + + +Substituting a path prefix with another one + +if filename.find(old_prefix) == 0: + filename = filename.replace(old_prefix, new_prefix) + + +or in Python 1.5.2: + + +import string +if string.find(filename, old_prefix) == 0: + filename = string.replace(filename, old_prefix, new_prefix) + + + + +Filtering a filename list to exclude/retain only a specific set +of extensions + +import os.path +filenames = [x for x in filenames if os.path.splitext(x)[1] in extensions] + + +or in Python 1.5.2: + + +import os.path +new_filenames = [] +for x in filenames: + if os.path.splitext(x)[1] in extensions: + new_filenames.append(x) + + + + +The "backtick function": run a shell command and capture the +output +import os +output = os.popen(command).read() + + diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 885c744d..42c5de1d 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -203,6 +203,9 @@ RELEASE 0.95 - XXX - Build Type Libraries in the target directory, not the source directory. + - Add an appendix to the User's Guide showing how to accomplish + various common tasks in Python. + From Greg Spencer: - Add support for Microsoft Visual Studio 2003 (version 7.1).