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