зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1284533 - Re-add custom ZipFile extraction to firefox-ui-tests. r=automatedtester
With bug 1276895 our custom code to unzip test archives has been removed. But we still need it because our Windows slave nodes in Jenkins do not have the unzip command installed. This code can finally removed once bug 1258539 is fixed. MozReview-Commit-ID: 4WbFrQ524l1 --HG-- extra : rebase_source : 94d7c782285827bfaf347a1e44a6ce952aec6978
This commit is contained in:
Родитель
48d31f6206
Коммит
86bc5d3034
|
@ -299,6 +299,53 @@ class FirefoxUITests(TestingMixin, VCSToolsScript):
|
|||
env=self.query_env(),
|
||||
)
|
||||
|
||||
def download_unzip(self, url, parent_dir, target_unzip_dirs=None, halt_on_failure=True):
|
||||
"""Overwritten method from BaseScript until bug 1258539 is fixed.
|
||||
|
||||
The downloaded file will always be saved to the working directory and is not getting
|
||||
deleted after extracting.
|
||||
|
||||
Args:
|
||||
url (str): URL where the file to be downloaded is located.
|
||||
parent_dir (str): directory where the downloaded file will
|
||||
be extracted to.
|
||||
target_unzip_dirs (list, optional): directories inside the zip file to extract.
|
||||
Defaults to `None`.
|
||||
halt_on_failure (bool, optional): whether or not to redefine the
|
||||
log level as `FATAL` on errors. Defaults to True.
|
||||
|
||||
"""
|
||||
import fnmatch
|
||||
import itertools
|
||||
import functools
|
||||
import zipfile
|
||||
|
||||
def _filter_entries(namelist):
|
||||
"""Filter entries of the archive based on the specified list of extract_dirs."""
|
||||
filter_partial = functools.partial(fnmatch.filter, namelist)
|
||||
for entry in itertools.chain(*map(filter_partial, target_unzip_dirs or ['*'])):
|
||||
yield entry
|
||||
|
||||
dirs = self.query_abs_dirs()
|
||||
zip = self.download_file(url, parent_dir=dirs['abs_work_dir'],
|
||||
error_level=FATAL)
|
||||
|
||||
try:
|
||||
self.info('Using ZipFile to extract {0} to {1}'.format(zip, parent_dir))
|
||||
with zipfile.ZipFile(zip) as bundle:
|
||||
for entry in _filter_entries(bundle.namelist()):
|
||||
bundle.extract(entry, path=parent_dir)
|
||||
|
||||
# ZipFile doesn't preserve permissions: http://bugs.python.org/issue15795
|
||||
fname = os.path.realpath(os.path.join(parent_dir, entry))
|
||||
mode = bundle.getinfo(entry).external_attr >> 16 & 0x1FF
|
||||
# Only set permissions if attributes are available.
|
||||
if mode:
|
||||
os.chmod(fname, mode)
|
||||
except zipfile.BadZipfile as e:
|
||||
self.log('{0} ({1})'.format(e.message, zip),
|
||||
level=FATAL, exit_code=2)
|
||||
|
||||
|
||||
class FirefoxUIFunctionalTests(FirefoxUITests):
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче