annotate rhodecode/lib/paster_commands/cache_keys.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl

Imported some of the GPLv3'd changes from RhodeCode v2.2.5. This imports changes between changesets 21af6c4eab3d and 6177597791c2 in RhodeCode's original repository, including only changes to Python files and HTML. RhodeCode clearly licensed its changes to these files under GPLv3 in their /LICENSE file, which states the following: The Python code and integrated HTML are licensed under the GPLv3 license. (See: https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE or http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE for an online copy of that LICENSE file) Conservancy reviewed these changes and confirmed that they can be licensed as a whole to the Kallithea project under GPLv3-only. While some of the contents committed herein are clearly licensed GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the statement above from RhodeCode indicates that they intend GPLv3-only as their license, per GPLv3ยง14 and other relevant sections of GPLv3.
author Bradley M. Kuhn <bkuhn@sfconservancy.org>
date Wed, 02 Jul 2014 19:03:13 -0400
parents 7c84b383824f
children e9f6b533a8f6
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 # 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
3 # 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
4 # 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
5 # (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
6 #
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 # 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
8 # 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
9 # 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
10 # 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
11 #
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 # 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
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3977
diff changeset
14 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3977
diff changeset
15 rhodecode.lib.paster_commands.cache_keys
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3977
diff changeset
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3977
diff changeset
17
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3977
diff changeset
18 cleanup-keys paster command for RhodeCode
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3977
diff changeset
19
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3977
diff changeset
20
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3977
diff changeset
21 :created_on: mar 27, 2013
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3977
diff changeset
22 :author: marcink
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3977
diff changeset
23 :copyright: (c) 2013 RhodeCode GmbH.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3977
diff changeset
24 :license: GPLv3, see LICENSE for more details.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3977
diff changeset
25 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3977
diff changeset
26
3616
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 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
28
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 os
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 sys
e9ac7544c2f6 added super simple cache_key paster function for showing and cleaning cache keys
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 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
32
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
3915
a42bfe8a9335 moved make-index command to paster_commands module
Marcin Kuzminski <marcin@python-works.com>
parents: 3616
diff changeset
34 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
35 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
36
a42bfe8a9335 moved make-index command to paster_commands module
Marcin Kuzminski <marcin@python-works.com>
parents: 3616
diff changeset
37 # fix rhodecode import
a42bfe8a9335 moved make-index command to paster_commands module
Marcin Kuzminski <marcin@python-works.com>
parents: 3616
diff changeset
38 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
39 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
40 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
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)
3977
7c84b383824f Don't create one big transaction when doing cache-keys cleanup.
Marcin Kuzminski <marcin@python-works.com>
parents: 3915
diff changeset
67 Session().commit()
3616
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 )