зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
4385ae1590
Коммит
c2d44cf64e
|
@ -1586,35 +1586,30 @@ 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
|
||||
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
|
||||
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;
|
||||
# ignore to avoid confusion.
|
||||
subtests[name] = None
|
||||
else:
|
||||
subtests[name] = size
|
||||
for name in subtests:
|
||||
if subtests[name] is not None:
|
||||
self.info('Size of %s: %s bytes' % (name,
|
||||
|
|
Загрузка…
Ссылка в новой задаче