From 6e76c3a5a07d03d9107685a7edec285744dd9fbb Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Mon, 30 Apr 2018 15:37:47 -0400 Subject: [PATCH] add a couple of cache management commands Change-Id: I15c14f9a64a9ae5d8dca6dd452d6ebae18fb51be Signed-off-by: Doug Hellmann --- goal_tools/caching.py | 5 +++ goal_tools/who_helped/cache.py | 61 ++++++++++++++++++++++++++++++++++ setup.cfg | 2 ++ 3 files changed, 68 insertions(+) create mode 100644 goal_tools/who_helped/cache.py diff --git a/goal_tools/caching.py b/goal_tools/caching.py index 6094783..d28afbd 100644 --- a/goal_tools/caching.py +++ b/goal_tools/caching.py @@ -39,3 +39,8 @@ class Cache: def __getitem__(self, key): return self._shelf[self._mk_key(key)] + + def __delitem__(self, key): + real_key = self._mk_key(key) + if real_key in self._shelf: + del self._shelf[real_key] diff --git a/goal_tools/who_helped/cache.py b/goal_tools/who_helped/cache.py new file mode 100644 index 0000000..7e85670 --- /dev/null +++ b/goal_tools/who_helped/cache.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import logging +import pprint + +from cliff import command + +LOG = logging.getLogger(__name__) + + +class CacheRemove(command.Command): + "Remove an entry from the cache." + + def get_parser(self, prog_name): + parser = super().get_parser(prog_name) + parser.add_argument( + 'type', + choices=['review', 'email'], + help='the kind of thing to remove', + ) + parser.add_argument( + 'id', + help='the id of the item to remove', + ) + return parser + + def take_action(self, parsed_args): + del self.app.cache[(parsed_args.type, parsed_args.id)] + + +class CacheShow(command.Command): + "Show an entry in the cache." + + def get_parser(self, prog_name): + parser = super().get_parser(prog_name) + parser.add_argument( + 'type', + choices=['review', 'email'], + help='the kind of thing to remove', + ) + parser.add_argument( + 'id', + help='the id of the item to remove', + ) + return parser + + def take_action(self, parsed_args): + data = self.app.cache[(parsed_args.type, parsed_args.id)] + pprint.pprint(data) diff --git a/setup.cfg b/setup.cfg index 226915f..064ac47 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,6 +32,8 @@ who_helped = contributions list = goal_tools.who_helped.contributions:ListContributions member show = goal_tools.who_helped.members:ShowMember changes query = goal_tools.who_helped.changes:QueryChanges + cache remove = goal_tools.who_helped.cache:CacheRemove + cache show = goal_tools.who_helped.cache:CacheShow [wheel]