Mercurial > kallithea
annotate rhodecode/lib/paster_commands/repo_scan.py @ 3915:a42bfe8a9335 beta
moved make-index command to paster_commands module
- optimized imports and code
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 30 May 2013 00:01:16 +0200 |
parents | f1491bad8339 |
children | b58ed6d608cc |
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) |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
61 added = ','.join(added) or '-' |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 removed = ','.join(removed) or '-' |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 log.info('Scan completed added:%s removed:%s' % (added, removed)) |
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): |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
66 self.parser.add_option('--delete-obsolete', |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 action='store_true', |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 help="Use this flag do delete repositories that are " |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
69 "present in RhodeCode database but not on the filesystem", |
f1491bad8339
unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 ) |