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
ffa155ad
Kaydet (Commit)
ffa155ad
authored
Nis 29, 2010
tarafından
Tarek Ziadé
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
make sure shutil checks for bz2 availability before it uses it.
üst
bf043491
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
9 deletions
+35
-9
shutil.rst
Doc/library/shutil.rst
+3
-3
shutil.py
Lib/shutil.py
+22
-5
test_shutil.py
Lib/test/test_shutil.py
+10
-1
No files found.
Doc/library/shutil.rst
Dosyayı görüntüle @
ffa155ad
...
...
@@ -238,7 +238,7 @@ Archives operations
*base_name* is the name of the file to create, including the path, minus
any format-specific extension. *format* is the archive format: one of
"zip", "tar", "bztar" or "gztar".
"zip", "tar", "bztar"
(if the :mod:`bz2` module is available)
or "gztar".
*root_dir* is a directory that will be the root directory of the
archive; i.e. we typically chdir into *root_dir* before creating the
...
...
@@ -264,7 +264,7 @@ Archives operations
By default :mod:`shutil` provides these formats:
- *gztar*: gzip'ed tar-file
- *bztar*: bzip2'ed tar-file
- *bztar*: bzip2'ed tar-file
(if the :mod:`bz2` module is available.)
- *tar*: uncompressed tar file
- *zip*: ZIP file
...
...
@@ -346,7 +346,7 @@ Archives operations
By default :mod:`shutil` provides these formats:
- *gztar*: gzip'ed tar-file
- *bztar*: bzip2'ed tar-file
- *bztar*: bzip2'ed tar-file
(if the :mod:`bz2` module is available.)
- *tar*: uncompressed tar file
- *zip*: ZIP file
...
...
Lib/shutil.py
Dosyayı görüntüle @
ffa155ad
...
...
@@ -13,6 +13,12 @@ import collections
import
errno
import
tarfile
try
:
import
bz2
_BZ2_SUPPORTED
=
True
except
ImportError
:
_BZ2_SUPPORTED
=
False
try
:
from
pwd
import
getpwnam
except
ImportError
:
...
...
@@ -376,13 +382,17 @@ def _make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
Returns the output filename.
"""
tar_compression
=
{
'gzip'
:
'gz'
,
'bzip2'
:
'bz2'
,
None
:
''
}
compress_ext
=
{
'gzip'
:
'.gz'
,
'bzip2'
:
'.bz2'
}
tar_compression
=
{
'gzip'
:
'gz'
,
None
:
''
}
compress_ext
=
{
'gzip'
:
'.gz'
}
if
_BZ2_SUPPORTED
:
tar_compression
[
'bzip2'
]
=
'bz2'
compress_ext
[
'bzip2'
]
=
'.bz2'
# flags for compression program, each element of list will be an argument
if
compress
is
not
None
and
compress
not
in
compress_ext
.
keys
():
raise
ValueError
(
"bad value for 'compress'
: must be None, 'gzip', or
"
"
'bzip2'"
)
raise
ValueError
(
"bad value for 'compress'
, or compression format not
"
"
supported : {0}"
.
format
(
compress
)
)
archive_name
=
base_name
+
'.tar'
+
compress_ext
.
get
(
compress
,
''
)
archive_dir
=
os
.
path
.
dirname
(
archive_name
)
...
...
@@ -488,6 +498,10 @@ _ARCHIVE_FORMATS = {
'zip'
:
(
_make_zipfile
,
[],
"ZIP file"
)
}
if
_BZ2_SUPPORTED
:
_ARCHIVE_FORMATS
[
'bztar'
]
=
(
_make_tarball
,
[(
'compress'
,
'bzip2'
)],
"bzip2'ed tar-file"
)
def
get_archive_formats
():
"""Returns a list of supported formats for archiving and unarchiving.
...
...
@@ -690,11 +704,14 @@ def _unpack_tarfile(filename, extract_dir):
_UNPACK_FORMATS
=
{
'gztar'
:
([
'.tar.gz'
,
'.tgz'
],
_unpack_tarfile
,
[],
"gzip'ed tar-file"
),
'bztar'
:
([
'.bz2'
],
_unpack_tarfile
,
[],
"bzip2'ed tar-file"
),
'tar'
:
([
'.tar'
],
_unpack_tarfile
,
[],
"uncompressed tar file"
),
'zip'
:
([
'.zip'
],
_unpack_zipfile
,
[],
"ZIP file"
)
}
if
_BZ2_SUPPORTED
:
_UNPACK_FORMATS
[
'bztar'
]
=
([
'.bz2'
],
_unpack_tarfile
,
[],
"bzip2'ed tar-file"
)
def
_find_unpack_format
(
filename
):
for
name
,
info
in
_UNPACK_FORMATS
.
items
():
for
extension
in
info
[
0
]:
...
...
Lib/test/test_shutil.py
Dosyayı görüntüle @
ffa155ad
...
...
@@ -22,6 +22,12 @@ import warnings
from
test
import
support
from
test.support
import
TESTFN
,
check_warnings
,
captured_stdout
try
:
import
bz2
BZ2_SUPPORTED
=
True
except
ImportError
:
BZ2_SUPPORTED
=
False
TESTFN2
=
TESTFN
+
"2"
try
:
...
...
@@ -612,8 +618,11 @@ class TestShutil(unittest.TestCase):
@unittest.skipUnless
(
zlib
,
"Requires zlib"
)
def
test_unpack_archive
(
self
):
formats
=
[
'tar'
,
'gztar'
,
'zip'
]
if
BZ2_SUPPORTED
:
formats
.
append
(
'bztar'
)
for
format
in
(
'tar'
,
'gztar'
,
'bztar'
,
'zip'
)
:
for
format
in
formats
:
tmpdir
=
self
.
mkdtemp
()
base_dir
,
root_dir
,
base_name
=
self
.
_create_files
()
tmpdir2
=
self
.
mkdtemp
()
...
...
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