annotate rhodecode/lib/paster_commands/repo_scan.py @ 3340:f1491bad8339 beta

unified RhodeCode paster commands - moved them to commont paster_commands package - re-use sqlalchemy session initializaiton - some docs updates
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 09 Feb 2013 22:21:31 +0100
parents
children a42bfe8a9335
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 os.path import dirname as dn, join as jn
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
33 from rhodecode.model.scm import ScmModel
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
34 #to get the rhodecode import
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 rc_path = dn(dn(dn(os.path.realpath(__file__))))
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 sys.path.append(rc_path)
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 from rhodecode.lib.utils import BasePasterCommand, repo2db_mapper
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39 from rhodecode.model.db import Repository
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 from rhodecode.model.repo import RepoModel
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41 from rhodecode.model.meta import Session
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
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44 log = logging.getLogger(__name__)
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 class Command(BasePasterCommand):
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 max_args = 1
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 min_args = 1
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52 usage = "CONFIG_FILE"
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 group_name = "RhodeCode"
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 takes_config_file = -1
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 parser = BasePasterCommand.standard_parser(verbose=True)
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 summary = "Rescan default location for new repositories"
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58 def command(self):
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59 #get SqlAlchemy session
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 self._init_session()
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 rm_obsolete = self.options.delete_obsolete
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 log.info('Now scanning root location for new repos...')
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 added, removed = repo2db_mapper(ScmModel().repo_scan(),
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
64 remove_obsolete=rm_obsolete)
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 added = ','.join(added) or '-'
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 removed = ','.join(removed) or '-'
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
67 log.info('Scan completed added:%s removed:%s' % (added, removed))
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 def update_parser(self):
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70 self.parser.add_option('--delete-obsolete',
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71 action='store_true',
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72 help="Use this flag do delete repositories that are "
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 "present in RhodeCode database but not on the filesystem",
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 )