kopia lustrzana https://github.com/micropython/micropython-lib
tarfile: Rename from utarfile.
This is compatible with the CPython module, so should be named tarfile. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>pull/702/head
rodzic
e45a7f6c18
commit
5004436164
|
@ -1,4 +0,0 @@
|
||||||
metadata(description="Adds write (create/append) support to utarfile.", version="0.1.1")
|
|
||||||
|
|
||||||
require("utarfile")
|
|
||||||
package("utarfile")
|
|
|
@ -1,7 +1,7 @@
|
||||||
""" tar append writes additional files to the end of an existing tar file."""
|
""" tar append writes additional files to the end of an existing tar file."""
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import utarfile
|
import tarfile
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
raise ValueError("Usage: %s appendfile.tar newinputfile1 ..." % sys.argv[0])
|
raise ValueError("Usage: %s appendfile.tar newinputfile1 ..." % sys.argv[0])
|
||||||
|
@ -10,6 +10,6 @@ tarfile = sys.argv[1]
|
||||||
if not tarfile.endswith(".tar"):
|
if not tarfile.endswith(".tar"):
|
||||||
raise ValueError("Filename %s does not end with .tar" % tarfile)
|
raise ValueError("Filename %s does not end with .tar" % tarfile)
|
||||||
|
|
||||||
with utarfile.TarFile(sys.argv[1], "a") as t:
|
with tarfile.TarFile(sys.argv[1], "a") as t:
|
||||||
for filename in sys.argv[2:]:
|
for filename in sys.argv[2:]:
|
||||||
t.add(filename)
|
t.add(filename)
|
|
@ -1,6 +1,6 @@
|
||||||
""" tar create writes a new tar file containing the specified files."""
|
""" tar create writes a new tar file containing the specified files."""
|
||||||
import sys
|
import sys
|
||||||
import utarfile
|
import tarfile
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
raise ValueError("Usage: %s outputfile.tar inputfile1 ..." % sys.argv[0])
|
raise ValueError("Usage: %s outputfile.tar inputfile1 ..." % sys.argv[0])
|
||||||
|
@ -9,6 +9,6 @@ tarfile = sys.argv[1]
|
||||||
if not tarfile.endswith(".tar"):
|
if not tarfile.endswith(".tar"):
|
||||||
raise ValueError("Filename %s does not end with .tar" % tarfile)
|
raise ValueError("Filename %s does not end with .tar" % tarfile)
|
||||||
|
|
||||||
with utarfile.TarFile(sys.argv[1], "w") as t:
|
with tarfile.TarFile(sys.argv[1], "w") as t:
|
||||||
for filename in sys.argv[2:]:
|
for filename in sys.argv[2:]:
|
||||||
t.add(filename)
|
t.add(filename)
|
|
@ -0,0 +1,4 @@
|
||||||
|
metadata(description="Adds write (create/append) support to tarfile.", version="0.1.1")
|
||||||
|
|
||||||
|
require("tarfile")
|
||||||
|
package("tarfile")
|
|
@ -1,7 +1,7 @@
|
||||||
"""Additions to the TarFile class to support creating and appending tar files.
|
"""Additions to the TarFile class to support creating and appending tar files.
|
||||||
|
|
||||||
The methods defined below in are injected into the TarFile class in the
|
The methods defined below in are injected into the TarFile class in the
|
||||||
utarfile package.
|
tarfile package.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import uctypes
|
import uctypes
|
|
@ -1,14 +1,14 @@
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import utarfile
|
import tarfile
|
||||||
|
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
raise ValueError("Usage: %s inputfile.tar" % sys.argv[0])
|
raise ValueError("Usage: %s inputfile.tar" % sys.argv[0])
|
||||||
|
|
||||||
t = utarfile.TarFile(sys.argv[1])
|
t = tarfile.TarFile(sys.argv[1])
|
||||||
for i in t:
|
for i in t:
|
||||||
print(i.name)
|
print(i.name)
|
||||||
if i.type == utarfile.DIRTYPE:
|
if i.type == tarfile.DIRTYPE:
|
||||||
os.mkdir(i.name)
|
os.mkdir(i.name)
|
||||||
else:
|
else:
|
||||||
f = t.extractfile(i)
|
f = t.extractfile(i)
|
|
@ -2,4 +2,4 @@ metadata(description="Read-only implementation of Python's tarfile.", version="0
|
||||||
|
|
||||||
# Originally written by Paul Sokolovsky.
|
# Originally written by Paul Sokolovsky.
|
||||||
|
|
||||||
package("utarfile")
|
package("tarfile")
|
|
@ -93,7 +93,7 @@ class TarFile:
|
||||||
try:
|
try:
|
||||||
self._open_write(name=name, mode=mode, fileobj=fileobj)
|
self._open_write(name=name, mode=mode, fileobj=fileobj)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
raise NotImplementedError("Install utarfile-write")
|
raise NotImplementedError("Install tarfile-write")
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self
|
return self
|
||||||
|
@ -141,7 +141,7 @@ class TarFile:
|
||||||
pass
|
pass
|
||||||
self.f.close()
|
self.f.close()
|
||||||
|
|
||||||
# Add additional methods to support write/append from the utarfile-write package.
|
# Add additional methods to support write/append from the tarfile-write package.
|
||||||
try:
|
try:
|
||||||
from .write import _open_write, _close_write, addfile, add
|
from .write import _open_write, _close_write, addfile, add
|
||||||
except ImportError:
|
except ImportError:
|
Ładowanie…
Reference in New Issue