Mercurial > kallithea
annotate rhodecode/lib/update_repoinfo.py @ 3066:5d580e9bc730 beta
JS cleanup
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 06 Dec 2012 01:20:57 +0100 |
parents | 9b95dc7c4570 |
children | 56cdbcf0678a |
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 |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 |
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 #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
|
40 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
|
41 |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 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
|
43 |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 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
|
45 |
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 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
|
48 |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 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
|
50 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
|
51 |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 #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
|
63 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
|
64 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
|
65 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
|
66 |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 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
|
68 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
|
69 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
|
70 |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 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
|
72 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
|
73 else: |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 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
|
75 for repo in repo_list: |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 last_change = repo.scm_instance.last_change |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 repo.update_last_change(last_change) |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 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
|
80 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
|
81 action='store', |
9b95dc7c4570
Implements #648 write Script for updating last modification time for lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 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
|
83 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
|
84 "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
|
85 ) |