def _ValidateIsConfigUpdatable(self, execute_job=False, dependency=None, platform=None): self._ValidateIsConfigWritable() if self._is_dirty 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)
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)
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))) zip_info = archive_info.ArchiveInfo( download_path, unzip_path, path_within_archive) 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
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) cs_bucket = dependency_dict.get('cloud_storage_bucket') cs_base_folder = dependency_dict.get('cloud_storage_base_folder', '') platforms_dict = dependency_dict.get('file_info', {}) for platform in platforms_dict: platform_info = platforms_dict.get(platform) 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_paths = paths download_path = platform_info.get('download_path', None) if download_path: download_path = self._FormatPath(download_path) download_path = os.path.abspath( os.path.join(base_path, download_path)) cs_remote_path = None cs_hash = platform_info.get('cloud_storage_hash', None) if cs_hash: cs_remote_file = '%s_%s' % (dependency, cs_hash) cs_remote_path = cs_remote_file if not cs_base_folder else ( '%s/%s' % (cs_base_folder, cs_remote_file)) version_in_cs = platform_info.get('version_in_cs', None) path_within_archive = platform_info.get( 'path_within_archive', None) if any([ download_path, cs_remote_path, cs_hash, version_in_cs, path_within_archive ]): dep_info = dependency_info.DependencyInfo( dependency, platform, self._config_path, cs_bucket=cs_bucket, cs_remote_path=cs_remote_path, download_path=download_path, cs_hash=cs_hash, version_in_cs=version_in_cs, path_within_archive=path_within_archive, local_paths=local_paths) else: dep_info = dependency_info.DependencyInfo( dependency, platform, self._config_path, local_paths=local_paths) yield dep_info