mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 15:25:52 +00:00
Bug 1216817 - Part 1: Add install_callback to artifacts. r=gps
--HG-- extra : commitid : 7Qjl1R0EAl9 extra : rebase_source : c34a581f6f513dde939e8e079e2b9676ce121f92
This commit is contained in:
parent
a3f03c1b51
commit
137016aacb
@ -332,36 +332,38 @@ class Artifacts(object):
|
|||||||
if self._log:
|
if self._log:
|
||||||
self._log(*args, **kwargs)
|
self._log(*args, **kwargs)
|
||||||
|
|
||||||
def install_from_file(self, filename, distdir):
|
def install_from_file(self, filename, distdir, install_callback=None):
|
||||||
self.log(logging.INFO, 'artifact',
|
self.log(logging.INFO, 'artifact',
|
||||||
{'filename': filename},
|
{'filename': filename},
|
||||||
'Installing from {filename}')
|
'Installing from {filename}')
|
||||||
|
|
||||||
# Copy all .so files to dist/bin, avoiding modification where possible.
|
# Copy all .so files to dist/bin, avoiding modification where possible.
|
||||||
ensureParentDir(os.path.join(distdir, 'bin', '.dummy'))
|
ensureParentDir(mozpath.join(distdir, 'bin', '.dummy'))
|
||||||
|
|
||||||
with zipfile.ZipFile(filename) as zf:
|
with zipfile.ZipFile(filename) as zf:
|
||||||
for info in zf.infolist():
|
for info in zf.infolist():
|
||||||
if not info.filename.endswith('.so'):
|
if not info.filename.endswith('.so'):
|
||||||
continue
|
continue
|
||||||
n = os.path.join(distdir, 'bin', os.path.basename(info.filename))
|
n = mozpath.join(distdir, 'bin', os.path.basename(info.filename))
|
||||||
fh = FileAvoidWrite(n, mode='r')
|
fh = FileAvoidWrite(n, mode='r')
|
||||||
shutil.copyfileobj(zf.open(info), fh)
|
shutil.copyfileobj(zf.open(info), fh)
|
||||||
file_existed, file_updated = fh.close()
|
file_existed, file_updated = fh.close()
|
||||||
self.log(logging.INFO, 'artifact',
|
self.log(logging.INFO, 'artifact',
|
||||||
{'updating': 'Updating' if file_updated else 'Not updating', 'filename': n},
|
{'updating': 'Updating' if file_updated else 'Not updating', 'filename': n},
|
||||||
'{updating} {filename}')
|
'{updating} {filename}')
|
||||||
|
if install_callback:
|
||||||
|
install_callback(os.path.basename(info.filename), file_existed, file_updated)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def install_from_url(self, url, distdir):
|
def install_from_url(self, url, distdir, install_callback=None):
|
||||||
self.log(logging.INFO, 'artifact',
|
self.log(logging.INFO, 'artifact',
|
||||||
{'url': url},
|
{'url': url},
|
||||||
'Installing from {url}')
|
'Installing from {url}')
|
||||||
with self._artifact_cache as artifact_cache: # The with block handles persistence.
|
with self._artifact_cache as artifact_cache: # The with block handles persistence.
|
||||||
filename = artifact_cache.fetch(url)
|
filename = artifact_cache.fetch(url)
|
||||||
return self.install_from_file(filename, distdir)
|
return self.install_from_file(filename, distdir, install_callback=install_callback)
|
||||||
|
|
||||||
def install_from_hg(self, revset, distdir):
|
def install_from_hg(self, revset, distdir, install_callback=None):
|
||||||
if not revset:
|
if not revset:
|
||||||
revset = '.'
|
revset = '.'
|
||||||
if len(revset) != 40:
|
if len(revset) != 40:
|
||||||
@ -389,19 +391,27 @@ class Artifacts(object):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
if url:
|
if url:
|
||||||
return self.install_from_url(url, distdir)
|
return self.install_from_url(url, distdir, install_callback=install_callback)
|
||||||
self.log(logging.ERROR, 'artifact',
|
self.log(logging.ERROR, 'artifact',
|
||||||
{'revset': revset},
|
{'revset': revset},
|
||||||
'No built artifacts for {revset} found.')
|
'No built artifacts for {revset} found.')
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def install_from(self, source, distdir):
|
def install_from(self, source, distdir, install_callback=None):
|
||||||
|
"""Install artifacts from a ``source`` into the given ``distdir``.
|
||||||
|
|
||||||
|
If ``callback`` is given, it is called once with arguments ``(path,
|
||||||
|
existed, updated)``, where ``path`` is the file path written relative
|
||||||
|
to ``distdir``; ``existed`` is a boolean indicating whether the file
|
||||||
|
existed; and ``updated`` is a boolean indicating whether the file was
|
||||||
|
updated.
|
||||||
|
"""
|
||||||
if source and os.path.isfile(source):
|
if source and os.path.isfile(source):
|
||||||
return self.install_from_file(source, distdir)
|
return self.install_from_file(source, distdir, install_callback=install_callback)
|
||||||
elif source and urlparse.urlparse(source).scheme:
|
elif source and urlparse.urlparse(source).scheme:
|
||||||
return self.install_from_url(source, distdir)
|
return self.install_from_url(source, distdir, install_callback=install_callback)
|
||||||
else:
|
else:
|
||||||
return self.install_from_hg(source, distdir)
|
return self.install_from_hg(source, distdir, install_callback=install_callback)
|
||||||
|
|
||||||
def print_last(self):
|
def print_last(self):
|
||||||
self.log(logging.INFO, 'artifact',
|
self.log(logging.INFO, 'artifact',
|
||||||
|
Loading…
Reference in New Issue
Block a user