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