Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / html / python / dist / module-distutils.util.html
CommitLineData
920dae64
AT
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3<head>
4<link rel="STYLESHEET" href="dist.css" type='text/css' />
5<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
6<link rel='start' href='../index.html' title='Python Documentation Index' />
7<link rel="first" href="dist.html" title='Distributing Python Modules' />
8<link rel='index' href='genindex.html' title='Index' />
9<link rel='last' href='about.html' title='About this document...' />
10<link rel='help' href='about.html' title='About this document...' />
11<link rel="next" href="module-distutils.dist.html" />
12<link rel="prev" href="module-distutils.fileutil.html" />
13<link rel="parent" href="api-reference.html" />
14<link rel="next" href="module-distutils.dist.html" />
15<meta name='aesop' content='information' />
16<title>10.13 distutils.util -- Miscellaneous other utility functions</title>
17</head>
18<body>
19<DIV CLASS="navigation">
20<div id='top-navigation-panel' xml:id='top-navigation-panel'>
21<table align="center" width="100%" cellpadding="0" cellspacing="2">
22<tr>
23<td class='online-navigation'><a rel="prev" title="10.12 distutils.file_util "
24 href="module-distutils.fileutil.html"><img src='../icons/previous.png'
25 border='0' height='32' alt='Previous Page' width='32' /></A></td>
26<td class='online-navigation'><a rel="parent" title="10. API Reference"
27 href="api-reference.html"><img src='../icons/up.png'
28 border='0' height='32' alt='Up One Level' width='32' /></A></td>
29<td class='online-navigation'><a rel="next" title="10.14 distutils.dist "
30 href="module-distutils.dist.html"><img src='../icons/next.png'
31 border='0' height='32' alt='Next Page' width='32' /></A></td>
32<td align="center" width="100%">Distributing Python Modules</td>
33<td class='online-navigation'><img src='../icons/blank.png'
34 border='0' height='32' alt='' width='32' /></td>
35<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
36 border='0' height='32' alt='Module Index' width='32' /></a></td>
37<td class='online-navigation'><a rel="index" title="Index"
38 href="genindex.html"><img src='../icons/index.png'
39 border='0' height='32' alt='Index' width='32' /></A></td>
40</tr></table>
41<div class='online-navigation'>
42<b class="navlabel">Previous:</b>
43<a class="sectref" rel="prev" href="module-distutils.fileutil.html">10.12 distutils.file_util </A>
44<b class="navlabel">Up:</b>
45<a class="sectref" rel="parent" href="api-reference.html">10. API Reference</A>
46<b class="navlabel">Next:</b>
47<a class="sectref" rel="next" href="module-distutils.dist.html">10.14 distutils.dist </A>
48</div>
49<hr /></div>
50</DIV>
51<!--End of Navigation Panel-->
52
53<H1><A NAME="SECTION00101300000000000000000">
5410.13 <tt class="module">distutils.util</tt> -- Miscellaneous other utility functions</A>
55</H1>
56<A NAME="module-distutils.util"></A>
57
58<P>
59This module contains other assorted bits and pieces that don't fit into
60any other utility module.
61
62<P>
63<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
64 <td><nobr><b><tt id='l2h-79' xml:id='l2h-79' class="function">get_platform</tt></b>(</nobr></td>
65 <td><var></var>)</td></tr></table></dt>
66<dd>
67Return a string that identifies the current platform. This is used
68mainly to distinguish platform-specific build directories and
69platform-specific built distributions. Typically includes the OS name
70and version and the architecture (as supplied by 'os.uname()'),
71although the exact information included depends on the OS; eg. for IRIX
72the architecture isn't particularly important (IRIX only runs on SGI
73hardware), but for Linux the kernel version isn't particularly
74important.
75
76<P>
77Examples of returned values:
78
79<UL>
80<LI><code>linux-i586</code>
81</LI>
82<LI><code>linux-alpha</code>
83</LI>
84<LI><code>solaris-2.6-sun4u</code>
85</LI>
86<LI><code>irix-5.3</code>
87</LI>
88<LI><code>irix64-6.2</code>
89</LI>
90</UL>
91
92<P>
93For non-POSIX platforms, currently just returns <code>sys.platform</code>.
94</dl>
95
96<P>
97<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
98 <td><nobr><b><tt id='l2h-80' xml:id='l2h-80' class="function">convert_path</tt></b>(</nobr></td>
99 <td><var>pathname</var>)</td></tr></table></dt>
100<dd>
101Return 'pathname' as a name that will work on the native filesystem,
102i.e. split it on '/' and put it back together again using the current
103directory separator. Needed because filenames in the setup script are
104always supplied in Unix style, and have to be converted to the local
105convention before we can actually use them in the filesystem. Raises
106<tt class="exception">ValueError</tt> on non-<span class="Unix">Unix</span>-ish systems if <var>pathname</var> either
107starts or ends with a slash.
108</dl>
109
110<P>
111<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
112 <td><nobr><b><tt id='l2h-81' xml:id='l2h-81' class="function">change_root</tt></b>(</nobr></td>
113 <td><var>new_root, pathname</var>)</td></tr></table></dt>
114<dd>
115Return <var>pathname</var> with <var>new_root</var> prepended. If <var>pathname</var> is
116relative, this is equivalent to "<tt class="samp">os.path.join(new_root,pathname)</tt>"Otherwise, it requires making <var>pathname</var> relative and then joining the
117two, which is tricky on DOS/Windows.
118</dl>
119
120<P>
121<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
122 <td><nobr><b><tt id='l2h-82' xml:id='l2h-82' class="function">check_environ</tt></b>(</nobr></td>
123 <td><var></var>)</td></tr></table></dt>
124<dd>
125Ensure that 'os.environ' has all the environment variables we
126guarantee that users can use in config files, command-line options,
127etc. Currently this includes:
128
129<UL>
130<LI><a class="envvar" id='l2h-90' xml:id='l2h-90'>HOME</a> - user's home directory (<span class="Unix">Unix</span> only)
131</LI>
132<LI><a class="envvar" id='l2h-91' xml:id='l2h-91'>PLAT</a> - description of the current platform, including
133 hardware and OS (see <tt class="function">get_platform()</tt>)
134</LI>
135</UL>
136</dl>
137
138<P>
139<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
140 <td><nobr><b><tt id='l2h-83' xml:id='l2h-83' class="function">subst_vars</tt></b>(</nobr></td>
141 <td><var>s, local_vars</var>)</td></tr></table></dt>
142<dd>
143Perform shell/Perl-style variable substitution on <var>s</var>. Every
144occurrence of <code>$</code> followed by a name is considered a variable, and
145variable is substituted by the value found in the <var>local_vars</var>
146dictionary, or in <code>os.environ</code> if it's not in <var>local_vars</var>.
147<var>os.environ</var> is first checked/augmented to guarantee that it contains
148certain values: see <tt class="function">check_environ()</tt>. Raise <tt class="exception">ValueError</tt>
149for any variables not found in either <var>local_vars</var> or <code>os.environ</code>.
150
151<P>
152Note that this is not a fully-fledged string interpolation function. A
153valid <code>$variable</code> can consist only of upper and lower case letters,
154numbers and an underscore. No { } or <SPAN CLASS="MATH"></SPAN> style quoting is available.
155</dl>
156
157<P>
158<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
159 <td><nobr><b><tt id='l2h-84' xml:id='l2h-84' class="function">grok_environment_error</tt></b>(</nobr></td>
160 <td><var>exc</var><big>[</big><var>, prefix=tex2html_deferred"<tt class="samp">'error: '</tt>"</var><big>]</big><var></var>)</td></tr></table></dt>
161<dd>
162Generate a useful error message from an <tt class="exception">EnvironmentError</tt>
163(<tt class="exception">IOError</tt> or <tt class="exception">OSError</tt>) exception object.
164Handles Python 1.5.1 and later styles, and does what it can to deal with
165exception objects that don't have a filename (which happens when the error
166is due to a two-file operation, such as <tt class="function">rename()</tt> or
167<tt class="function">link()</tt>). Returns the error message as a string prefixed
168with <var>prefix</var>.
169</dl>
170
171<P>
172<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
173 <td><nobr><b><tt id='l2h-85' xml:id='l2h-85' class="function">split_quoted</tt></b>(</nobr></td>
174 <td><var>s</var>)</td></tr></table></dt>
175<dd>
176Split a string up according to Unix shell-like rules for quotes and
177backslashes. In short: words are delimited by spaces, as long as those
178spaces are not escaped by a backslash, or inside a quoted string.
179Single and double quotes are equivalent, and the quote characters can
180be backslash-escaped. The backslash is stripped from any two-character
181escape sequence, leaving only the escaped character. The quote
182characters are stripped from any quoted string. Returns a list of
183words.
184</dl>
185
186<P>
187<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
188 <td><nobr><b><tt id='l2h-86' xml:id='l2h-86' class="function">execute</tt></b>(</nobr></td>
189 <td><var>func, args</var><big>[</big><var>, msg=<code>None</code>, verbose=<code>0</code>, dry_run=<code>0</code></var><big>]</big><var></var>)</td></tr></table></dt>
190<dd>
191Perform some action that affects the outside world (for instance,
192writing to the filesystem). Such actions are special because they
193are disabled by the <var>dry_run</var> flag. This method takes
194care of all that bureaucracy for you; all you have to do is supply the
195function to call and an argument tuple for it (to embody the
196``external action'' being performed), and an optional message to
197print.
198</dl>
199
200<P>
201<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
202 <td><nobr><b><tt id='l2h-87' xml:id='l2h-87' class="function">strtobool</tt></b>(</nobr></td>
203 <td><var>val</var>)</td></tr></table></dt>
204<dd>
205Convert a string representation of truth to true (1) or false (0).
206
207<P>
208True values are <code>y</code>, <code>yes</code>, <code>t</code>, <code>true</code>, <code>on</code>
209and <code>1</code>; false values are <code>n</code>, <code>no</code>, <code>f</code>, <code>false</code>,
210<code>off</code> and <code>0</code>. Raises <tt class="exception">ValueError</tt> if <var>val</var>
211is anything else.
212</dl>
213
214<P>
215<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
216 <td><nobr><b><tt id='l2h-88' xml:id='l2h-88' class="function">byte_compile</tt></b>(</nobr></td>
217 <td><var>py_files</var><big>[</big><var>,
218 optimize=<code>0</code>, force=<code>0</code>,
219 prefix=<code>None</code>, base_dir=<code>None</code>,
220 verbose=<code>1</code>, dry_run=<code>0</code>,
221 direct=<code>None</code></var><big>]</big><var></var>)</td></tr></table></dt>
222<dd>
223Byte-compile a collection of Python source files to either <span class="file">.pyc</span>
224or <span class="file">.pyo</span> files in the same directory. <var>py_files</var> is a list of files
225to compile; any files that don't end in <span class="file">.py</span> are silently skipped.
226<var>optimize</var> must be one of the following:
227
228<UL>
229<LI><code>0</code> - don't optimize (generate <span class="file">.pyc</span>)
230</LI>
231<LI><code>1</code> - normal optimization (like "<tt class="samp">python -O</tt>")
232</LI>
233<LI><code>2</code> - extra optimization (like "<tt class="samp">python -OO</tt>")
234</LI>
235</UL>
236
237<P>
238If <var>force</var> is true, all files are recompiled regardless of
239timestamps.
240
241<P>
242The source filename encoded in each bytecode file defaults to the
243filenames listed in <var>py_files</var>; you can modify these with <var>prefix</var> and
244<var>basedir</var>. <var>prefix</var> is a string that will be stripped off of each
245source filename, and <var>base_dir</var> is a directory name that will be
246prepended (after <var>prefix</var> is stripped). You can supply either or both
247(or neither) of <var>prefix</var> and <var>base_dir</var>, as you wish.
248
249<P>
250If <var>dry_run</var> is true, doesn't actually do anything that would
251affect the filesystem.
252
253<P>
254Byte-compilation is either done directly in this interpreter process
255with the standard <tt class="module">py_compile</tt> module, or indirectly by writing a
256temporary script and executing it. Normally, you should let
257<tt class="function">byte_compile()</tt> figure out to use direct compilation or not (see
258the source for details). The <var>direct</var> flag is used by the script
259generated in indirect mode; unless you know what you're doing, leave
260it set to <code>None</code>.
261</dl>
262
263<P>
264<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
265 <td><nobr><b><tt id='l2h-89' xml:id='l2h-89' class="function">rfc822_escape</tt></b>(</nobr></td>
266 <td><var>header</var>)</td></tr></table></dt>
267<dd>
268Return a version of <var>header</var> escaped for inclusion in an
269<a class="rfc" id='rfcref-5222' xml:id='rfcref-5222'
270href="http://www.faqs.org/rfcs/rfc822.html">RFC 822</a> header, by ensuring there are 8 spaces space after each newline.
271Note that it does no other modification of the string.
272</dl>
273
274<P>
275
276<DIV CLASS="navigation">
277<div class='online-navigation'>
278<p></p><hr />
279<table align="center" width="100%" cellpadding="0" cellspacing="2">
280<tr>
281<td class='online-navigation'><a rel="prev" title="10.12 distutils.file_util "
282 href="module-distutils.fileutil.html"><img src='../icons/previous.png'
283 border='0' height='32' alt='Previous Page' width='32' /></A></td>
284<td class='online-navigation'><a rel="parent" title="10. API Reference"
285 href="api-reference.html"><img src='../icons/up.png'
286 border='0' height='32' alt='Up One Level' width='32' /></A></td>
287<td class='online-navigation'><a rel="next" title="10.14 distutils.dist "
288 href="module-distutils.dist.html"><img src='../icons/next.png'
289 border='0' height='32' alt='Next Page' width='32' /></A></td>
290<td align="center" width="100%">Distributing Python Modules</td>
291<td class='online-navigation'><img src='../icons/blank.png'
292 border='0' height='32' alt='' width='32' /></td>
293<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
294 border='0' height='32' alt='Module Index' width='32' /></a></td>
295<td class='online-navigation'><a rel="index" title="Index"
296 href="genindex.html"><img src='../icons/index.png'
297 border='0' height='32' alt='Index' width='32' /></A></td>
298</tr></table>
299<div class='online-navigation'>
300<b class="navlabel">Previous:</b>
301<a class="sectref" rel="prev" href="module-distutils.fileutil.html">10.12 distutils.file_util </A>
302<b class="navlabel">Up:</b>
303<a class="sectref" rel="parent" href="api-reference.html">10. API Reference</A>
304<b class="navlabel">Next:</b>
305<a class="sectref" rel="next" href="module-distutils.dist.html">10.14 distutils.dist </A>
306</div>
307</div>
308<hr />
309<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
310</DIV>
311<!--End of Navigation Panel-->
312<ADDRESS>
313See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
314</ADDRESS>
315</BODY>
316</HTML>