annotate rhodecode/lib/paster_commands/cache_keys.py @ 3616:e9ac7544c2f6 beta

added super simple cache_key paster function for showing and cleaning cache keys
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 27 Mar 2013 19:06:09 +0100
parents
children a42bfe8a9335
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3616
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
2 """
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 rhodecode.lib.paster_commands.cache_keys
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 cleanup-keys paster command for RhodeCode
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
9 :created_on: mar 27, 2013
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
10 :author: marcink
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 :copyright: (C) 2010-2013 Marcin Kuzminski <marcin@python-works.com>
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 :license: GPLv3, see COPYING for more details.
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 """
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 # This program is free software: you can redistribute it and/or modify
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 # it under the terms of the GNU General Public License as published by
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 # the Free Software Foundation, either version 3 of the License, or
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 # (at your option) any later version.
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 #
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 # This program is distributed in the hope that it will be useful,
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 # GNU General Public License for more details.
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 #
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 # You should have received a copy of the GNU General Public License
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 from __future__ import with_statement
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 import os
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 import sys
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30 import logging
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32 from os.path import dirname as dn, join as jn
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 from rhodecode.model.meta import Session
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 #to get the rhodecode import
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 rc_path = dn(dn(dn(os.path.realpath(__file__))))
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 sys.path.append(rc_path)
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 from rhodecode.lib.utils import BasePasterCommand
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39 from rhodecode.model.db import CacheInvalidation
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 log = logging.getLogger(__name__)
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 class Command(BasePasterCommand):
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 max_args = 1
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 min_args = 1
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 usage = "CONFIG_FILE"
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 group_name = "RhodeCode"
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 takes_config_file = -1
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 parser = BasePasterCommand.standard_parser(verbose=True)
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 summary = "Cache keys utils"
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 def command(self):
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 #get SqlAlchemy session
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58 self._init_session()
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 _caches = CacheInvalidation.query().order_by(CacheInvalidation.cache_key).all()
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 if self.options.show:
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 for c_obj in _caches:
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 print 'key:%s active:%s' % (c_obj.cache_key, c_obj.cache_active)
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 elif self.options.cleanup:
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 for c_obj in _caches:
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 Session().delete(c_obj)
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 print 'removing key:%s' % (c_obj.cache_key)
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 Session().commit()
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68 else:
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 print 'nothing done exiting...'
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70 sys.exit(0)
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 def update_parser(self):
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 self.parser.add_option(
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 '--show',
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 action='store_true',
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 dest='show',
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77 help=("show existing cache keys with together with status")
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 )
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 self.parser.add_option(
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81 '--cleanup',
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82 action="store_true",
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
83 dest="cleanup",
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 help="cleanup existing cache keys"
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85 )