##// END OF EJS Templates
update_repoinfo: fix invalidation
Mads Kiilerich -
r3662:93795b90 beta
parent child Browse files
Show More
@@ -1,88 +1,87 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 rhodecode.lib.paster_commands.make_rcextensions
3 rhodecode.lib.paster_commands.make_rcextensions
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5
5
6 uodate-repoinfo paster command for RhodeCode
6 uodate-repoinfo paster command for RhodeCode
7
7
8 :created_on: Jul 14, 2012
8 :created_on: Jul 14, 2012
9 :author: marcink
9 :author: marcink
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
11 :license: GPLv3, see COPYING for more details.
12 """
12 """
13 # This program is free software: you can redistribute it and/or modify
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
16 # (at your option) any later version.
17 #
17 #
18 # This program is distributed in the hope that it will be useful,
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
21 # GNU General Public License for more details.
22 #
22 #
23 # You should have received a copy of the GNU General Public License
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 from __future__ import with_statement
25 from __future__ import with_statement
26
26
27 import os
27 import os
28 import sys
28 import sys
29 import logging
29 import logging
30 import string
30 import string
31
31
32 from os.path import dirname as dn, join as jn
32 from os.path import dirname as dn, join as jn
33 #to get the rhodecode import
33 #to get the rhodecode import
34 rc_path = dn(dn(dn(os.path.realpath(__file__))))
34 rc_path = dn(dn(dn(os.path.realpath(__file__))))
35 sys.path.append(rc_path)
35 sys.path.append(rc_path)
36 from rhodecode.lib.utils import BasePasterCommand
36 from rhodecode.lib.utils import BasePasterCommand
37
37
38 from rhodecode.model.db import Repository
38 from rhodecode.model.db import Repository
39 from rhodecode.model.repo import RepoModel
39 from rhodecode.model.repo import RepoModel
40 from rhodecode.model.meta import Session
40 from rhodecode.model.meta import Session
41
41
42 log = logging.getLogger(__name__)
42 log = logging.getLogger(__name__)
43
43
44
44
45 class Command(BasePasterCommand):
45 class Command(BasePasterCommand):
46
46
47 max_args = 1
47 max_args = 1
48 min_args = 1
48 min_args = 1
49
49
50 usage = "CONFIG_FILE"
50 usage = "CONFIG_FILE"
51 group_name = "RhodeCode"
51 group_name = "RhodeCode"
52 takes_config_file = -1
52 takes_config_file = -1
53 parser = BasePasterCommand.standard_parser(verbose=True)
53 parser = BasePasterCommand.standard_parser(verbose=True)
54 summary = "Updates repositories caches for last changeset"
54 summary = "Updates repositories caches for last changeset"
55
55
56 def command(self):
56 def command(self):
57 #get SqlAlchemy session
57 #get SqlAlchemy session
58 self._init_session()
58 self._init_session()
59
59
60 repo_update_list = map(string.strip,
60 repo_update_list = map(string.strip,
61 self.options.repo_update_list.split(',')) \
61 self.options.repo_update_list.split(',')) \
62 if self.options.repo_update_list else None
62 if self.options.repo_update_list else None
63
63
64 if repo_update_list:
64 if repo_update_list:
65 repo_list = Repository.query()\
65 repo_list = Repository.query()\
66 .filter(Repository.repo_name.in_(repo_update_list))
66 .filter(Repository.repo_name.in_(repo_update_list))
67 else:
67 else:
68 repo_list = Repository.getAll()
68 repo_list = Repository.getAll()
69 RepoModel.update_repoinfo(repositories=repo_list)
69 RepoModel.update_repoinfo(repositories=repo_list)
70 Session().commit()
70 Session().commit()
71
71
72 if self.options.invalidate_cache:
72 if self.options.invalidate_cache:
73 for r in repo_list:
73 for r in repo_list:
74 r.invalidate
74 r.set_invalidate()
75 Session().commit()
76 log.info('Updated cache for %s repositories' % (len(repo_list)))
75 log.info('Updated cache for %s repositories' % (len(repo_list)))
77
76
78 def update_parser(self):
77 def update_parser(self):
79 self.parser.add_option('--update-only',
78 self.parser.add_option('--update-only',
80 action='store',
79 action='store',
81 dest='repo_update_list',
80 dest='repo_update_list',
82 help="Specifies a comma separated list of repositores "
81 help="Specifies a comma separated list of repositores "
83 "to update last commit info for. OPTIONAL")
82 "to update last commit info for. OPTIONAL")
84 self.parser.add_option('--invalidate-cache',
83 self.parser.add_option('--invalidate-cache',
85 action='store_true',
84 action='store_true',
86 dest='invalidate_cache',
85 dest='invalidate_cache',
87 help="Trigger cache invalidation event for repos. "
86 help="Trigger cache invalidation event for repos. "
88 "OPTIONAL")
87 "OPTIONAL")
General Comments 0
You need to be logged in to leave comments. Login now