Mercurial > kallithea
annotate rhodecode/lib/paster_commands/repo_scan.py @ 3997:156cb1cdd7ad
Added handling of copied files diff parsing
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 15 Jun 2013 20:47:41 +0200 |
parents | 68abb78a3d2f |
children | ffd45b185016 |
rev | line source |
---|---|
3340
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 """ |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 rhodecode.lib.paster_commands.make_rcextensions |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 repo-scan paster command for RhodeCode |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 :created_on: Feb 9, 2013 |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 :author: marcink |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 :copyright: (C) 2010-2013 Marcin Kuzminski <marcin@python-works.com> |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 :license: GPLv3, see COPYING for more details. |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 """ |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 # This program is free software: you can redistribute it and/or modify |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 # it under the terms of the GNU General Public License as published by |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 # the Free Software Foundation, either version 3 of the License, or |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 # (at your option) any later version. |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 # This program is distributed in the hope that it will be useful, |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 # GNU General Public License for more details. |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 # You should have received a copy of the GNU General Public License |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 from __future__ import with_statement |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 import os |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 import sys |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 import logging |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 from rhodecode.model.scm import ScmModel |
3915
a42bfe8a9335
moved make-index command to paster_commands module
Marcin Kuzminski <marcin@python-works.com>
parents:
3340
diff
changeset
|
33 from rhodecode.lib.utils import BasePasterCommand, repo2db_mapper |
a42bfe8a9335
moved make-index command to paster_commands module
Marcin Kuzminski <marcin@python-works.com>
parents:
3340
diff
changeset
|
34 |
a42bfe8a9335
moved make-index command to paster_commands module
Marcin Kuzminski <marcin@python-works.com>
parents:
3340
diff
changeset
|
35 # fix rhodecode import |
a42bfe8a9335
moved make-index command to paster_commands module
Marcin Kuzminski <marcin@python-works.com>
parents:
3340
diff
changeset
|
36 from os.path import dirname as dn |
3340
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 rc_path = dn(dn(dn(os.path.realpath(__file__)))) |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 sys.path.append(rc_path) |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 log = logging.getLogger(__name__) |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 class Command(BasePasterCommand): |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 max_args = 1 |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 min_args = 1 |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 usage = "CONFIG_FILE" |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 group_name = "RhodeCode" |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 takes_config_file = -1 |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 parser = BasePasterCommand.standard_parser(verbose=True) |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 summary = "Rescan default location for new repositories" |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 def command(self): |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 #get SqlAlchemy session |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 self._init_session() |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 rm_obsolete = self.options.delete_obsolete |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 log.info('Now scanning root location for new repos...') |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 added, removed = repo2db_mapper(ScmModel().repo_scan(), |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 remove_obsolete=rm_obsolete) |
3987
b58ed6d608cc
Use space after , in lists
Mads Kiilerich <madski@unity3d.com>
parents:
3915
diff
changeset
|
61 added = ', '.join(added) or '-' |
b58ed6d608cc
Use space after , in lists
Mads Kiilerich <madski@unity3d.com>
parents:
3915
diff
changeset
|
62 removed = ', '.join(removed) or '-' |
3991
68abb78a3d2f
small formatting
Marcin Kuzminski <marcin@python-works.com>
parents:
3987
diff
changeset
|
63 log.info('Scan completed added: %s removed: %s' % (added, removed)) |
3340
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 def update_parser(self): |
3991
68abb78a3d2f
small formatting
Marcin Kuzminski <marcin@python-works.com>
parents:
3987
diff
changeset
|
66 self.parser.add_option( |
68abb78a3d2f
small formatting
Marcin Kuzminski <marcin@python-works.com>
parents:
3987
diff
changeset
|
67 '--delete-obsolete', |
68abb78a3d2f
small formatting
Marcin Kuzminski <marcin@python-works.com>
parents:
3987
diff
changeset
|
68 action='store_true', |
68abb78a3d2f
small formatting
Marcin Kuzminski <marcin@python-works.com>
parents:
3987
diff
changeset
|
69 help="Use this flag do delete repositories that are " |
68abb78a3d2f
small formatting
Marcin Kuzminski <marcin@python-works.com>
parents:
3987
diff
changeset
|
70 "present in RhodeCode database but not on the filesystem", |
68abb78a3d2f
small formatting
Marcin Kuzminski <marcin@python-works.com>
parents:
3987
diff
changeset
|
71 ) |