diff --git a/rhodecode/lib/paster_commands/__init__.py b/rhodecode/lib/paster_commands/__init__.py new file mode 100644 diff --git a/rhodecode/lib/cleanup.py b/rhodecode/lib/paster_commands/cleanup.py rename from rhodecode/lib/cleanup.py rename to rhodecode/lib/paster_commands/cleanup.py --- a/rhodecode/lib/cleanup.py +++ b/rhodecode/lib/paster_commands/cleanup.py @@ -1,7 +1,10 @@ # -*- coding: utf-8 -*- """ - package.rhodecode.lib.cleanup - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + rhodecode.lib.paster_commands.make_rcextensions + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + cleanup-repos paster command for RhodeCode + :created_on: Jul 14, 2012 :author: marcink @@ -30,30 +33,28 @@ import logging import datetime from os.path import dirname as dn, join as jn -from rhodecode.model import init_model -from rhodecode.lib.utils2 import engine_from_config, safe_str +#to get the rhodecode import +rc_path = dn(dn(dn(os.path.realpath(__file__)))) +sys.path.append(rc_path) +from rhodecode.lib.utils import BasePasterCommand, ask_ok, REMOVED_REPO_PAT + +from rhodecode.lib.utils2 import safe_str from rhodecode.model.db import RhodeCodeUi -#to get the rhodecode import -sys.path.append(dn(dn(dn(os.path.realpath(__file__))))) - -from rhodecode.lib.utils import BasePasterCommand, Command, ask_ok,\ - REMOVED_REPO_PAT, add_cache - log = logging.getLogger(__name__) -class CleanupCommand(BasePasterCommand): +class Command(BasePasterCommand): max_args = 1 min_args = 1 usage = "CONFIG_FILE" - summary = "Cleanup deleted repos" group_name = "RhodeCode" takes_config_file = -1 - parser = Command.standard_parser(verbose=True) + parser = BasePasterCommand.standard_parser(verbose=True) + summary = "Cleanup deleted repos" def _parse_older_than(self, val): regex = re.compile(r'((?P\d+?)d)?((?P\d+?)h)?((?P\d+?)m)?((?P\d+?)s)?') @@ -78,13 +79,8 @@ class CleanupCommand(BasePasterCommand): return datetime.datetime.strptime(date_part, '%Y%m%d_%H%M%S') def command(self): - logging.config.fileConfig(self.path_to_ini_file) - from pylons import config - - #get to remove repos !! - add_cache(config) - engine = engine_from_config(config, 'sqlalchemy.db1.') - init_model(engine) + #get SqlAlchemy session + self._init_session() repos_location = RhodeCodeUi.get_repos_location() to_remove = [] diff --git a/rhodecode/config/rcextensions/make_rcextensions.py b/rhodecode/lib/paster_commands/make_rcextensions.py rename from rhodecode/config/rcextensions/make_rcextensions.py rename to rhodecode/lib/paster_commands/make_rcextensions.py --- a/rhodecode/config/rcextensions/make_rcextensions.py +++ b/rhodecode/lib/paster_commands/make_rcextensions.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- """ - rhodecode.config.rcextensions.make_rcextensions + rhodecode.lib.paster_commands.make_rcextensions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Whoosh indexing module for RhodeCode + make-rcext paster command for RhodeCode :created_on: Mar 6, 2012 :author: marcink @@ -29,26 +29,27 @@ import sys import pkg_resources import traceback import logging + from os.path import dirname as dn, join as jn - #to get the rhodecode import -sys.path.append(dn(dn(dn(os.path.realpath(__file__))))) +rc_path = dn(dn(dn(os.path.realpath(__file__)))) +sys.path.append(rc_path) -from rhodecode.lib.utils import BasePasterCommand, Command, ask_ok +from rhodecode.lib.utils import BasePasterCommand, ask_ok log = logging.getLogger(__name__) -class MakeRcExt(BasePasterCommand): +class Command(BasePasterCommand): max_args = 1 min_args = 1 usage = "CONFIG_FILE" - summary = "Creates additional extensions for rhodecode" group_name = "RhodeCode" takes_config_file = -1 - parser = Command.standard_parser(verbose=True) + parser = BasePasterCommand.standard_parser(verbose=True) + summary = "Creates additional extensions for rhodecode" def command(self): logging.config.fileConfig(self.path_to_ini_file) diff --git a/rhodecode/lib/paster_commands/repo_scan.py b/rhodecode/lib/paster_commands/repo_scan.py new file mode 100644 --- /dev/null +++ b/rhodecode/lib/paster_commands/repo_scan.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- +""" + rhodecode.lib.paster_commands.make_rcextensions + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + repo-scan paster command for RhodeCode + + + :created_on: Feb 9, 2013 + :author: marcink + :copyright: (C) 2010-2013 Marcin Kuzminski + :license: GPLv3, see COPYING for more details. +""" +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +from __future__ import with_statement + +import os +import sys +import logging + +from os.path import dirname as dn, join as jn +from rhodecode.model.scm import ScmModel +#to get the rhodecode import +rc_path = dn(dn(dn(os.path.realpath(__file__)))) +sys.path.append(rc_path) +from rhodecode.lib.utils import BasePasterCommand, repo2db_mapper + +from rhodecode.model.db import Repository +from rhodecode.model.repo import RepoModel +from rhodecode.model.meta import Session + + +log = logging.getLogger(__name__) + + +class Command(BasePasterCommand): + + max_args = 1 + min_args = 1 + + usage = "CONFIG_FILE" + group_name = "RhodeCode" + takes_config_file = -1 + parser = BasePasterCommand.standard_parser(verbose=True) + summary = "Rescan default location for new repositories" + + def command(self): + #get SqlAlchemy session + self._init_session() + rm_obsolete = self.options.delete_obsolete + log.info('Now scanning root location for new repos...') + added, removed = repo2db_mapper(ScmModel().repo_scan(), + remove_obsolete=rm_obsolete) + added = ','.join(added) or '-' + removed = ','.join(removed) or '-' + log.info('Scan completed added:%s removed:%s' % (added, removed)) + + def update_parser(self): + self.parser.add_option('--delete-obsolete', + action='store_true', + help="Use this flag do delete repositories that are " + "present in RhodeCode database but not on the filesystem", + ) diff --git a/rhodecode/config/setup_rhodecode.py b/rhodecode/lib/paster_commands/setup_rhodecode.py rename from rhodecode/config/setup_rhodecode.py rename to rhodecode/lib/paster_commands/setup_rhodecode.py --- a/rhodecode/config/setup_rhodecode.py +++ b/rhodecode/lib/paster_commands/setup_rhodecode.py @@ -1,26 +1,30 @@ import os +import sys from paste.script.appinstall import AbstractInstallCommand from paste.script.command import BadCommand from paste.deploy import appconfig +from os.path import dirname as dn, join as jn +#to get the rhodecode import +rc_path = dn(dn(dn(os.path.realpath(__file__)))) +sys.path.append(rc_path) -class SetupCommand(AbstractInstallCommand): + +class Command(AbstractInstallCommand): default_verbosity = 1 max_args = 1 min_args = 1 summary = "Setup an application, given a config file" usage = "CONFIG_FILE" + group_name = "RhodeCode" description = """\ - Note: this is an experimental command, and it will probably change - in several ways by the next release. - Setup an application according to its configuration file. This is + Setup RhodeCode according to its configuration file. This is the second part of a two-phase web application installation - process (the first phase is prepare-app). The setup process may - consist of things like creating directories and setting up - databases. + process (the first phase is prepare-app). The setup process + consist of things like setting up databases, creating super user """ parser = AbstractInstallCommand.standard_parser( diff --git a/rhodecode/lib/update_repoinfo.py b/rhodecode/lib/paster_commands/update_repoinfo.py rename from rhodecode/lib/update_repoinfo.py rename to rhodecode/lib/paster_commands/update_repoinfo.py --- a/rhodecode/lib/update_repoinfo.py +++ b/rhodecode/lib/paster_commands/update_repoinfo.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- """ - package.rhodecode.lib.cleanup - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + rhodecode.lib.paster_commands.make_rcextensions + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + uodate-repoinfo paster command for RhodeCode :created_on: Jul 14, 2012 :author: marcink @@ -24,47 +26,36 @@ from __future__ import with_statement import os import sys -import re -import shutil import logging -import datetime import string from os.path import dirname as dn, join as jn -from rhodecode.model import init_model -from rhodecode.lib.utils2 import engine_from_config +#to get the rhodecode import +rc_path = dn(dn(dn(os.path.realpath(__file__)))) +sys.path.append(rc_path) +from rhodecode.lib.utils import BasePasterCommand + from rhodecode.model.db import Repository from rhodecode.model.repo import RepoModel from rhodecode.model.meta import Session - -#to get the rhodecode import -sys.path.append(dn(dn(dn(os.path.realpath(__file__))))) - -from rhodecode.lib.utils import BasePasterCommand, Command, add_cache - log = logging.getLogger(__name__) -class UpdateCommand(BasePasterCommand): +class Command(BasePasterCommand): max_args = 1 min_args = 1 usage = "CONFIG_FILE" - summary = "Updates repositories caches for last changeset" group_name = "RhodeCode" takes_config_file = -1 - parser = Command.standard_parser(verbose=True) + parser = BasePasterCommand.standard_parser(verbose=True) + summary = "Updates repositories caches for last changeset" def command(self): - logging.config.fileConfig(self.path_to_ini_file) - from pylons import config - - #get to remove repos !! - add_cache(config) - engine = engine_from_config(config, 'sqlalchemy.db1.') - init_model(engine) + #get SqlAlchemy session + self._init_session() repo_update_list = map(string.strip, self.options.repo_update_list.split(',')) \ @@ -77,6 +68,7 @@ class UpdateCommand(BasePasterCommand): repo_list = Repository.getAll() RepoModel.update_repoinfo(repositories=repo_list) Session().commit() + log.info('Updated cache for %s repositories' % (len(repo_list))) def update_parser(self): self.parser.add_option('--update-only', diff --git a/rhodecode/lib/utils.py b/rhodecode/lib/utils.py --- a/rhodecode/lib/utils.py +++ b/rhodecode/lib/utils.py @@ -704,6 +704,20 @@ class BasePasterCommand(Command): conf = paste.deploy.appconfig('config:' + self.path_to_ini_file) pylonsconfig.init_app(conf.global_conf, conf.local_conf) + def _init_session(self): + """ + Inits SqlAlchemy Session + """ + logging.config.fileConfig(self.path_to_ini_file) + from pylons import config + from rhodecode.model import init_model + from rhodecode.lib.utils2 import engine_from_config + + #get to remove repos !! + add_cache(config) + engine = engine_from_config(config, 'sqlalchemy.db1.') + init_model(engine) + def check_git_version(): """ diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -158,11 +158,12 @@ setup( main = pylons.util:PylonsInstaller [paste.global_paster_command] - setup-rhodecode=rhodecode.config.setup_rhodecode:SetupCommand - cleanup-repos=rhodecode.lib.cleanup:CleanupCommand - update-repoinfo=rhodecode.lib.update_repoinfo:UpdateCommand + setup-rhodecode=rhodecode.lib.paster_commands.setup_rhodecode:Command + cleanup-repos=rhodecode.lib.paster_commands.cleanup:Command + update-repoinfo=rhodecode.lib.paster_commands.update_repoinfo:Command + make-rcext=rhodecode.lib.paster_commands.make_rcextensions:Command + repo-scan=rhodecode.lib.paster_commands.repo_scan:Command make-index=rhodecode.lib.indexers:MakeIndex - make-rcext=rhodecode.config.rcextensions.make_rcextensions:MakeRcExt upgrade-db=rhodecode.lib.dbmigrate:UpgradeDb celeryd=rhodecode.lib.celerypylons.commands:CeleryDaemonCommand """,