예제 #1
0
  def Run(self, args):
    with cache_util.GetCache(args.cache) as cache:
      log.info('cache name {}'.format(cache.name))

      if args.tables:
        names = [name for pattern in args.tables
                 for name in cache.Select(pattern)]
        if not names:
          raise cache_util.NoTablesMatched('No tables matched [{}].'.format(
              ','.join(args.tables)))
        if not args.IsSpecified('format'):
          args.format = 'json'
        results = []
        for name in names:
          try:
            table = cache.Table(name, create=False)
            results.append({
                'name': table.name,
                'data': table.Select(ignore_expiration=False)
            })
          except cache_exceptions.Error as e:
            log.warning(e)
        return results

      if not args.IsSpecified('format'):
        args.format = ('table[box](name, columns:label=COL, keys:label=KEY, '
                       'timeout, is_expired:label=EXPIRED)')
      names = cache.Select()
      return [cache.Table(name=name, create=False) for name in sorted(names)]
예제 #2
0
  def Run(self, args):

    def _RequireConfirmation(name):
      """Prompt for cache deletion and return confirmation."""
      console_io.PromptContinue(
          message='The entire [{}] cache will be deleted.'.format(name),
          cancel_on_no=True,
          default=True)

    if not args.tables and not args.IsSpecified('cache'):
      _RequireConfirmation(args.cache)
      cache_util.Delete()
      return None

    with cache_util.GetCache(args.cache) as cache:
      log.info('cache name {}'.format(cache.name))
      if args.tables:
        names = [name for pattern in args.tables
                 for name in cache.Select(pattern)]
        if not names:
          raise cache_util.NoTablesMatched('No tables matched [{}].'.format(
              ','.join(args.tables)))
        console_io.PromptContinue(
            message='[{}] will be deleted.'.format(','.join(names)),
            default=True,
            cancel_on_no=True)
        for name in names:
          table = cache.Table(name)
          table.Delete()
        return None

      _RequireConfirmation(cache.name)
      cache.Delete()

    return None
예제 #3
0
  def Run(self, args):
    with cache_util.GetCache(args.cache) as cache:
      log.info('cache name {}'.format(cache.name))
      if args.tables:
        names = [name for pattern in args.tables
                 for name in cache.Select(pattern)]
        if not names:
          raise cache_util.NoTablesMatched('No tables matched [{}].'.format(
              ','.join(args.tables)))
        console_io.PromptContinue(
            message=u'[{}] will be deleted.'.format(','.join(names)),
            default=True,
            cancel_on_no=True)
        for name in names:
          table = cache.Table(name)
          table.Delete()
        return None
      console_io.PromptContinue(
          message='The entire [{}] cache will be deleted.'.format(cache.name),
          default=True,
          cancel_on_no=True)

    cache_util.GetCache(args.cache).Delete()
    return None