[PATCH 06 of 17 v3] cli: convert 'gearbox cache-keys --show/--cleanup' into 'kallithea-cli cache-show-keys/cache-cleanup-keys'

Thomas De Schampheleire patrickdepinguin at gmail.com
Thu Oct 18 20:49:29 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 949f164c58c8cccd17b76f9720e21783c8f391ec
# Parent  75d52bf69ca48a534cca12c3d7301175b9488b3f
cli: convert 'gearbox cache-keys --show/--cleanup' into 'kallithea-cli cache-show-keys/cache-cleanup-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
@@ -16,6 +16,7 @@
 from kallithea.bin.kallithea_cli_base import cli
 
 # import commands (they will add themselves to the 'cli' object)
+import kallithea.bin.kallithea_cli_cache
 import kallithea.bin.kallithea_cli_celery
 import kallithea.bin.kallithea_cli_config
 import kallithea.bin.kallithea_cli_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,35 @@
 # 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
+from kallithea.bin.kallithea_cli_base import cli
+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 cli.command()
+ at cli_util.auto_setup_app()
+def cache_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))
 
-    def get_parser(self, prog_name):
-        parser = super(Command, self).get_parser(prog_name)
-
-        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 cli.command()
+ at cli_util.auto_setup_app()
+def cache_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