Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / html / python / lib / tarfile-objects.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="tarinfo-objects.html" />
<link rel="prev" href="module-tarfile.html" />
<link rel="parent" href="module-tarfile.html" />
<link rel="next" href="tarinfo-objects.html" />
<meta name='aesop' content='information' />
<title>7.19.1 TarFile Objects </title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="7.19 tarfile "
href="module-tarfile.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="7.19 tarfile "
href="module-tarfile.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="7.19.2 TarInfo Objects"
href="tarinfo-objects.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-tarfile.html">7.19 tarfile </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-tarfile.html">7.19 tarfile </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="tarinfo-objects.html">7.19.2 TarInfo Objects</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H2><A NAME="SECTION0091910000000000000000"></A><A NAME="tarfile-objects"></A>
<BR>
7.19.1 TarFile Objects
</H2>
<P>
The <tt class="class">TarFile</tt> object provides an interface to a tar archive. A tar
archive is a sequence of blocks. An archive member (a stored file) is made up
of a header block followed by data blocks. It is possible, to store a file in a
tar archive several times. Each archive member is represented by a
<tt class="class">TarInfo</tt> object, see <em class="citetitle"
>TarInfo Objects</em> (section
<A href="tarinfo-objects.html#tarinfo-objects">7.19.2</A>) for details.
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-2900' xml:id='l2h-2900' class="class">TarFile</tt></b>(</nobr></td>
<td><var></var><big>[</big><var>name
</var><big>[</big><var>, mode</var><big>[</big><var>, fileobj</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Open an <em>(uncompressed)</em> tar archive <var>name</var>.
<var>mode</var> is either <code>'r'</code> to read from an existing archive,
<code>'a'</code> to append data to an existing file or <code>'w'</code> to create a new
file overwriting an existing one. <var>mode</var> defaults to <code>'r'</code>.
<P>
If <var>fileobj</var> is given, it is used for reading or writing data.
If it can be determined, <var>mode</var> is overridden by <var>fileobj</var>'s mode.
<div class="note"><b class="label">Note:</b>
<var>fileobj</var> is not closed, when <tt class="class">TarFile</tt> is closed.
</div>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2901' xml:id='l2h-2901' class="method">open</tt></b>(</nobr></td>
<td><var>...</var>)</td></tr></table></dt>
<dd>
Alternative constructor. The <tt class="function">open()</tt> function on module level is
actually a shortcut to this classmethod. See section&nbsp;<A href="module-tarfile.html#module-tarfile">7.19</A>
for details.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2902' xml:id='l2h-2902' class="method">getmember</tt></b>(</nobr></td>
<td><var>name</var>)</td></tr></table></dt>
<dd>
Return a <tt class="class">TarInfo</tt> object for member <var>name</var>. If <var>name</var> can
not be found in the archive, <tt class="exception">KeyError</tt> is raised.
<div class="note"><b class="label">Note:</b>
If a member occurs more than once in the archive, its last
occurrence is assumed to be the most up-to-date version.
</div>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2903' xml:id='l2h-2903' class="method">getmembers</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Return the members of the archive as a list of <tt class="class">TarInfo</tt> objects.
The list has the same order as the members in the archive.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2904' xml:id='l2h-2904' class="method">getnames</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Return the members as a list of their names. It has the same order as
the list returned by <tt class="method">getmembers()</tt>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2905' xml:id='l2h-2905' class="method">list</tt></b>(</nobr></td>
<td><var>verbose=True</var>)</td></tr></table></dt>
<dd>
Print a table of contents to <code>sys.stdout</code>. If <var>verbose</var> is
<tt class="constant">False</tt>, only the names of the members are printed. If it is
<tt class="constant">True</tt>, output similar to that of <b class="program">ls -l</b> is produced.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2906' xml:id='l2h-2906' class="method">next</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Return the next member of the archive as a <tt class="class">TarInfo</tt> object, when
<tt class="class">TarFile</tt> is opened for reading. Return <code>None</code> if there is no
more available.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2907' xml:id='l2h-2907' class="method">extract</tt></b>(</nobr></td>
<td><var>member</var><big>[</big><var>, path</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Extract a member from the archive to the current working directory,
using its full name. Its file information is extracted as accurately as
possible.
<var>member</var> may be a filename or a <tt class="class">TarInfo</tt> object.
You can specify a different directory using <var>path</var>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2908' xml:id='l2h-2908' class="method">extractfile</tt></b>(</nobr></td>
<td><var>member</var>)</td></tr></table></dt>
<dd>
Extract a member from the archive as a file object.
<var>member</var> may be a filename or a <tt class="class">TarInfo</tt> object.
If <var>member</var> is a regular file, a file-like object is returned.
If <var>member</var> is a link, a file-like object is constructed from the
link's target.
If <var>member</var> is none of the above, <code>None</code> is returned.
<div class="note"><b class="label">Note:</b>
The file-like object is read-only and provides the following methods:
<tt class="method">read()</tt>, <tt class="method">readline()</tt>, <tt class="method">readlines()</tt>,
<tt class="method">seek()</tt>, <tt class="method">tell()</tt>.
</div>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2909' xml:id='l2h-2909' class="method">add</tt></b>(</nobr></td>
<td><var>name</var><big>[</big><var>, arcname</var><big>[</big><var>, recursive</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Add the file <var>name</var> to the archive. <var>name</var> may be any type
of file (directory, fifo, symbolic link, etc.).
If given, <var>arcname</var> specifies an alternative name for the file in the
archive. Directories are added recursively by default.
This can be avoided by setting <var>recursive</var> to <tt class="constant">False</tt>;
the default is <tt class="constant">True</tt>.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2910' xml:id='l2h-2910' class="method">addfile</tt></b>(</nobr></td>
<td><var>tarinfo</var><big>[</big><var>, fileobj</var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Add the <tt class="class">TarInfo</tt> object <var>tarinfo</var> to the archive.
If <var>fileobj</var> is given, <code><var>tarinfo</var>.size</code> bytes are read
from it and added to the archive. You can create <tt class="class">TarInfo</tt> objects
using <tt class="method">gettarinfo()</tt>.
<div class="note"><b class="label">Note:</b>
On Windows platforms, <var>fileobj</var> should always be opened with mode
<code>'rb'</code> to avoid irritation about the file size.
</div>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2911' xml:id='l2h-2911' class="method">gettarinfo</tt></b>(</nobr></td>
<td><var></var><big>[</big><var>name</var><big>[</big><var>,
arcname</var><big>[</big><var>, fileobj</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Create a <tt class="class">TarInfo</tt> object for either the file <var>name</var> or
the file object <var>fileobj</var> (using <tt class="function">os.fstat()</tt> on its
file descriptor). You can modify some of the <tt class="class">TarInfo</tt>'s
attributes before you add it using <tt class="method">addfile()</tt>. If given,
<var>arcname</var> specifies an alternative name for the file in the
archive.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><tt id='l2h-2912' xml:id='l2h-2912' class="method">close</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Close the <tt class="class">TarFile</tt>. In write mode, two finishing zero
blocks are appended to the archive.
</dl>
<P>
<dl><dt><b><tt id='l2h-2913' xml:id='l2h-2913' class="member">posix</tt></b></dt>
<dd>
If true, create a POSIX 1003.1-1990 compliant archive. GNU
extensions are not used, because they are not part of the POSIX
standard. This limits the length of filenames to at most 256,
link names to 100 characters and the maximum file size to 8
gigabytes. A <tt class="exception">ValueError</tt> is raised if a file exceeds
this limit. If false, create a GNU tar compatible archive. It
will not be POSIX compliant, but can store files without any
of the above restrictions.
<span class="versionnote">Changed in version 2.4:
<var>posix</var> defaults to <tt class="constant">False</tt>.</span>
</dl>
<P>
<dl><dt><b><tt id='l2h-2914' xml:id='l2h-2914' class="member">dereference</tt></b></dt>
<dd>
If false, add symbolic and hard links to archive. If true, add the
content of the target files to the archive. This has no effect on
systems that do not support symbolic links.
</dl>
<P>
<dl><dt><b><tt id='l2h-2915' xml:id='l2h-2915' class="member">ignore_zeros</tt></b></dt>
<dd>
If false, treat an empty block as the end of the archive. If true,
skip empty (and invalid) blocks and try to get as many members as
possible. This is only useful for concatenated or damaged
archives.
</dl>
<P>
<dl><dt><b><tt id='l2h-2916' xml:id='l2h-2916' class="member">debug=0</tt></b></dt>
<dd>
To be set from <code>0</code> (no debug messages; the default) up to
<code>3</code> (all debug messages). The messages are written to
<code>sys.stderr</code>.
</dl>
<P>
<dl><dt><b><tt id='l2h-2917' xml:id='l2h-2917' class="member">errorlevel</tt></b></dt>
<dd>
If <code>0</code> (the default), all errors are ignored when using
<tt class="method">extract()</tt>. Nevertheless, they appear as error messages
in the debug output, when debugging is enabled. If <code>1</code>, all
<em>fatal</em> errors are raised as <tt class="exception">OSError</tt> or
<tt class="exception">IOError</tt> exceptions. If <code>2</code>, all <em>non-fatal</em>
errors are raised as <tt class="exception">TarError</tt> exceptions as well.
</dl>
<P>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="7.19 tarfile "
href="module-tarfile.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="7.19 tarfile "
href="module-tarfile.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="7.19.2 TarInfo Objects"
href="tarinfo-objects.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="module-tarfile.html">7.19 tarfile </A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-tarfile.html">7.19 tarfile </A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="tarinfo-objects.html">7.19.2 TarInfo Objects</A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>