def testPageMarker(self): resource = [[1, 2, 3], ['a', 'b', 'c'], resource_printer_base.PageMarker(), [7, 8, 9], ['x', 'y', 'z']] expected = [[1, 2, 3], ['a', 'b', 'c'], 'Page', [7, 8, 9], ['x', 'y', 'z'], 'Finish'] printer = MockPrinter() printer.Print(resource) actual = printer.GetTestOutput() self.assertEqual(expected, actual)
def testIsResourceMarker(self): resource = [[1, 2, 3], ['a', 'b', 'c'], resource_printer_base.PageMarker(), [7, 8, 9], ['x', 'y', 'z'], resource_printer_base.FinishMarker()] expected = [False, False, True, False, False, True] actual = [] for record in resource: actual.append(resource_printer_base.IsResourceMarker(record)) self.assertEqual(expected, actual)
def Tap(self, resource): """Injects a PageMarker if the current page limit has been reached. Args: resource: The resource to limit. Returns: TapInjector(PageMarker) if the page current page limit has been reached, otherwise True to retain the current resource. """ if resource_printer_base.IsResourceMarker(resource): return True self._count += 1 if self._count > self._page_size: self._count = 0 return peek_iterable.TapInjector(resource_printer_base.PageMarker()) return True
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. Yields: Subscription paths that match the regular expression in args.name_filter. Raises: sdk_ex.HttpException if there is an error with the regular expression syntax. """ msgs = self.context['pubsub_msgs'] pubsub = self.context['pubsub'] page_token = None if args.page_size: page_size = min(args.page_size, util.MAX_LIST_RESULTS) else: page_size = None if not args.filter and args.limit: page_size = min(args.limit, page_size or util.MAX_LIST_RESULTS) try: while True: list_subscriptions_req = msgs.PubsubProjectsSubscriptionsListRequest( project=util.ProjectFormat(), pageToken=page_token, pageSize=page_size) list_subscriptions_response = pubsub.projects_subscriptions.List( list_subscriptions_req) for subscription in list_subscriptions_response.subscriptions: yield SubscriptionDict(subscription) page_token = list_subscriptions_response.nextPageToken if not page_token: break yield resource_printer_base.PageMarker() except re.error as e: raise sdk_ex.HttpException(str(e))
def Run(self, args): """This is what gets called when the user runs this command. Args: args: an argparse namespace. All the arguments that were provided to this command invocation. Yields: Subscriptions paths that match the regular expression in args.name_filter. """ msgs = self.context['pubsub_msgs'] pubsub = self.context['pubsub'] page_size = None page_token = None if args.page_size: page_size = min(args.page_size, util.MAX_LIST_RESULTS) if not args.filter and args.limit: page_size = min(args.limit, page_size or util.MAX_LIST_RESULTS) while True: list_subscriptions_req = ( msgs.PubsubProjectsTopicsSubscriptionsListRequest( topic=util.TopicFormat(args.topic), pageSize=page_size, pageToken=page_token)) list_subscriptions_result = pubsub.projects_topics_subscriptions.List( list_subscriptions_req) for subscription in list_subscriptions_result.subscriptions: yield TopicSubscriptionDict(subscription) page_token = list_subscriptions_result.nextPageToken if not page_token: break yield resource_printer_base.PageMarker()