def testMain(self):
   """Test that the main function works."""
   options = mox.MockObject(object)
   old_binhost = 'http://prebuilt/1'
   options.previous_binhost_url = [old_binhost]
   options.board = 'x86-foo'
   options.profile = None
   target = prebuilt.BuildTarget(options.board, options.profile)
   options.build_path = '/trunk'
   options.debug = False
   options.private = True
   options.packages = []
   options.sync_host = True
   options.git_sync = True
   options.upload_board_tarball = True
   options.prepackaged_tarball = None
   options.toolchain_tarballs = []
   options.toolchain_upload_path = ''
   options.upload = 'gs://upload/'
   options.binhost_base_url = options.upload
   options.prepend_version = True
   options.set_version = None
   options.skip_upload = False
   options.filters = True
   options.key = 'PORTAGE_BINHOST'
   options.binhost_conf_dir = 'foo'
   options.sync_binhost_conf = True
   options.slave_targets = [prebuilt.BuildTarget('x86-bar', 'aura')]
   self.mox.StubOutWithMock(prebuilt, 'ParseOptions')
   prebuilt.ParseOptions().AndReturn(tuple([options, target]))
   self.mox.StubOutWithMock(binpkg, 'GrabRemotePackageIndex')
   binpkg.GrabRemotePackageIndex(old_binhost).AndReturn(True)
   self.mox.StubOutWithMock(prebuilt.PrebuiltUploader, '__init__')
   self.mox.StubOutWithMock(prebuilt, 'GetBoardOverlay')
   fake_overlay_path = '/fake_path'
   prebuilt.GetBoardOverlay(
       options.build_path, options.board).AndReturn(fake_overlay_path)
   expected_gs_acl_path = os.path.join(fake_overlay_path,
                                       prebuilt._GOOGLESTORAGE_ACL_FILE)
   prebuilt.PrebuiltUploader.__init__(options.upload, expected_gs_acl_path,
                                      options.upload, mox.IgnoreArg(),
                                      options.build_path, options.packages,
                                      False, options.binhost_conf_dir, False,
                                      target, options.slave_targets)
   self.mox.StubOutWithMock(prebuilt.PrebuiltUploader, 'SyncHostPrebuilts')
   prebuilt.PrebuiltUploader.SyncHostPrebuilts(mox.IgnoreArg(), options.key,
       options.git_sync, options.sync_binhost_conf)
   self.mox.StubOutWithMock(prebuilt.PrebuiltUploader, 'SyncBoardPrebuilts')
   prebuilt.PrebuiltUploader.SyncBoardPrebuilts(
       mox.IgnoreArg(), options.key, options.git_sync,
       options.sync_binhost_conf, options.upload_board_tarball, None, [], '')
   self.mox.ReplayAll()
   prebuilt.main([])
def _GrabAllRemotePackageIndexes(binhost_urls):
  """Grab all of the packages files associated with a list of binhost_urls.

  Args:
    binhost_urls: The URLs for the directories containing the Packages files we
                  want to grab.

  Returns:
    A list of PackageIndex objects.
  """
  pkg_indexes = []
  for url in binhost_urls:
    pkg_index = binpkg.GrabRemotePackageIndex(url)
    if pkg_index:
      pkg_indexes.append(pkg_index)
  return pkg_indexes
Example #3
0
def GetPackageIndex(binhost, binhost_cache=None):
    """Get the packages index for |binhost|.

  If a cache is provided, use it to a cache remote packages index.

  Args:
    binhost: a portage binhost, local, google storage or http.
    binhost_cache: a cache for the remote packages index.

  Returns:
    A PackageIndex object.
  """
    key = binhost.split('://')[-1]
    key = key.rstrip('/').split('/')

    if binhost_cache and binhost_cache.Lookup(key).Exists():
        with open(binhost_cache.Lookup(key).path) as f:
            return pickle.load(f)

    pkgindex = binpkg.GrabRemotePackageIndex(binhost, quiet=True)
    if pkgindex and binhost_cache:
        # Only cache remote binhosts as local binhosts can change.
        with tempfile.NamedTemporaryFile(delete=False) as temp_file:
            pickle.dump(pkgindex, temp_file)
            temp_file.file.close()
            binhost_cache.Lookup(key).Assign(temp_file.name)
    elif pkgindex is None:
        urlparts = urllib.parse.urlsplit(binhost)
        if urlparts.scheme not in ('file', ''):
            # Don't fail the build on network errors. Print a warning message and
            # continue.
            logging.warning('Could not get package index %s', binhost)
            return None

        binhost = urlparts.path
        if not os.path.isdir(binhost):
            raise ValueError('unrecognized binhost format for %s.')
        pkgindex = binpkg.GrabLocalPackageIndex(binhost)

    return pkgindex