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