Changeset - f1491bad8339
[Not reviewed]
beta
4 2 6
Marcin Kuzminski - 13 years ago 2013-02-09 22:21:31
marcin@python-works.com
unified RhodeCode paster commands
- moved them to commont paster_commands package
- re-use sqlalchemy session initializaiton
- some docs updates
8 files changed with 144 insertions and 62 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/paster_commands/__init__.py
Show inline comments
 
new file 100644
rhodecode/lib/paster_commands/cleanup.py
Show inline comments
 
file renamed from rhodecode/lib/cleanup.py to rhodecode/lib/paster_commands/cleanup.py
 
# -*- 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<days>\d+?)d)?((?P<hours>\d+?)h)?((?P<minutes>\d+?)m)?((?P<seconds>\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 = []
rhodecode/lib/paster_commands/make_rcextensions.py
Show inline comments
 
file renamed from rhodecode/config/rcextensions/make_rcextensions.py to rhodecode/lib/paster_commands/make_rcextensions.py
 
# -*- 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)
rhodecode/lib/paster_commands/repo_scan.py
Show inline comments
 
new file 100644
 
# -*- 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 <marcin@python-works.com>
 
    :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 <http://www.gnu.org/licenses/>.
 
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",
 
                          )
rhodecode/lib/paster_commands/setup_rhodecode.py
Show inline comments
 
file renamed from rhodecode/config/setup_rhodecode.py to rhodecode/lib/paster_commands/setup_rhodecode.py
 
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(
rhodecode/lib/paster_commands/update_repoinfo.py
Show inline comments
 
file renamed from rhodecode/lib/update_repoinfo.py to rhodecode/lib/paster_commands/update_repoinfo.py
 
# -*- 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',
rhodecode/lib/utils.py
Show inline comments
 
@@ -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():
 
    """
setup.py
Show inline comments
 
@@ -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
 
    """,
0 comments (0 inline, 0 general)