示例#1
0
文件: cache.py 项目: leo-s-z/glazier
  def CacheFromLine(self, line: Text,
                    build_info: 'buildinfo.BuildInfo') -> Optional[Text]:
    """Downloads any files in the command line and replaces with the local path.

    Args:
      line: the command line to process as a string
      build_info: the current build information

    Returns:
      the final command line as a string; None on error

    Raises:
      CacheError: unable to download a file to the local cache
    """
    match = self._FindDownload(line)
    while match:
      dl = download.Transform(match, build_info)
      if download.IsRemote(dl):
        destination = self._DestinationPath(build_info.CachePath(), dl)
        try:
          self._downloader.DownloadFile(dl, destination)
        except download.DownloadError as e:
          self._downloader.PrintDebugInfo()
          raise CacheError('Unable to download required file %s: %s' % (dl, e))
      else:  # bypass download for local files
        destination = dl
      line = line.replace(match, destination)
      match = self._FindDownload(line)
    return line
示例#2
0
 def Run(self):
   downloader = download.Download()
   for arg in self._args:
     src = arg[0]
     dst = arg[1]
     full_url = download.Transform(src, self._build_info)
     # support legacy untagged short filenames
     if not (download.IsRemote(full_url) or download.IsLocal(full_url)):
       full_url = download.PathCompile(self._build_info, file_name=full_url)
     try:
       file_util.CreateDirectories(dst)
     except file_util.Error as e:
       raise ActionError('Could not create destination directory %s. %s' %
                         (dst, e))
     try:
       downloader.DownloadFile(full_url, dst, show_progress=True)
     except download.DownloadError as e:
       downloader.PrintDebugInfo()
       raise ActionError('Transfer error while downloading %s: %s' %
                         (full_url, str(e)))
     if len(arg) > 2 and arg[2]:
       logging.info('Verifying SHA256 hash for %s.', dst)
       hash_ok = downloader.VerifyShaHash(dst, arg[2])
       if not hash_ok:
         raise ActionError('SHA256 hash for %s was incorrect.' % dst)
示例#3
0
 def testIsRemote(self):
   self.assertTrue(download.IsRemote('http://glazier.example.com'))
   self.assertTrue(download.IsRemote('https://glazier.example.com'))
   self.assertTrue(download.IsRemote('HTTPS://glazier.example.com'))
   self.assertFalse(download.IsRemote('String with HTTP in it.'))
   self.assertFalse(download.IsRemote('C:/glazier'))