示例#1
0
  def UpdateLatestFilesForBot(self, config, versions):
    """Update the LATEST files, for a given bot, in Google Storage.

    Args:
      config: The builder config to update.
      versions: Versions of ChromeOS to look at, sorted in descending order.
    """
    base_url = archive_lib.GetBaseUploadURI(config)
    acl = archive_lib.GetUploadACL(config)
    latest_url = None
    # gs.GSContext skips over all commands (including read-only checks)
    # when dry_run is True, so we have to create two context objects.
    # TODO(davidjames): Fix this.
    gs_ctx = gs.GSContext()
    copy_ctx = gs.GSContext(dry_run=self._dryrun)
    for version in reversed(versions):
      url = os.path.join(base_url, 'LATEST-%s' % version)
      found = gs_ctx.Exists(url, print_cmd=False)
      if not found and latest_url:
        try:
          copy_ctx.Copy(latest_url, url, version=0, acl=acl)
          logging.info('Copied %s -> %s', latest_url, url)
        except gs.GSContextPreconditionFailed:
          found = True

      if found:
        logging.info('Found %s', url)
        latest_url = url
示例#2
0
    def __init__(self,
                 cache_dir,
                 board,
                 clear_cache=False,
                 chrome_src=None,
                 sdk_path=None,
                 toolchain_path=None,
                 silent=False,
                 use_external_config=None):
        """Initialize the class.

    Args:
      cache_dir: The toplevel cache dir to use.
      board: The board to manage the SDK for.
      clear_cache: Clears the sdk cache during __init__.
      chrome_src: The location of the chrome checkout.  If unspecified, the
        cwd is presumed to be within a chrome checkout.
      sdk_path: The path (whether a local directory or a gs:// path) to fetch
        SDK components from.
      toolchain_path: The path (whether a local directory or a gs:// path) to
        fetch toolchain components from.
      silent: If set, the fetcher prints less output.
      use_external_config: When identifying the configuration for a board,
        force usage of the external configuration if both external and internal
        are available.
    """
        site_config = config_lib.GetConfig()

        self.cache_base = os.path.join(cache_dir, COMMAND_NAME)
        if clear_cache:
            logging.warning('Clearing the SDK cache.')
            osutils.RmDir(self.cache_base, ignore_missing=True)
        self.tarball_cache = cache.TarballCache(
            os.path.join(self.cache_base, self.TARBALL_CACHE))
        self.misc_cache = cache.DiskCache(
            os.path.join(self.cache_base, self.MISC_CACHE))
        self.board = board
        self.config = site_config.FindCanonicalConfigForBoard(
            board, allow_internal=not use_external_config)
        self.gs_base = archive_lib.GetBaseUploadURI(self.config)
        self.clear_cache = clear_cache
        self.chrome_src = chrome_src
        self.sdk_path = sdk_path
        self.toolchain_path = toolchain_path
        self.silent = silent

        # For external configs, there is no need to run 'gsutil config', because
        # the necessary files are all accessible to anonymous users.
        internal = self.config['internal']
        self.gs_ctx = gs.GSContext(cache_dir=cache_dir, init_boto=internal)

        if self.sdk_path is None:
            self.sdk_path = os.environ.get(self.SDK_PATH_ENV)

        if self.toolchain_path is None:
            self.toolchain_path = 'gs://%s' % constants.SDK_GS_BUCKET
示例#3
0
 def _GetBaseUploadURI(self, *args, **kwargs):
     """Test GetBaseUploadURI with archive_base and no bot_id."""
     return archive_lib.GetBaseUploadURI(self.cfg, *args, **kwargs)