Exemplo n.º 1
0
 def _ValidateIsConfigUpdatable(
     self, execute_job=False, dependency=None, platform=None):
   self._ValidateIsConfigWritable()
   if self._IsDirty() and execute_job:
     raise exceptions.ReadWriteError(
         'A change has already been made to this config. Either call without'
         'using the execute_job option or first call ExecuteUpdateJobs().')
   if dependency and not self._config_data.get(dependency):
     raise ValueError('Cannot update information because dependency %s does '
                      'not exist.' % dependency)
   if platform and not self._GetPlatformData(dependency, platform):
     raise ValueError('No dependency info is available for the given '
                      'dependency: %s' % dependency)
Exemplo n.º 2
0
 def _ValidateIsConfigWritable(self):
   if not self._writable:
     raise exceptions.ReadWriteError(
         'Trying to update the information from a read-only config. '
         'File for config: %s' % self._config_path)
Exemplo n.º 3
0
  def IterDependencyInfo(self):
    """ Yields a DependencyInfo for each dependency/platform pair.

    Raises:
        ReadWriteError: If called when the config is writable.
        ValueError: If any of the dependencies contain partial information for
            downloading from cloud_storage. (See dependency_info.py)
    """
    if self._writable:
      raise exceptions.ReadWriteError(
          'Trying to read dependency info from a  writable config. File for '
          'config: %s' % self._config_path)
    base_path = os.path.dirname(self._config_path)
    for dependency in self._config_data:
      dependency_dict = self._config_data.get(dependency)
      platforms_dict = dependency_dict.get('file_info', {})
      for platform in platforms_dict:
        platform_info = platforms_dict.get(platform)

        local_info = None
        local_paths = platform_info.get('local_paths', [])
        if local_paths:
          paths = []
          for path in local_paths:
            path = self._FormatPath(path)
            paths.append(os.path.abspath(os.path.join(base_path, path)))
          local_info = local_path_info.LocalPathInfo(paths)

        cs_info = None
        cs_bucket = dependency_dict.get('cloud_storage_bucket')
        cs_base_folder = dependency_dict.get('cloud_storage_base_folder', '')
        download_path = platform_info.get('download_path')
        if download_path:
          download_path = self._FormatPath(download_path)
          download_path = os.path.abspath(
              os.path.join(base_path, download_path))

          cs_hash = platform_info.get('cloud_storage_hash')
          if not cs_hash:
            raise exceptions.ConfigError(
                'Dependency %s has cloud storage info on platform %s, but is '
                'missing a cloud storage hash.', dependency, platform)
          cs_remote_path = self._CloudStorageRemotePath(
              dependency, cs_hash, cs_base_folder)
          version_in_cs = platform_info.get('version_in_cs')

          zip_info = None
          path_within_archive = platform_info.get('path_within_archive')
          if path_within_archive:
            unzip_path = os.path.abspath(
                os.path.join(os.path.dirname(download_path),
                             '%s_%s_%s' % (dependency, platform, cs_hash)))
            stale_unzip_path_glob = os.path.abspath(
                os.path.join(os.path.dirname(download_path),
                             '%s_%s_%s' % (dependency, platform,
                                           '[0-9a-f]' * 40)))
            zip_info = archive_info.ArchiveInfo(
                download_path, unzip_path, path_within_archive,
                stale_unzip_path_glob)

          cs_info = cloud_storage_info.CloudStorageInfo(
              cs_bucket, cs_hash, download_path, cs_remote_path,
              version_in_cs=version_in_cs, archive_info=zip_info)

        dep_info = dependency_info.DependencyInfo(
            dependency, platform, self._config_path,
            local_path_info=local_info, cloud_storage_info=cs_info)
        yield dep_info