Skip to content

Commit

Permalink
Merge pull request SCons#4527 from mwichmann/tarfile-mod
Browse files Browse the repository at this point in the history
scons-time: add filter to tarfile extract call.
  • Loading branch information
bdbaddog authored May 15, 2024
2 parents e853087 + 3813ec6 commit c33bb1a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 42 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
tweaks. Update manpage and user guide for Variables usage.
- Regularize internal usage of Python version strings and drop one
old Python 2-only code block in a test.
- scons-time tests now supply a "filter" argument to tarfile.extract
to quiet a warning which was added in Python 3.13 beta 1.


RELEASE 4.7.0 - Sun, 17 Mar 2024 17:22:20 -0700
Expand Down
28 changes: 15 additions & 13 deletions bin/scons-time.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,23 +223,25 @@ def draw(self):

def untar(fname):
import tarfile
tar = tarfile.open(name=fname, mode='r')
for tarinfo in tar:
tar.extract(tarinfo)
tar.close()
with tarfile.open(name=fname, mode='r') as tar:
for tarinfo in tar:
try:
tar.extract(tarinfo, filter="tar")
except TypeError:
tar.extract(tarinfo)


def unzip(fname):
import zipfile
zf = zipfile.ZipFile(fname, 'r')
for name in zf.namelist():
dir = os.path.dirname(name)
try:
os.makedirs(dir)
except OSError:
pass
with open(name, 'wb') as f:
f.write(zf.read(name))
with zipfile.ZipFile(fname, 'r') as zf:
for name in zf.namelist():
dir = os.path.dirname(name)
try:
os.makedirs(dir)
except OSError:
pass
with open(name, 'wb') as f:
f.write(zf.read(name))


def read_tree(dir):
Expand Down
44 changes: 15 additions & 29 deletions testing/framework/TestSCons_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def write_args(fp, args):
Memory before building targets: 300%(index)s
Memory after building targets: 400%(index)s
Object counts:
pre- post- pre- post-
pre- post- pre- post-
read read build build Class
101%(index)s 102%(index)s 103%(index)s 104%(index)s Action.CommandAction
201%(index)s 202%(index)s 203%(index)s 204%(index)s Action.CommandGeneratorAction
Expand Down Expand Up @@ -273,20 +273,16 @@ def write_sample_directory(self, archive, dir, files):

def write_sample_tarfile(self, archive, dir, files):
import shutil
try:
import tarfile
except ImportError:
self.skip_test('no tarfile module\n', from_framework=True)
else:
base, suffix = self.archive_split(archive)
import tarfile
base, suffix = self.archive_split(archive)

mode = {
'.tar' : 'w',
'.tar.gz' : 'w:gz',
'.tgz' : 'w:gz',
}
mode = {
'.tar' : 'w',
'.tar.gz' : 'w:gz',
'.tgz' : 'w:gz',
}

tar = tarfile.open(archive, mode[suffix])
with tarfile.open(archive, mode[suffix]) as tar:
for name, content in files:
path = os.path.join(dir, name)
with open(path, 'wb') as f:
Expand All @@ -298,30 +294,20 @@ def write_sample_tarfile(self, archive, dir, files):
tarinfo.gname = 'fake_group'
with open(path, 'rb') as f:
tar.addfile(tarinfo, f)
tar.close()
shutil.rmtree(dir)
return self.workpath(archive)
shutil.rmtree(dir)
return self.workpath(archive)

def write_sample_zipfile(self, archive, dir, files):
import shutil
try:
import zipfile
except ImportError:

sys.stderr.write('no zipfile module\n')
self.no_result()

else:

zip = zipfile.ZipFile(archive, 'w')
import zipfile
with zipfile.ZipFile(archive, 'w') as zip:
for name, content in files:
path = os.path.join(dir, name)
with open(path, 'w') as f:
f.write(content)
zip.write(path)
zip.close()
shutil.rmtree(dir)
return self.workpath(archive)
shutil.rmtree(dir)
return self.workpath(archive)

sample_project_files = [
('SConstruct', SConstruct),
Expand Down

0 comments on commit c33bb1a

Please sign in to comment.