Show More
@@ -1,85 +1,86 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | """ |
|
3 | 3 | package.rhodecode.lib.cleanup |
|
4 | 4 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
5 | 5 | |
|
6 | 6 | :created_on: Jul 14, 2012 |
|
7 | 7 | :author: marcink |
|
8 | 8 | :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> |
|
9 | 9 | :license: GPLv3, see COPYING for more details. |
|
10 | 10 | """ |
|
11 | 11 | # This program is free software: you can redistribute it and/or modify |
|
12 | 12 | # it under the terms of the GNU General Public License as published by |
|
13 | 13 | # the Free Software Foundation, either version 3 of the License, or |
|
14 | 14 | # (at your option) any later version. |
|
15 | 15 | # |
|
16 | 16 | # This program is distributed in the hope that it will be useful, |
|
17 | 17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 | 18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 | 19 | # GNU General Public License for more details. |
|
20 | 20 | # |
|
21 | 21 | # You should have received a copy of the GNU General Public License |
|
22 | 22 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
23 | 23 | from __future__ import with_statement |
|
24 | 24 | |
|
25 | 25 | import os |
|
26 | 26 | import sys |
|
27 | 27 | import re |
|
28 | 28 | import shutil |
|
29 | 29 | import logging |
|
30 | 30 | import datetime |
|
31 | 31 | import string |
|
32 | 32 | |
|
33 | 33 | from os.path import dirname as dn, join as jn |
|
34 | 34 | from rhodecode.model import init_model |
|
35 | 35 | from rhodecode.lib.utils2 import engine_from_config, safe_str |
|
36 | 36 | from rhodecode.model.db import RhodeCodeUi, Repository |
|
37 | 37 | |
|
38 | 38 | |
|
39 | 39 | #to get the rhodecode import |
|
40 | 40 | sys.path.append(dn(dn(dn(os.path.realpath(__file__))))) |
|
41 | 41 | |
|
42 | 42 | from rhodecode.lib.utils import BasePasterCommand, Command, add_cache |
|
43 | 43 | |
|
44 | 44 | log = logging.getLogger(__name__) |
|
45 | 45 | |
|
46 | 46 | |
|
47 | 47 | class UpdateCommand(BasePasterCommand): |
|
48 | 48 | |
|
49 | 49 | max_args = 1 |
|
50 | 50 | min_args = 1 |
|
51 | 51 | |
|
52 | 52 | usage = "CONFIG_FILE" |
|
53 | 53 | summary = "Cleanup deleted repos" |
|
54 | 54 | group_name = "RhodeCode" |
|
55 | 55 | takes_config_file = -1 |
|
56 | 56 | parser = Command.standard_parser(verbose=True) |
|
57 | 57 | |
|
58 | 58 | def command(self): |
|
59 | 59 | logging.config.fileConfig(self.path_to_ini_file) |
|
60 | 60 | from pylons import config |
|
61 | 61 | |
|
62 | 62 | #get to remove repos !! |
|
63 | 63 | add_cache(config) |
|
64 | 64 | engine = engine_from_config(config, 'sqlalchemy.db1.') |
|
65 | 65 | init_model(engine) |
|
66 | 66 | |
|
67 | 67 | repo_update_list = map(string.strip, |
|
68 | 68 | self.options.repo_update_list.split(',')) \ |
|
69 | 69 | if self.options.repo_update_list else None |
|
70 | 70 | |
|
71 | 71 | if repo_update_list: |
|
72 | 72 | repo_list = Repository.query().filter(Repository.repo_name.in_(repo_update_list)) |
|
73 | 73 | else: |
|
74 | 74 | repo_list = Repository.getAll() |
|
75 | 75 | for repo in repo_list: |
|
76 | last_change = repo.scm_instance.last_change | |
|
76 | last_change = (repo.scm_instance.last_change if repo.scm_instance | |
|
77 | else datetime.datetime.utcfromtimestamp(0)) | |
|
77 | 78 | repo.update_last_change(last_change) |
|
78 | 79 | |
|
79 | 80 | def update_parser(self): |
|
80 | 81 | self.parser.add_option('--update-only', |
|
81 | 82 | action='store', |
|
82 | 83 | dest='repo_update_list', |
|
83 | 84 | help="Specifies a comma separated list of repositores " |
|
84 | 85 | "to update last commit info for. OPTIONAL", |
|
85 | 86 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now