Bug 1442378 - part 3 - factor out common code for zipfiles vs. tarfiles; r=jmaher

The zipfile and tarfiles paths for finding interesting files in the
installer have duplicated code.  We can eliminate this duplicated code
by factoring out a function to just get the paths and sizes for files
contained in the installer.  If we need to make changes to how paths are
processed, we now only have to make the change in a single place, and we
can add other kinds of installers easily in the future.
This commit is contained in:
Nathan Froyd 2018-03-02 08:34:39 -05:00
Родитель 4385ae1590
Коммит c2d44cf64e
1 изменённых файлов: 19 добавлений и 24 удалений

Просмотреть файл

@ -1586,28 +1586,23 @@ or run without that action (ie: --no-{action})"
installer_size = 0
size_measurements = []
def paths_with_sizes(installer):
if zipfile.is_zipfile(installer):
with zipfile.ZipFile(installer, 'r') as zf:
for zi in zf.infolist():
yield zi.filename, zi.file_size
elif tarfile.is_tarfile(installer):
with tarfile.open(installer, 'r:*') as tf:
for ti in tf:
yield ti.name, ti.size
if os.path.exists(installer):
installer_size = self.query_filesize(installer)
self.info('Size of %s: %s bytes' % (packageName, installer_size))
try:
subtests = {}
if zipfile.is_zipfile(installer):
with zipfile.ZipFile(installer, 'r') as zf:
for zi in zf.infolist():
name = os.path.basename(zi.filename)
size = zi.file_size
if name in interests:
if name in subtests:
# File seen twice in same archive;
# ignore to avoid confusion.
subtests[name] = None
else:
subtests[name] = size
elif tarfile.is_tarfile(installer):
with tarfile.open(installer, 'r:*') as tf:
for ti in tf:
name = os.path.basename(ti.name)
size = ti.size
for path, size in paths_with_sizes(installer):
name = os.path.basename(path)
if name in interests:
if name in subtests:
# File seen twice in same archive;