Пример #1
0
 def _AddPageTap(self):
     """Taps a resource pager into self.resources if needed."""
     page_size = self._GetFlag('page_size')
     if page_size is None or page_size <= 0:
         return
     tap = display_taps.Pager(page_size)
     self._resources = peek_iterable.Tapper(self._resources, tap)
Пример #2
0
 def _AddFilterTap(self):
     """Taps a resource filter into self.resources if needed."""
     expression = self._GetFlag('filter')
     if not expression:
         return
     tap = display_taps.Filterer(expression, self._defaults)
     self._resources = peek_iterable.Tapper(self._resources, tap)
Пример #3
0
 def _AddLimitTap(self):
     """Taps a resource limit into self.resources if needed."""
     limit = self._GetFlag('limit')
     if limit is None or limit < 0:
         return
     tap = display_taps.Limiter(limit)
     self._resources = peek_iterable.Tapper(self._resources, tap)
Пример #4
0
 def _Slice(key):
     """Helper to add one flattened slice tap."""
     tap = display_taps.Flattener(key)
     # Apply the flatteners from left to right so the innermost flattener
     # flattens the leftmost slice. The outer flatteners can then access
     # the flattened keys to the left.
     self._resources = peek_iterable.Tapper(self._resources, tap)
Пример #5
0
    def _AddUriReplaceTap(self):
        """Taps a resource Uri replacer into self.resources if needed."""

        if not self._GetFlag('uri'):
            return

        tap = display_taps.UriReplacer(self._transform_uri)
        self._resources = peek_iterable.Tapper(self._resources, tap)
Пример #6
0
 def _AddLimitTap(self):
     """Taps a resource limit into self.resources if needed."""
     limit = _GetFlag(self._args, 'limit')
     if limit is None or limit < 0:
         return
     limiter = _Limiter(limit)
     self._resources = peek_iterable.Tapper(self._resources,
                                            limiter.LimitResource)
Пример #7
0
 def _AddFilterTap(self):
     """Taps a resource filter into self.resources if needed."""
     expression = _GetFlag(self._args, 'filter')
     if not expression:
         return
     filterer = _Filterer(expression, self._defaults)
     self._resources = peek_iterable.Tapper(self._resources,
                                            filterer.FilterResource)
Пример #8
0
    def _AddUriCacheTap(self):
        """Taps a resource Uri cache updater into self.resources if needed."""

        cache_update_op = self._command.GetUriCacheUpdateOp()
        if not cache_update_op:
            return

        if any([self._GetFlag(flag) for flag in self._CORRUPT_FLAGS]):
            return

        cacher = display_taps.UriCacher(cache_update_op, self._defaults)
        self._resources = peek_iterable.Tapper(self._resources, cacher.Tap,
                                               cacher.Done)
Пример #9
0
    def _AddUriCacheTap(self):
        """Taps a resource Uri cache updater into self.resources if needed."""

        cache_update_op = self._command.GetUriCacheUpdateOp()
        if not cache_update_op:
            return

        if any([_GetFlag(self._args, flag) for flag in self._CORRUPT_FLAGS]):
            return

        cacher = _UriCacher(cache_update_op)
        self._resources = peek_iterable.Tapper(self._resources,
                                               cacher.AddResource,
                                               cacher.Update)
Пример #10
0
    def _AddUriCacheTap(self):
        """Taps a resource Uri cache updater into self.resources if needed."""

        if not self._info or self._info.bypass_cache:
            return

        cache_update_op = self._command.GetUriCacheUpdateOp()
        if not cache_update_op:
            return

        if any([self._GetFlag(flag) for flag in self._CORRUPT_FLAGS]):
            return

        tap = display_taps.UriCacher(cache_update_op, self._transform_uri)
        self._resources = peek_iterable.Tapper(self._resources, tap)
Пример #11
0
    def _AddUriCacheTap(self):
        """Taps a resource Uri cache updater into self.resources if needed."""

        from googlecloudsdk.calliope import base  # pylint: disable=g-import-not-at-top, circular dependency

        if self._cache_updater == cache_update_ops.NoCacheUpdater:
            return

        if not self._cache_updater:
            # pylint: disable=protected-access
            if not isinstance(self._command,
                              (base.CreateCommand, base.DeleteCommand,
                               base.ListCommand, base.RestoreCommand)):
                return
            if 'AddCacheUpdater' in properties.VALUES.core.lint.Get():
                # pylint: disable=protected-access
                raise CommandNeedsAddCacheUpdater(
                    '`{}` needs a parser.display_info.AddCacheUpdater() call.'.
                    format(' '.join(self._args._GetCommand().GetPath())))
            return

        if self._legacy and (not self._info or self._info.bypass_cache):
            return
        if any([self._GetFlag(flag) for flag in self._CORRUPT_FLAGS]):
            return

        # pylint: disable=protected-access
        if isinstance(self._command,
                      (base.CreateCommand, base.RestoreCommand)):
            cache_update_op = cache_update_ops.AddToCacheOp(
                self._cache_updater)
        elif isinstance(self._command, base.DeleteCommand):
            cache_update_op = cache_update_ops.DeleteFromCacheOp(
                self._cache_updater)
        elif isinstance(self._command, base.ListCommand):
            cache_update_op = cache_update_ops.ReplaceCacheOp(
                self._cache_updater)
        else:
            raise CommandShouldntHaveAddCacheUpdater(
                'Cache updater [{}] not expected for [{}] `{}`.'.format(
                    module_util.GetModulePath(self._cache_updater),
                    module_util.GetModulePath(self._args._GetCommand()),
                    ' '.join(self._args._GetCommand().GetPath())))

        tap = display_taps.UriCacher(cache_update_op, self._transform_uri)
        self._resources = peek_iterable.Tapper(self._resources, tap)
Пример #12
0
 def _AddFlattenTap(self):
   """Taps one or more resource flatteners into self.resources if needed."""
   keys = self._GetFlag('flatten')
   if not keys:
     return
   for key in keys:
     flattened_key = []
     for k in resource_lex.Lexer(key).Key():
       if k is None:
         # None represents a [] slice in resource keys.
         tap = display_taps.Flattener(flattened_key)
         # Apply the flatteners from left to right so the innermost flattener
         # flattens the leftmost slice. The outer flatteners can then access
         # the flattened keys to the left.
         self._resources = peek_iterable.Tapper(self._resources, tap)
       else:
         flattened_key.append(k)