Ejemplo n.º 1
0
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 = "Interactive shell"

    def command(self):
        #get SqlAlchemy session
        self._init_session()

        # imports, used in ipython shell
        import os
        import sys
        import time
        import shutil
        import datetime
        from rhodecode.model.db import *

        try:
            from IPython import embed
            from IPython.config.loader import Config
            cfg = Config()
            cfg.InteractiveShellEmbed.confirm_exit = False
            embed(config=cfg, banner1="RhodeCode IShell.")
        except ImportError:
            print 'ipython installation required for ishell'
            sys.exit(-1)

    def update_parser(self):
        pass
Ejemplo n.º 2
0
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",
        )
Ejemplo n.º 3
0
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 = "Updates repositories caches for last changeset"

    def command(self):
        #get SqlAlchemy session
        self._init_session()

        repo_update_list = map(string.strip,
                               self.options.repo_update_list.split(',')) \
                               if self.options.repo_update_list else None

        if repo_update_list:
            repo_list = Repository.query()\
                .filter(Repository.repo_name.in_(repo_update_list))
        else:
            repo_list = Repository.getAll()
        RepoModel.update_repoinfo(repositories=repo_list)
        Session().commit()

        if self.options.invalidate_cache:
            for r in repo_list:
                r.set_invalidate()
        log.info('Updated cache for %s repositories' % (len(repo_list)))

    def update_parser(self):
        self.parser.add_option(
            '--update-only',
            action='store',
            dest='repo_update_list',
            help="Specifies a comma separated list of repositores "
            "to update last commit info for. OPTIONAL")
        self.parser.add_option(
            '--invalidate-cache',
            action='store_true',
            dest='invalidate_cache',
            help="Trigger cache invalidation event for repos. "
            "OPTIONAL")
Ejemplo n.º 4
0
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 = "Cache keys utils"

    def command(self):
        #get SqlAlchemy session
        self._init_session()
        _caches = CacheInvalidation.query().order_by(
            CacheInvalidation.cache_key).all()
        if self.options.show:
            for c_obj in _caches:
                print 'key:%s active:%s' % (c_obj.cache_key,
                                            c_obj.cache_active)
        elif self.options.cleanup:
            for c_obj in _caches:
                Session().delete(c_obj)
                print 'removing key:%s' % (c_obj.cache_key)
            Session().commit()
        else:
            print 'nothing done exiting...'
        sys.exit(0)

    def update_parser(self):
        self.parser.add_option(
            '--show',
            action='store_true',
            dest='show',
            help=("show existing cache keys with together with status"))

        self.parser.add_option('--cleanup',
                               action="store_true",
                               dest="cleanup",
                               help="cleanup existing cache keys")
Ejemplo n.º 5
0
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 = "Creates additional extensions for rhodecode"

    def command(self):
        logging.config.fileConfig(self.path_to_ini_file)
        from pylons import config

        def _make_file(ext_file, tmpl):
            bdir = os.path.split(ext_file)[0]
            if not os.path.isdir(bdir):
                os.makedirs(bdir)
            with open(ext_file, 'wb') as f:
                f.write(tmpl)
                log.info('Writen new extensions file to %s' % ext_file)

        here = config['here']
        tmpl = pkg_resources.resource_string(
            'rhodecode', jn('config', 'rcextensions', '__init__.py'))
        ext_file = jn(here, 'rcextensions', '__init__.py')
        if os.path.exists(ext_file):
            msg = ('Extension file already exists, do you want '
                   'to overwrite it ? [y/n]')
            if ask_ok(msg):
                _make_file(ext_file, tmpl)
            else:
                log.info('nothing done...')
        else:
            _make_file(ext_file, tmpl)

    def update_parser(self):
        pass
Ejemplo n.º 6
0
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 = "Creates or updates full text search index"

    def command(self):
        logging.config.fileConfig(self.path_to_ini_file)
        #get SqlAlchemy session
        self._init_session()
        from pylons import config
        index_location = config['index_dir']
        load_rcextensions(config['here'])

        repo_location = self.options.repo_location \
            if self.options.repo_location else RepoModel().repos_path
        repo_list = map(strip, self.options.repo_list.split(',')) \
            if self.options.repo_list else None

        repo_update_list = map(strip, self.options.repo_update_list.split(',')) \
            if self.options.repo_update_list else None

        #======================================================================
        # WHOOSH DAEMON
        #======================================================================
        from rhodecode.lib.pidlock import LockHeld, DaemonLock
        from rhodecode.lib.indexers.daemon import WhooshIndexingDaemon
        try:
            l = DaemonLock(
                file_=os.path.join(dn(dn(index_location)), 'make_index.lock'))
            WhooshIndexingDaemon(index_location=index_location,
                                 repo_location=repo_location,
                                 repo_list=repo_list,
                                 repo_update_list=repo_update_list)\
                .run(full_index=self.options.full_index)
            l.release()
        except LockHeld:
            sys.exit(1)

    def update_parser(self):
        self.parser.add_option(
            '--repo-location',
            action='store',
            dest='repo_location',
            help="Specifies repositories location to index OPTIONAL",
        )
        self.parser.add_option(
            '--index-only',
            action='store',
            dest='repo_list',
            help="Specifies a comma separated list of repositores "
            "to build index on. If not given all repositories "
            "are scanned for indexing. OPTIONAL",
        )
        self.parser.add_option(
            '--update-only',
            action='store',
            dest='repo_update_list',
            help="Specifies a comma separated list of repositores "
            "to re-build index on. OPTIONAL",
        )
        self.parser.add_option(
            '-f',
            action='store_true',
            dest='full_index',
            help="Specifies that index should be made full i.e"
            " destroy old and build from scratch",
            default=False)
Ejemplo n.º 7
0
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 = "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)?')
        parts = regex.match(val)
        if not parts:
            return
        parts = parts.groupdict()
        time_params = {}
        for (name, param) in parts.iteritems():
            if param:
                time_params[name] = int(param)
        return datetime.timedelta(**time_params)

    def _extract_date(self, name):
        """
        Extract the date part from rm__<date> pattern of removed repos,
        and convert it to datetime object

        :param name:
        """
        date_part = name[4:19]  # 4:19 since we don't parse milisecods
        return datetime.datetime.strptime(date_part, '%Y%m%d_%H%M%S')

    def command(self):
        #get SqlAlchemy session
        self._init_session()

        repos_location = RhodeCodeUi.get_repos_location()
        to_remove = []
        for dn, dirs, f in os.walk(safe_str(repos_location)):
            alldirs = list(dirs)
            del dirs[:]
            if ('.hg' in alldirs or
                'objects' in alldirs and ('refs' in alldirs or 'packed-refs' in f)):
                continue
            for loc in alldirs:
                if REMOVED_REPO_PAT.match(loc):
                    to_remove.append([os.path.join(dn, loc),
                                      self._extract_date(loc)])
                else:
                    dirs.append(loc)

        #filter older than (if present)!
        now = datetime.datetime.now()
        older_than = self.options.older_than
        if older_than:
            to_remove_filtered = []
            older_than_date = self._parse_older_than(older_than)
            for name, date_ in to_remove:
                repo_age = now - date_
                if repo_age > older_than_date:
                    to_remove_filtered.append([name, date_])

            to_remove = to_remove_filtered
            print >> sys.stdout, 'removing %s deleted repos older than %s (%s)' \
                % (len(to_remove), older_than, older_than_date)
        else:
            print >> sys.stdout, 'removing all [%s] deleted repos' \
                % len(to_remove)
        if self.options.dont_ask or not to_remove:
            # don't ask just remove !
            remove = True
        else:
            remove = ask_ok('the following repositories will be deleted completely:\n%s\n'
                            'are you sure you want to remove them [y/n]?'
                            % ', \n'.join(['%s removed on %s'
                    % (safe_str(x[0]), safe_str(x[1])) for x in to_remove]))

        if remove:
            for path, date_ in to_remove:
                print >> sys.stdout, 'removing repository %s' % path
                shutil.rmtree(path)
        else:
            print 'nothing done exiting...'
            sys.exit(0)

    def update_parser(self):
        self.parser.add_option(
            '--older-than',
            action='store',
            dest='older_than',
            help=("only remove repos that have been removed "
                 "at least given time ago. "
                 "The default is to remove all removed repositories. "
                 "Possible suffixes: "
                 "d (days), h (hours), m (minutes), s (seconds). "
                 "For example --older-than=30d deletes repositories "
                 "removed more than 30 days ago.")
            )

        self.parser.add_option(
            '--dont-ask',
            action="store_true",
            dest="dont_ask",
            help="remove repositories without asking for confirmation."
        )