def Wait(self, name, is_regex_name, timeout): """Verifies the local artifact exists and returns the appropriate names. Args: name: Name to look at. is_regex_name: True if the name is a regex pattern. timeout: How long to wait for the artifact to become available. Returns: A list of names that match. Raises: ArtifactDownloadError: An error occurred when obtaining artifact. """ artifacts = android_build.BuildAccessor.GetArtifacts( branch=self.branch, build_id=self.build_id, target=self.target) names = [] for artifact_name in [a['name'] for a in artifacts]: match = (re.match(name, artifact_name) if is_regex_name else name == artifact_name) if match: names.append(artifact_name) if not names: raise build_artifact.ArtifactDownloadError( 'No artifact found with given name: %s for %s-%s. All available ' 'artifacts are: %s' % (name, self.target, self.build_id, ','.join([a['name'] for a in artifacts]))) return names
def Wait(self, name, is_regex_name, timeout): """Verifies the local artifact exists and returns the appropriate names. Args: name: Name to look at. is_regex_name: True if the name is a regex pattern. timeout: How long to wait for the artifact to become available. Returns: A list of names that match. Raises: ArtifactDownloadError: An error occurred when obtaining artifact. """ if is_regex_name: filter_re = re.compile(name) artifacts = [ f for f in os.listdir(self.source_path) if filter_re.match(f) ] else: glob_search = glob.glob(os.path.join(self.source_path, name)) artifacts = [os.path.basename(g) for g in glob_search] if not artifacts: raise build_artifact.ArtifactDownloadError( 'Artifact %s not found at %s(regex_match: %s)' % (name, self.source_path, is_regex_name)) return artifacts
def _TranslateSignedGSUrl(self, build_id, channel=None): """Translate the GS URL to be able to find signed images. Args: build_id: Path to the image or update directory on the devserver or in Google Storage. e.g. 'x86-generic/R26-4000.0.0' channel: The channel for the image. If none, it tries to guess it in order of stability. Returns: The GS URL for the directory where the signed image can be found. Raises: build_artifact.ArtifactDownloadError: If we failed to download the artifact. """ match = re.match(r'^([^/]+?)(?:-release)?/R\d+-(.*)$', build_id) channels = [] if channel: channels.append(channel) else: # Attempt to enumerate all channels, in order of stability. channels.extend(devserver_constants.CHANNELS[::-1]) for c in channels: image_dir = devserver_constants.GS_CHANNEL_DIR % { 'channel': c, 'board': match.group(1), } gs_url = os.path.join(image_dir, match.group(2)) try: self._LS(gs_url) return gs_url except gs.GSNoSuchKey: continue raise build_artifact.ArtifactDownloadError( 'Could not find signed image URL for %s in Google Storage' % build_id)
def Wait(self, name, is_regex_name, alt_name, timeout): """Waits for artifact to exist and returns the appropriate names. Args: name: Name to look at. is_regex_name: True if the name is a regex pattern. alt_name: Name to use if we don't have list permission. timeout: How long to wait for the artifact to become available. Returns: A list of names that match. Raises: ArtifactDownloadError: An error occurred when obtaining artifact. """ names = [] try: names = self._ctx.GetGsNamesWithWait( name, self._archive_url, timeout=timeout, is_regex_pattern=is_regex_name) except gs.GSCommandError as e: # Anonymous callers don't have list permission. Instead, # construct the alt name and attempt to download that. if common_util.IsAnonymousCaller(e) and alt_name: if not isinstance(alt_name, list): alt_name = [alt_name] names = [ n.format(build=self._build, board=self._board.replace('-', '_')) for n in alt_name ] if not names: raise build_artifact.ArtifactDownloadError( 'Could not find %s in Google Storage at %s' % (name, self._archive_url)) return names
def Wait(self, name, is_regex_name, timeout): """Waits for artifact to exist and returns the appropriate names. Args: name: Name to look at. is_regex_name: True if the name is a regex pattern. timeout: How long to wait for the artifact to become available. Returns: A list of names that match. Raises: ArtifactDownloadError: An error occurred when obtaining artifact. """ names = self._ctx.GetGsNamesWithWait(name, self._archive_url, timeout=timeout, is_regex_pattern=is_regex_name) if not names: raise build_artifact.ArtifactDownloadError( 'Could not find %s in Google Storage at %s' % (name, self._archive_url)) return names
def ListBuildDir(self): """List the files in the build directory. Only lists files a single level into the build directory. Includes timestamp information in the listing. Returns: A string with information about the files in the build directory. None if the build directory doesn't exist. Raises: build_artifact.ArtifactDownloadError: If the build_dir path exists but is not a directory. """ if not os.path.exists(self._build_dir): return None if not os.path.isdir(self._build_dir): raise build_artifact.ArtifactDownloadError( 'Artifacts %s improperly staged to build_dir path %s. The path is ' 'not a directory.' % (self._archive_url, self._build_dir)) ls_format = collections.namedtuple( 'ls', ['name', 'accessed', 'modified', 'size']) output_format = ('Name: %(name)s Accessed: %(accessed)s ' 'Modified: %(modified)s Size: %(size)s bytes.\n') build_dir_info = 'Listing contents of :%s \n' % self._build_dir for file_name in os.listdir(self._build_dir): file_path = os.path.join(self._build_dir, file_name) file_info = os.stat(file_path) ls_info = ls_format(file_path, datetime.fromtimestamp(file_info.st_atime), datetime.fromtimestamp(file_info.st_mtime), file_info.st_size) build_dir_info += output_format % ls_info._asdict() return build_dir_info