Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
00a73e77
Kaydet (Commit)
00a73e77
authored
Mar 04, 2005
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Patch #1043890: tarfile: add extractall() method.
üst
fd78a6f7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
0 deletions
+68
-0
libtarfile.tex
Doc/lib/libtarfile.tex
+25
-0
tarfile.py
Lib/tarfile.py
+41
-0
NEWS
Misc/NEWS
+2
-0
No files found.
Doc/lib/libtarfile.tex
Dosyayı görüntüle @
00a73e77
...
...
@@ -196,12 +196,29 @@ tar archive several times. Each archive member is represented by a
more available.
\end{methoddesc}
\begin{methoddesc}
{
extractall
}{
\optional
{
path
\optional
{
, members
}}}
Extract all members from the archive to the current working directory
or directory
\var
{
path
}
. If optional
\var
{
members
}
is given, it must be
a subset of the list returned by
\method
{
getmembers()
}
.
Directory informations like owner, modification time and permissions are
set after all members have been extracted. This is done to work around two
problems: A directory's modification time is reset each time a file is
created in it. And, if a directory's permissions do not allow writing,
extracting files to it will fail.
\versionadded
{
2.5
}
\end{methoddesc}
\begin{methoddesc}
{
extract
}{
member
\optional
{
, path
}}
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
}
may be a filename or a
\class
{
TarInfo
}
object.
You can specify a different directory using
\var
{
path
}
.
\begin{notice}
Because the
\method
{
extract()
}
method allows random access to a tar
archive there are some issues you must take care of yourself. See the
description for
\method
{
extractall()
}
above.
\end{notice}
\end{methoddesc}
\begin{methoddesc}
{
extractfile
}{
member
}
...
...
@@ -416,6 +433,14 @@ A \class{TarInfo} object also provides some convenient query methods:
\subsection
{
Examples
\label
{
tar-examples
}}
How to extract an entire tar archive to the current working directory:
\begin{verbatim}
import tarfile
tar = tarfile.open("sample.tar.gz")
tar.extractall()
tar.close()
\end{verbatim}
How to create an uncompressed tar archive from a list of filenames:
\begin{verbatim}
import tarfile
...
...
Lib/tarfile.py
Dosyayı görüntüle @
00a73e77
...
...
@@ -1321,6 +1321,47 @@ class TarFile(object):
self
.
members
.
append
(
tarinfo
)
def
extractall
(
self
,
path
=
"."
,
members
=
None
):
"""Extract all members from the archive to the current working
directory and set owner, modification time and permissions on
directories afterwards. `path' specifies a different directory
to extract to. `members' is optional and must be a subset of the
list returned by getmembers().
"""
directories
=
[]
if
members
is
None
:
members
=
self
for
tarinfo
in
members
:
if
tarinfo
.
isdir
():
# Extract directory with a safe mode, so that
# all files below can be extracted as well.
try
:
os
.
makedirs
(
os
.
path
.
join
(
path
,
tarinfo
.
name
),
0777
)
except
EnvironmentError
:
pass
directories
.
append
(
tarinfo
)
else
:
self
.
extract
(
tarinfo
,
path
)
# Reverse sort directories.
directories
.
sort
(
lambda
a
,
b
:
cmp
(
a
.
name
,
b
.
name
))
directories
.
reverse
()
# Set correct owner, mtime and filemode on directories.
for
tarinfo
in
directories
:
path
=
os
.
path
.
join
(
path
,
tarinfo
.
name
)
try
:
self
.
chown
(
tarinfo
,
path
)
self
.
utime
(
tarinfo
,
path
)
self
.
chmod
(
tarinfo
,
path
)
except
ExtractError
,
e
:
if
self
.
errorlevel
>
1
:
raise
else
:
self
.
_dbg
(
1
,
"tarfile:
%
s"
%
e
)
def
extract
(
self
,
member
,
path
=
""
):
"""Extract a member from the archive to the current working directory,
using its full name. Its file information is extracted as accurately
...
...
Misc/NEWS
Dosyayı görüntüle @
00a73e77
...
...
@@ -75,6 +75,8 @@ Extension Modules
Library
-------
- Patch #1043890: Add extractall method to tarfile.
- Patch #1075887: Don'
t
require
MSVC
in
distutils
if
there
is
nothing
to
build
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment