annotate rhodecode/lib/update_repoinfo.py @ 3181:efe23d6c178c rhodecode-0.0.1.5.2

merged with beta
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 21 Jan 2013 00:49:59 +0100
parents 8182ebed2922
children b3cf4539d1bd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 """
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
3 package.rhodecode.lib.cleanup
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
5
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
6 :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
7 :author: marcink
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
8 :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
9 :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
10 """
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
11 # 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
12 # 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
13 # 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
14 # (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
15 #
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 # 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
17 # 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
18 # 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
19 # 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
20 #
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 # 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
22 # 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
23 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
24
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 import os
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 import sys
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
27 import re
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28 import shutil
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 datetime
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 import string
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
32
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 from os.path import dirname as dn, join as jn
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 from rhodecode.model import init_model
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 from rhodecode.lib.utils2 import engine_from_config, safe_str
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 from rhodecode.model.db import RhodeCodeUi, Repository
3147
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3118
diff changeset
37 from rhodecode.lib.vcs.backends.base import EmptyChangeset
3006
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 #to get the rhodecode import
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 sys.path.append(dn(dn(dn(os.path.realpath(__file__)))))
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 from rhodecode.lib.utils import BasePasterCommand, Command, add_cache
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 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
46
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 class UpdateCommand(BasePasterCommand):
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 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
51 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
52
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 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
54 summary = "Cleanup deleted repos"
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 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
56 takes_config_file = -1
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 parser = Command.standard_parser(verbose=True)
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 def command(self):
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 logging.config.fileConfig(self.path_to_ini_file)
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 from pylons import config
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 #get to remove repos !!
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 add_cache(config)
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 engine = engine_from_config(config, 'sqlalchemy.db1.')
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 init_model(engine)
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68 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
69 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
70 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
71
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 if 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
73 repo_list = Repository.query().filter(Repository.repo_name.in_(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
74 else:
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75 repo_list = Repository.getAll()
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 for repo in repo_list:
3147
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3118
diff changeset
77 last_cs = (repo.scm_instance.get_changeset() if repo.scm_instance
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3118
diff changeset
78 else EmptyChangeset())
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3118
diff changeset
79 repo.update_changeset_cache(last_cs)
3006
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81 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
82 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
83 action='store',
9b95dc7c4570 Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 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
85 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
86 "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
87 )