def ListBreakpoints(self, location_regexp=None, resource_ids=None, include_all_users=False, include_inactive=False, restrict_to_type=None): """Returns all breakpoints matching the given IDs or patterns. Lists all breakpoints for this debuggee, and returns every breakpoint where the location field contains the given pattern or the ID is exactly equal to the pattern (there can be at most one breakpoint matching by ID). Args: location_regexp: A list of regular expressions to compare against the location ('path:line') of the breakpoints. If both location_regexp and resource_ids are empty or None, all breakpoints will be returned. resource_ids: Zero or more resource IDs in the form expected by the resource parser. These breakpoints will be retrieved regardless of the include_all_users or include_inactive flags include_all_users: If true, search breakpoints created by all users. include_inactive: If true, search breakpoints that are in the final state. This option controls whether regular expressions can match inactive breakpoints. If an object is specified by ID, it will be returned whether or not this flag is set. restrict_to_type: An optional breakpoint type (LOGPOINT_TYPE or SNAPSHOT_TYPE) Returns: A list of all matching breakpoints. Raises: InvalidLocationException if a regular expression is not valid. """ resource_ids = resource_ids or [] location_regexp = location_regexp or [] ids = set([ self._resource_parser.Parse( r, params={ 'debuggeeId': self.target_id }, collection='clouddebugger.debugger.debuggees.breakpoints'). Name() for r in resource_ids ]) patterns = [] for r in location_regexp: try: patterns.append(re.compile(r'^(.*/)?(' + r + ')$')) except re.error as e: raise errors.InvalidLocationException( 'The location pattern "{0}" is not a valid Python regular ' 'expression: {1}'.format(r, e)) request = (self._debug_messages. ClouddebuggerDebuggerDebuggeesBreakpointsListRequest( debuggeeId=self.target_id, includeAllUsers=include_all_users, includeInactive=include_inactive or bool(ids), clientVersion=self.CLIENT_VERSION)) try: response = self._debug_client.debugger_debuggees_breakpoints.List( request) except apitools_exceptions.HttpError as error: raise errors.UnknownHttpError(error) if not patterns and not ids: return self._FilteredDictListWithInfo(response.breakpoints, restrict_to_type) if include_inactive: # Match everything (including inactive breakpoints) against all ids and # patterns. result = [ bp for bp in response.breakpoints if _BreakpointMatchesIdOrRegexp(bp, ids, patterns) ] else: # Return everything that is listed by ID, plus every breakpoint that # is not inactive (i.e. isFinalState is false) which matches any pattern. # Breakpoints that are inactive should not be matched against the # patterns. result = [ bp for bp in response.breakpoints if _BreakpointMatchesIdOrRegexp( bp, ids, [] if bp.isFinalState else patterns) ] # Check if any ids were missing, and fetch them individually. This can # happen if an ID for another user's breakpoint was specified, but the # all_users flag was false. This code will also raise an error for any # missing IDs. missing_ids = ids - set([bp.id for bp in result]) if missing_ids: raise errors.BreakpointNotFoundError( missing_ids, self._BreakpointDescription(restrict_to_type)) # Verify that all patterns matched at least one breakpoint. for p in patterns: if not [ bp for bp in result if _BreakpointMatchesIdOrRegexp(bp, [], [p]) ]: raise errors.NoMatchError( self._BreakpointDescription(restrict_to_type), p.pattern) return self._FilteredDictListWithInfo(result, restrict_to_type)
def ListBreakpoints(self, location_regexp_or_ids=None, include_all_users=False, include_inactive=False, restrict_to_type=None): """Returns all breakpoints matching the given IDs or patterns. Lists all breakpoints for this debuggee, and returns every breakpoint where the location field contains the given pattern or the ID is exactly equal to the pattern (there can be at most one breakpoint matching by ID). Args: location_regexp_or_ids: A list of regular expressions or breakpoint IDs. Regular expressions will be compared against the location ('path:line') of the breakpoints. Exact breakpoint IDs will be retrieved regardless of the include_all_users or include_inactive flags. If empty or None, all breakpoints will be returned. include_all_users: If true, search breakpoints created by all users. include_inactive: If true, search breakpoints that are in the final state. This option controls whether regular expressions can match inactive breakpoints. If an object is specified by ID, it will be returned whether or not this flag is set. restrict_to_type: An optional breakpoint type (LOGPOINT_TYPE or SNAPSHOT_TYPE) Returns: A list of all matching breakpoints. Raises: InvalidArgumentException if a regular expression is not valid. """ self._CheckClient() # Try using the resource parser on every argument, and save the resulting # (argument, resource) pairs parsed_args = [ (arg, self.TryParse( arg, params={'debuggeeId': self.target_id}, collection='clouddebugger.debugger.debuggees.breakpoints')) for arg in location_regexp_or_ids or [] ] # Pass through the results and find anything that looks like a breakpoint # ID. This will include things that looked like an ID originally, plus # any IDs the resource parser detected. ids = set([ r.Name() for _, r in parsed_args if r and _BREAKPOINT_ID_PATTERN.match(r.Name()) ]) # Treat everything that's not an ID (i.e. everything that either wasn't # parsable as a resource or whose name doesn't look like an ID) as a reqular # expression to be checked against the breakpoint location. Tweak the RE # so it will also match just the trailing file name component(s) + line # number, since the server may chose to return the full path. try: patterns = [ re.compile(r'^(.*/)?(' + arg + ')$') for arg, r in parsed_args if not r or (r.Name() not in ids) ] except re.error as e: raise exceptions.InvalidArgumentException('LOCATION-REGEXP', str(e)) request = (self._debug_messages. ClouddebuggerDebuggerDebuggeesBreakpointsListRequest( debuggeeId=self.target_id, includeAllUsers=include_all_users, includeInactive=include_inactive or bool(ids), clientVersion=self.CLIENT_VERSION)) try: response = self._debug_client.debugger_debuggees_breakpoints.List( request) except apitools_exceptions.HttpError as error: raise errors.UnknownHttpError(error) if not location_regexp_or_ids: return self._FilteredDictListWithInfo(response.breakpoints, restrict_to_type) if include_inactive: # Match everything (including inactive breakpoints) against all ids and # patterns. result = [ bp for bp in response.breakpoints if _BreakpointMatchesIdOrRegexp(bp, ids, patterns) ] else: # Return everything that is listed by ID, plus every breakpoint that # is not inactive (i.e. isFinalState is false) which matches any pattern. # Breakpoints that are inactive should not be matched against the # patterns. result = [ bp for bp in response.breakpoints if _BreakpointMatchesIdOrRegexp( bp, ids, [] if bp.isFinalState else patterns) ] # Check if any ids were missing, and fetch them individually. This can # happen if an ID for another user's breakpoint was specified, but the # all_users flag was false. This code will also raise an error for any # missing IDs. missing_ids = ids - set([bp.id for bp in result]) if missing_ids: raise errors.BreakpointNotFoundError( missing_ids, self._BreakpointDescription(restrict_to_type)) # Verify that all patterns matched at least one breakpoint. for p in patterns: if not [ bp for bp in result if _BreakpointMatchesIdOrRegexp(bp, [], [p]) ]: raise errors.NoMatchError( self._BreakpointDescription(restrict_to_type), p.pattern) return self._FilteredDictListWithInfo(result, restrict_to_type)