Esempio n. 1
0
    def __get_readme_data(self, repo_name, repo):

        @cache_region('long_term')
        def _get_readme_from_cache(key):
            readme_data = None
            readme_file = None
            log.debug('Fetching readme file')
            try:
                cs = repo.get_changeset()  # fetches TIP
                renderer = MarkupRenderer()
                for f in README_FILES:
                    try:
                        readme = cs.get_node(f)
                        readme_file = f
                        readme_data = renderer.render(readme.content, f)
                        log.debug('Found readme %s' % readme_file)
                        break
                    except NodeDoesNotExistError:
                        continue
            except ChangesetError:
                log.error(traceback.format_exc())
                pass
            except EmptyRepositoryError:
                pass
            except Exception:
                log.error(traceback.format_exc())

            return readme_data, readme_file

        key = repo_name + '_README'
        inv = CacheInvalidation.invalidate(key)
        if inv is not None:
            region_invalidate(_get_readme_from_cache, None, key)
            CacheInvalidation.set_valid(inv.cache_key)
        return _get_readme_from_cache(key)
Esempio n. 2
0
    def rss(self, repo_name):
        """Produce an rss2 feed via feedgenerator module"""

        @cache_region('long_term')
        def _get_feed_from_cache(key):
            feed = Rss201rev2Feed(
                title=self.title % repo_name,
                link=url('summary_home', repo_name=repo_name,
                         qualified=True),
                description=self.description % repo_name,
                language=self.language,
                ttl=self.ttl
            )

            for cs in reversed(list(c.rhodecode_repo[-self.feed_nr:])):
                feed.add_item(title=self._get_title(cs),
                              link=url('changeset_home', repo_name=repo_name,
                                       revision=cs.raw_id, qualified=True),
                              author_name=cs.author,
                              description=''.join(self.__get_desc(cs)),
                              pubdate=cs.date,
                             )

            response.content_type = feed.mime_type
            return feed.writeString('utf-8')

        key = repo_name + '_RSS'
        inv = CacheInvalidation.invalidate(key)
        if inv is not None:
            region_invalidate(_get_feed_from_cache, None, key)
            CacheInvalidation.set_valid(inv.cache_key)
        return _get_feed_from_cache(key)
Esempio n. 3
0
    def __get_readme_data(self, repo_name, repo):
        @cache_region('long_term')
        def _get_readme_from_cache(key):
            readme_data = None
            readme_file = None
            log.debug('Fetching readme file')
            try:
                cs = repo.get_changeset()  # fetches TIP
                renderer = MarkupRenderer()
                for f in README_FILES:
                    try:
                        readme = cs.get_node(f)
                        readme_file = f
                        readme_data = renderer.render(readme.content, f)
                        log.debug('Found readme %s' % readme_file)
                        break
                    except NodeDoesNotExistError:
                        continue
            except ChangesetError:
                log.error(traceback.format_exc())
                pass
            except EmptyRepositoryError:
                pass
            except Exception:
                log.error(traceback.format_exc())

            return readme_data, readme_file

        key = repo_name + '_README'
        inv = CacheInvalidation.invalidate(key)
        if inv is not None:
            region_invalidate(_get_readme_from_cache, None, key)
            CacheInvalidation.set_valid(inv.cache_key)
        return _get_readme_from_cache(key)
Esempio n. 4
0
    def rss(self, repo_name):
        """Produce an rss2 feed via feedgenerator module"""

        @cache_region('long_term')
        def _get_feed_from_cache(key):
            feed = Rss201rev2Feed(
                title=self.title % repo_name,
                link=url('summary_home', repo_name=repo_name,
                         qualified=True),
                description=self.description % repo_name,
                language=self.language,
                ttl=self.ttl
            )

            for cs in reversed(list(c.rhodecode_repo[-self.feed_nr:])):
                feed.add_item(title=self._get_title(cs),
                              link=url('changeset_home', repo_name=repo_name,
                                       revision=cs.raw_id, qualified=True),
                              author_name=cs.author,
                              description=''.join(self.__get_desc(cs)),
                              pubdate=cs.date,
                             )

            response.content_type = feed.mime_type
            return feed.writeString('utf-8')

        key = repo_name + '_RSS'
        inv = CacheInvalidation.invalidate(key)
        if inv is not None:
            region_invalidate(_get_feed_from_cache, None, key)
            CacheInvalidation.set_valid(inv.cache_key)
        return _get_feed_from_cache(key)
Esempio n. 5
0
    def __get_readme_data(self, db_repo):
        repo_name = db_repo.repo_name

        @cache_region('long_term')
        def _get_readme_from_cache(key):
            readme_data = None
            readme_file = None
            log.debug('Looking for README file')
            try:
                # get's the landing revision! or tip if fails
                cs = db_repo.get_landing_changeset()
                if isinstance(cs, EmptyChangeset):
                    raise EmptyRepositoryError()
                renderer = MarkupRenderer()
                for f in README_FILES:
                    try:
                        readme = cs.get_node(f)
                        if not isinstance(readme, FileNode):
                            continue
                        readme_file = f
                        log.debug('Found README file `%s` rendering...' %
                                  readme_file)
                        readme_data = renderer.render(readme.content, f)
                        break
                    except NodeDoesNotExistError:
                        continue
            except ChangesetError:
                log.error(traceback.format_exc())
                pass
            except EmptyRepositoryError:
                pass
            except Exception:
                log.error(traceback.format_exc())

            return readme_data, readme_file

        key = repo_name + '_README'
        inv = CacheInvalidation.invalidate(key)
        if inv is not None:
            region_invalidate(_get_readme_from_cache, None, key)
            CacheInvalidation.set_valid(inv.cache_key)
        return _get_readme_from_cache(key)
Esempio n. 6
0
    def __get_readme_data(self, db_repo):
        repo_name = db_repo.repo_name

        @cache_region('long_term')
        def _get_readme_from_cache(key):
            readme_data = None
            readme_file = None
            log.debug('Looking for README file')
            try:
                # get's the landing revision! or tip if fails
                cs = db_repo.get_landing_changeset()
                if isinstance(cs, EmptyChangeset):
                    raise EmptyRepositoryError()
                renderer = MarkupRenderer()
                for f in README_FILES:
                    try:
                        readme = cs.get_node(f)
                        if not isinstance(readme, FileNode):
                            continue
                        readme_file = f
                        log.debug('Found README file `%s` rendering...' %
                                  readme_file)
                        readme_data = renderer.render(readme.content, f)
                        break
                    except NodeDoesNotExistError:
                        continue
            except ChangesetError:
                log.error(traceback.format_exc())
                pass
            except EmptyRepositoryError:
                pass
            except Exception:
                log.error(traceback.format_exc())

            return readme_data, readme_file

        key = repo_name + '_README'
        inv = CacheInvalidation.invalidate(key)
        if inv is not None:
            region_invalidate(_get_readme_from_cache, None, key)
            CacheInvalidation.set_valid(inv.cache_key)
        return _get_readme_from_cache(key)
Esempio n. 7
0
def repo2db_mapper(initial_repo_list, remove_obsolete=False,
                   install_git_hook=False):
    """
    maps all repos given in initial_repo_list, non existing repositories
    are created, if remove_obsolete is True it also check for db entries
    that are not in initial_repo_list and removes them.

    :param initial_repo_list: list of repositories found by scanning methods
    :param remove_obsolete: check for obsolete entries in database
    :param install_git_hook: if this is True, also check and install githook
        for a repo if missing
    """
    from rhodecode.model.repo import RepoModel
    from rhodecode.model.scm import ScmModel
    sa = meta.Session()
    rm = RepoModel()
    user = sa.query(User).filter(User.admin == True).first()
    if user is None:
        raise Exception('Missing administrative account!')
    added = []

#    # clear cache keys
#    log.debug("Clearing cache keys now...")
#    CacheInvalidation.clear_cache()
#    sa.commit()

    for name, repo in initial_repo_list.items():
        group = map_groups(name)
        db_repo = rm.get_by_repo_name(name)
        # found repo that is on filesystem not in RhodeCode database
        if not db_repo:
            log.info('repository %s not found, creating now' % name)
            added.append(name)
            desc = (repo.description
                    if repo.description != 'unknown'
                    else '%s repository' % name)
            new_repo = rm.create_repo(
                repo_name=name,
                repo_type=repo.alias,
                description=desc,
                repos_group=getattr(group, 'group_id', None),
                owner=user,
                just_db=True
            )
            # we added that repo just now, and make sure it has githook
            # installed
            if new_repo.repo_type == 'git':
                ScmModel().install_git_hook(new_repo.scm_instance)
        elif install_git_hook:
            if db_repo.repo_type == 'git':
                ScmModel().install_git_hook(db_repo.scm_instance)
        # during starting install all cache keys for all repositories in the
        # system, this will register all repos and multiple instances
        key, _prefix, _org_key = CacheInvalidation._get_key(name)
        CacheInvalidation.invalidate(name)
        log.debug("Creating a cache key for %s instance_id=>`%s`"
                  % (name, _prefix or '-'))

    sa.commit()
    removed = []
    if remove_obsolete:
        # remove from database those repositories that are not in the filesystem
        for repo in sa.query(Repository).all():
            if repo.repo_name not in initial_repo_list.keys():
                log.debug("Removing non-existing repository found in db `%s`" %
                          repo.repo_name)
                try:
                    sa.delete(repo)
                    sa.commit()
                    removed.append(repo.repo_name)
                except:
                    #don't hold further removals on error
                    log.error(traceback.format_exc())
                    sa.rollback()

    return added, removed
Esempio n. 8
0
def repo2db_mapper(initial_repo_list,
                   remove_obsolete=False,
                   install_git_hook=False):
    """
    maps all repos given in initial_repo_list, non existing repositories
    are created, if remove_obsolete is True it also check for db entries
    that are not in initial_repo_list and removes them.

    :param initial_repo_list: list of repositories found by scanning methods
    :param remove_obsolete: check for obsolete entries in database
    :param install_git_hook: if this is True, also check and install githook
        for a repo if missing
    """
    from rhodecode.model.repo import RepoModel
    from rhodecode.model.scm import ScmModel
    sa = meta.Session()
    rm = RepoModel()
    user = sa.query(User).filter(User.admin == True).first()
    if user is None:
        raise Exception('Missing administrative account!')
    added = []

    ##creation defaults
    defs = RhodeCodeSetting.get_default_repo_settings(strip_prefix=True)
    enable_statistics = defs.get('repo_enable_statistics')
    enable_locking = defs.get('repo_enable_locking')
    enable_downloads = defs.get('repo_enable_downloads')
    private = defs.get('repo_private')

    for name, repo in initial_repo_list.items():
        group = map_groups(name)
        db_repo = rm.get_by_repo_name(name)
        # found repo that is on filesystem not in RhodeCode database
        if not db_repo:
            log.info('repository %s not found, creating now' % name)
            added.append(name)
            desc = (repo.description if repo.description != 'unknown' else
                    '%s repository' % name)

            new_repo = rm.create_repo(repo_name=name,
                                      repo_type=repo.alias,
                                      description=desc,
                                      repos_group=getattr(
                                          group, 'group_id', None),
                                      owner=user,
                                      just_db=True,
                                      enable_locking=enable_locking,
                                      enable_downloads=enable_downloads,
                                      enable_statistics=enable_statistics,
                                      private=private)
            # we added that repo just now, and make sure it has githook
            # installed
            if new_repo.repo_type == 'git':
                ScmModel().install_git_hook(new_repo.scm_instance)
            new_repo.update_changeset_cache()
        elif install_git_hook:
            if db_repo.repo_type == 'git':
                ScmModel().install_git_hook(db_repo.scm_instance)
        # during starting install all cache keys for all repositories in the
        # system, this will register all repos and multiple instances
        cache_key = CacheInvalidation._get_cache_key(name)
        log.debug("Creating invalidation cache key for %s: %s", name,
                  cache_key)
        CacheInvalidation.invalidate(name)

    sa.commit()
    removed = []
    if remove_obsolete:
        # remove from database those repositories that are not in the filesystem
        for repo in sa.query(Repository).all():
            if repo.repo_name not in initial_repo_list.keys():
                log.debug("Removing non-existing repository found in db `%s`" %
                          repo.repo_name)
                try:
                    sa.delete(repo)
                    sa.commit()
                    removed.append(repo.repo_name)
                except Exception:
                    #don't hold further removals on error
                    log.error(traceback.format_exc())
                    sa.rollback()
    return added, removed