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
150cd191
Kaydet (Commit)
150cd191
authored
Nis 07, 2017
tarafından
Serhiy Storchaka
Kaydeden (comit)
GitHub
Nis 07, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-29958: Minor improvements to zipfile and tarfile CLI. (#944)
üst
fd0cd07a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
14 deletions
+28
-14
tarfile.py
Lib/tarfile.py
+6
-9
test_tarfile.py
Lib/test/test_tarfile.py
+10
-0
test_zipfile.py
Lib/test/test_zipfile.py
+10
-0
zipfile.py
Lib/zipfile.py
+2
-5
No files found.
Lib/tarfile.py
Dosyayı görüntüle @
150cd191
...
@@ -2450,11 +2450,11 @@ open = TarFile.open
...
@@ -2450,11 +2450,11 @@ open = TarFile.open
def
main
():
def
main
():
import
argparse
import
argparse
description
=
'A simple command
line interface for tarfile module.'
description
=
'A simple command
-
line interface for tarfile module.'
parser
=
argparse
.
ArgumentParser
(
description
=
description
)
parser
=
argparse
.
ArgumentParser
(
description
=
description
)
parser
.
add_argument
(
'-v'
,
'--verbose'
,
action
=
'store_true'
,
default
=
False
,
parser
.
add_argument
(
'-v'
,
'--verbose'
,
action
=
'store_true'
,
default
=
False
,
help
=
'Verbose output'
)
help
=
'Verbose output'
)
group
=
parser
.
add_mutually_exclusive_group
()
group
=
parser
.
add_mutually_exclusive_group
(
required
=
True
)
group
.
add_argument
(
'-l'
,
'--list'
,
metavar
=
'<tarfile>'
,
group
.
add_argument
(
'-l'
,
'--list'
,
metavar
=
'<tarfile>'
,
help
=
'Show listing of a tarfile'
)
help
=
'Show listing of a tarfile'
)
group
.
add_argument
(
'-e'
,
'--extract'
,
nargs
=
'+'
,
group
.
add_argument
(
'-e'
,
'--extract'
,
nargs
=
'+'
,
...
@@ -2467,7 +2467,7 @@ def main():
...
@@ -2467,7 +2467,7 @@ def main():
help
=
'Test if a tarfile is valid'
)
help
=
'Test if a tarfile is valid'
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
if
args
.
test
:
if
args
.
test
is
not
None
:
src
=
args
.
test
src
=
args
.
test
if
is_tarfile
(
src
):
if
is_tarfile
(
src
):
with
open
(
src
,
'r'
)
as
tar
:
with
open
(
src
,
'r'
)
as
tar
:
...
@@ -2478,7 +2478,7 @@ def main():
...
@@ -2478,7 +2478,7 @@ def main():
else
:
else
:
parser
.
exit
(
1
,
'{!r} is not a tar archive.
\n
'
.
format
(
src
))
parser
.
exit
(
1
,
'{!r} is not a tar archive.
\n
'
.
format
(
src
))
elif
args
.
list
:
elif
args
.
list
is
not
None
:
src
=
args
.
list
src
=
args
.
list
if
is_tarfile
(
src
):
if
is_tarfile
(
src
):
with
TarFile
.
open
(
src
,
'r:*'
)
as
tf
:
with
TarFile
.
open
(
src
,
'r:*'
)
as
tf
:
...
@@ -2486,7 +2486,7 @@ def main():
...
@@ -2486,7 +2486,7 @@ def main():
else
:
else
:
parser
.
exit
(
1
,
'{!r} is not a tar archive.
\n
'
.
format
(
src
))
parser
.
exit
(
1
,
'{!r} is not a tar archive.
\n
'
.
format
(
src
))
elif
args
.
extract
:
elif
args
.
extract
is
not
None
:
if
len
(
args
.
extract
)
==
1
:
if
len
(
args
.
extract
)
==
1
:
src
=
args
.
extract
[
0
]
src
=
args
.
extract
[
0
]
curdir
=
os
.
curdir
curdir
=
os
.
curdir
...
@@ -2508,7 +2508,7 @@ def main():
...
@@ -2508,7 +2508,7 @@ def main():
else
:
else
:
parser
.
exit
(
1
,
'{!r} is not a tar archive.
\n
'
.
format
(
src
))
parser
.
exit
(
1
,
'{!r} is not a tar archive.
\n
'
.
format
(
src
))
elif
args
.
create
:
elif
args
.
create
is
not
None
:
tar_name
=
args
.
create
.
pop
(
0
)
tar_name
=
args
.
create
.
pop
(
0
)
_
,
ext
=
os
.
path
.
splitext
(
tar_name
)
_
,
ext
=
os
.
path
.
splitext
(
tar_name
)
compressions
=
{
compressions
=
{
...
@@ -2534,8 +2534,5 @@ def main():
...
@@ -2534,8 +2534,5 @@ def main():
if
args
.
verbose
:
if
args
.
verbose
:
print
(
'{!r} file created.'
.
format
(
tar_name
))
print
(
'{!r} file created.'
.
format
(
tar_name
))
else
:
parser
.
exit
(
1
,
parser
.
format_help
())
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
main
()
main
()
Lib/test/test_tarfile.py
Dosyayı görüntüle @
150cd191
...
@@ -2167,6 +2167,16 @@ class CommandLineTest(unittest.TestCase):
...
@@ -2167,6 +2167,16 @@ class CommandLineTest(unittest.TestCase):
for
tardata
in
files
:
for
tardata
in
files
:
tf
.
add
(
tardata
,
arcname
=
os
.
path
.
basename
(
tardata
))
tf
.
add
(
tardata
,
arcname
=
os
.
path
.
basename
(
tardata
))
def
test_bad_use
(
self
):
rc
,
out
,
err
=
self
.
tarfilecmd_failure
()
self
.
assertEqual
(
out
,
b
''
)
self
.
assertIn
(
b
'usage'
,
err
.
lower
())
self
.
assertIn
(
b
'error'
,
err
.
lower
())
self
.
assertIn
(
b
'required'
,
err
.
lower
())
rc
,
out
,
err
=
self
.
tarfilecmd_failure
(
'-l'
,
''
)
self
.
assertEqual
(
out
,
b
''
)
self
.
assertNotEqual
(
err
.
strip
(),
b
''
)
def
test_test_command
(
self
):
def
test_test_command
(
self
):
for
tar_name
in
testtarnames
:
for
tar_name
in
testtarnames
:
for
opt
in
'-t'
,
'--test'
:
for
opt
in
'-t'
,
'--test'
:
...
...
Lib/test/test_zipfile.py
Dosyayı görüntüle @
150cd191
...
@@ -2140,6 +2140,16 @@ class CommandLineTest(unittest.TestCase):
...
@@ -2140,6 +2140,16 @@ class CommandLineTest(unittest.TestCase):
def
zipfilecmd_failure
(
self
,
*
args
):
def
zipfilecmd_failure
(
self
,
*
args
):
return
script_helper
.
assert_python_failure
(
'-m'
,
'zipfile'
,
*
args
)
return
script_helper
.
assert_python_failure
(
'-m'
,
'zipfile'
,
*
args
)
def
test_bad_use
(
self
):
rc
,
out
,
err
=
self
.
zipfilecmd_failure
()
self
.
assertEqual
(
out
,
b
''
)
self
.
assertIn
(
b
'usage'
,
err
.
lower
())
self
.
assertIn
(
b
'error'
,
err
.
lower
())
self
.
assertIn
(
b
'required'
,
err
.
lower
())
rc
,
out
,
err
=
self
.
zipfilecmd_failure
(
'-l'
,
''
)
self
.
assertEqual
(
out
,
b
''
)
self
.
assertNotEqual
(
err
.
strip
(),
b
''
)
def
test_test_command
(
self
):
def
test_test_command
(
self
):
zip_name
=
findfile
(
'zipdir.zip'
)
zip_name
=
findfile
(
'zipdir.zip'
)
for
opt
in
'-t'
,
'--test'
:
for
opt
in
'-t'
,
'--test'
:
...
...
Lib/zipfile.py
Dosyayı görüntüle @
150cd191
...
@@ -1965,9 +1965,9 @@ class PyZipFile(ZipFile):
...
@@ -1965,9 +1965,9 @@ class PyZipFile(ZipFile):
def
main
(
args
=
None
):
def
main
(
args
=
None
):
import
argparse
import
argparse
description
=
'A simple command
line interface for zipfile module.'
description
=
'A simple command
-
line interface for zipfile module.'
parser
=
argparse
.
ArgumentParser
(
description
=
description
)
parser
=
argparse
.
ArgumentParser
(
description
=
description
)
group
=
parser
.
add_mutually_exclusive_group
()
group
=
parser
.
add_mutually_exclusive_group
(
required
=
True
)
group
.
add_argument
(
'-l'
,
'--list'
,
metavar
=
'<zipfile>'
,
group
.
add_argument
(
'-l'
,
'--list'
,
metavar
=
'<zipfile>'
,
help
=
'Show listing of a zipfile'
)
help
=
'Show listing of a zipfile'
)
group
.
add_argument
(
'-e'
,
'--extract'
,
nargs
=
2
,
group
.
add_argument
(
'-e'
,
'--extract'
,
nargs
=
2
,
...
@@ -2022,8 +2022,5 @@ def main(args=None):
...
@@ -2022,8 +2022,5 @@ def main(args=None):
zippath
=
''
zippath
=
''
addToZip
(
zf
,
path
,
zippath
)
addToZip
(
zf
,
path
,
zippath
)
else
:
parser
.
exit
(
2
,
parser
.
format_usage
())
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
main
()
main
()
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