Mercurial > kallithea
annotate rhodecode/lib/paster_commands/update_repoinfo.py @ 3340:f1491bad8339 beta
unified RhodeCode paster commands
- moved them to commont paster_commands package
- re-use sqlalchemy session initializaiton
- some docs updates
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 09 Feb 2013 22:21:31 +0100 |
parents | rhodecode/lib/update_repoinfo.py@968b28545f93 |
children | e08321d4c106 |
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 |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 from os.path import dirname as dn, join as jn |
3340
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3334
diff
changeset
|
33 #to get the rhodecode import |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3334
diff
changeset
|
34 rc_path = dn(dn(dn(os.path.realpath(__file__)))) |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3334
diff
changeset
|
35 sys.path.append(rc_path) |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3334
diff
changeset
|
36 from rhodecode.lib.utils import BasePasterCommand |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3334
diff
changeset
|
37 |
3309
b3cf4539d1bd
Added missing migrations, and move update_repoinfo to RepoModel
Marcin Kuzminski <marcin@python-works.com>
parents:
3147
diff
changeset
|
38 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
|
39 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
|
40 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
|
41 |
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() |
3340
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
3334
diff
changeset
|
71 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
|
72 |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
73 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
|
74 self.parser.add_option('--update-only', |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 action='store', |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 dest='repo_update_list', |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 help="Specifies a comma separated list of repositores " |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 "to update last commit info for. OPTIONAL", |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 ) |