Mercurial > kallithea
annotate rhodecode/lib/paster_commands/cache_keys.py @ 3915:a42bfe8a9335 beta
moved make-index command to paster_commands module
- optimized imports and code
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 30 May 2013 00:01:16 +0200 |
parents | e9ac7544c2f6 |
children | 7c84b383824f |
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 rhodecode.model.meta import Session |
3915
a42bfe8a9335
moved make-index command to paster_commands module
Marcin Kuzminski <marcin@python-works.com>
parents:
3616
diff
changeset
|
33 from rhodecode.lib.utils import BasePasterCommand |
a42bfe8a9335
moved make-index command to paster_commands module
Marcin Kuzminski <marcin@python-works.com>
parents:
3616
diff
changeset
|
34 from rhodecode.model.db import CacheInvalidation |
a42bfe8a9335
moved make-index command to paster_commands module
Marcin Kuzminski <marcin@python-works.com>
parents:
3616
diff
changeset
|
35 |
a42bfe8a9335
moved make-index command to paster_commands module
Marcin Kuzminski <marcin@python-works.com>
parents:
3616
diff
changeset
|
36 # fix rhodecode import |
a42bfe8a9335
moved make-index command to paster_commands module
Marcin Kuzminski <marcin@python-works.com>
parents:
3616
diff
changeset
|
37 from os.path import dirname as dn |
3616
e9ac7544c2f6
added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 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
|
39 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
|
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 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
|
42 |
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 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
|
45 |
e9ac7544c2f6
added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 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
|
47 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
|
48 |
e9ac7544c2f6
added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 |
e9ac7544c2f6
added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 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
|
56 #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
|
57 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
|
58 _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
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 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
|
67 else: |
e9ac7544c2f6
added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 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
|
69 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
|
70 |
e9ac7544c2f6
added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 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
|
72 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
|
73 '--show', |
e9ac7544c2f6
added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 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
|
75 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
|
76 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
|
77 ) |
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 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
|
80 '--cleanup', |
e9ac7544c2f6
added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
81 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
|
82 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
|
83 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
|
84 ) |