[PATCH 6 of 7 WIPv2] cli: convert 'gearbox cache-keys --show/--cleanup' into 'kallithea-cli cache show-keys/cleanup-keys'

Thomas De Schampheleire patrickdepinguin at gmail.com
Mon Oct 8 19:57:37 UTC 2018


# HG changeset patch
# User Thomas De Schampheleire <thomas.de_schampheleire at nokia.com>
# Date 1538596063 -7200
#      Wed Oct 03 21:47:43 2018 +0200
# Node ID 2993ba9db9e2d9cfb02d298d1933b04d4f4086fe
# Parent  6ecaf9e33bbfa23943b488cc3a24b69dff6ed1c0
cli: convert 'gearbox cache-keys --show/--cleanup' into 'kallithea-cli cache show-keys/cleanup-keys'

Note: cli topic has been named 'cache' rather than 'cache-keys' in
anticipation of possible future cache-related commands that are not
related to 'keys'.

diff --git a/kallithea/bin/kallithea_cli.py b/kallithea/bin/kallithea_cli.py
--- a/kallithea/bin/kallithea_cli.py
+++ b/kallithea/bin/kallithea_cli.py
@@ -14,6 +14,7 @@
 
 import click
 
+from kallithea.bin.kallithea_cli_cache import cache
 from kallithea.bin.kallithea_cli_celery import celery
 from kallithea.bin.kallithea_cli_config import config
 from kallithea.bin.kallithea_cli_ishell import ishell
@@ -23,6 +24,7 @@ def cli():
     """Various commands to set up a Kallithea instance."""
     pass
 
+cli.add_command(cache)
 cli.add_command(celery)
 cli.add_command(config)
 cli.add_command(ishell)
diff --git a/kallithea/lib/paster_commands/cache_keys.py b/kallithea/bin/kallithea_cli_cache.py
rename from kallithea/lib/paster_commands/cache_keys.py
rename to kallithea/bin/kallithea_cli_cache.py
--- a/kallithea/lib/paster_commands/cache_keys.py
+++ b/kallithea/bin/kallithea_cli_cache.py
@@ -12,59 +12,38 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 """
-kallithea.lib.paster_commands.cache_keys
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-cleanup-keys gearbox command for Kallithea
-
-
-This file was forked by the Kallithea project in July 2014.
+This file was forked by the Kallithea project in July 2014 and later moved.
 Original author and date, and relevant copyright and licensing information is below:
 :created_on: mar 27, 2013
 :author: marcink
 :copyright: (c) 2013 RhodeCode GmbH, and others.
 :license: GPLv3, see LICENSE.md for more details.
 """
-
+import click
+import kallithea.bin.kallithea_cli_util as cli_util
 
-
-from kallithea.lib.paster_commands.common import BasePasterCommand
+from kallithea.model.db import CacheInvalidation
 from kallithea.model.meta import Session
 from kallithea.lib.utils2 import safe_str
-from kallithea.model.db import CacheInvalidation
 
-
-class Command(BasePasterCommand):
-    "Kallithea: Utilities for managing caching of database content"
-
-    def take_action(self, args):
-        _caches = CacheInvalidation.query().order_by(CacheInvalidation.cache_key).all()
-        if args.show:
-            for c_obj in _caches:
-                print 'key:%s active:%s' % (safe_str(c_obj.cache_key), c_obj.cache_active)
-        elif args.cleanup:
-            for c_obj in _caches:
-                Session().delete(c_obj)
-                print 'Removing key: %s' % (safe_str(c_obj.cache_key))
-            Session().commit()
-        else:
-            print 'Nothing done, exiting...'
+ at click.group()
+def cache():
+    pass
 
-    def get_parser(self, prog_name):
-        parser = super(Command, self).get_parser(prog_name)
+ at cache.command()
+ at cli_util.auto_setup_app()
+def show_keys(config_file):
+    """Show existing cache keys with their status."""
+    _caches = CacheInvalidation.query().order_by(CacheInvalidation.cache_key).all()
+    for c_obj in _caches:
+        click.echo('key:%s active:%s' % (safe_str(c_obj.cache_key), c_obj.cache_active))
 
-        parser.add_argument(
-            '--show',
-            action='store_true',
-            dest='show',
-            help="show existing cache keys with together with status",
-        )
-
-        parser.add_argument(
-            '--cleanup',
-            action="store_true",
-            dest="cleanup",
-            help="cleanup existing cache keys",
-        )
-
-        return parser
+ at cache.command()
+ at cli_util.auto_setup_app()
+def cleanup_keys(config_file):
+    """Clean up existing cache keys."""
+    _caches = CacheInvalidation.query().order_by(CacheInvalidation.cache_key).all()
+    for c_obj in _caches:
+        Session().delete(c_obj)
+        click.echo('Removing key: %s' % (safe_str(c_obj.cache_key)))
+    Session().commit()
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -158,7 +158,6 @@ setuptools.setup(
     main = kallithea.config.middleware:make_app
 
     [gearbox.commands]
-    cache-keys=kallithea.lib.paster_commands.cache_keys:Command
     cleanup-repos=kallithea.lib.paster_commands.cleanup:Command
     install-iis=kallithea.lib.paster_commands.install_iis:Command
     make-index=kallithea.lib.paster_commands.make_index:Command


More information about the kallithea-general mailing list