Пример #1
0
    def _get_ui_revisions(self, reverse=True):
        """Generates the list of displayable revisions"""
        repos = Repository(self.env)

        revmin = repos.get_oldest_rev()
        revmax = repos.get_youngest_rev()

        revisions = []
        for rev in xrange(int(revmax), int(revmin) - 1, -1):
#             if len(revisions) > 50:
#                 if rev % 100:
#                     continue
#             elif len(revisions) > 30:
#                 if rev % 20:
#                     continue
#             elif len(revisions) > 10:
#                 if rev % 10:
#                     continue

            revisions.append(rev)

        if revisions[-1] != int(revmin):
            revisions.append(int(revmin))

        return sorted(revisions, reverse=reverse)
Пример #2
0
    def _process_filter_request(self, req):
        '''
        Process filter request.

        This method is invoked when RevTree update is done by user.

        :param req: Trac request object
        '''
        session_ctx = SessionContext(req)

        # Reset clause
        if req.args.get("reset"):
            session_ctx.clear()

            dump = json.dumps(dict())

            # Send response
            req.send_response(200)
            req.send_header('Content-Type', "application/json")
            req.send_header('Content-Length', len(dump))
            req.write(dump);
            return

        for key in ['query_options', 'query_filters']:
            if key not in req.args:
                continue
            return self._process_query_filters_options(req,
                                                       key,
                                                       req.args[key])

        # Repository object
        repos = Repository(self.env)

        if self.abstime:
            timebase = int(time.time())
        else:
            youngest = repos.get_youngest_rev()
            timebase = to_timestamp(repos.get_changeset(youngest).date)

        # Style options
        style = req.args.get('style', 'compact')

        try:
            # Generate query
            query = QueryFilter(self.env,
                                repos,
                                req.args)

            # Update session context information
            session_ctx['query'] = query.export()
            session_ctx['style'] = style

            svgbranches, revisions, filtered_revisions = \
                self._process_query(repos,
                                    query,
                                    timebase)
            if (not svgbranches) or (not revisions):
                raise EmptyRangeError('')

            repos = Repository(self.env)

            # MANDATORY: revisions must be sorted in reversed order
            revisions.sort(reverse=True, key=lambda t: t[0])

            # SVG revision tree object
            svgrevtree = self.rt.get_revtree(repos, req)
            svgrevtree.create(req,
                              svgbranches,
                              revisions,
                              filtered_revisions,
                              style)

            svgrevtree.build()
        except EmptyRangeError as excpt:
            msg = _('Selected filters cannot '
                    'render a revision tree. %s' % excpt.message.encode('utf8'))
            msg = msg.encode('UTF-8')
            req.send_response(404)
            req.send_header('Content-Type', "text/html; charset=utf-8'")
            req.send_header('Content-Length', len(msg))
            req.write(msg)
        else:
            data = dict(revisions=self._get_ui_revisions(),
                        authors=self._get_ui_authors(),
                        # branches=self._get_ui_branches(reverse=False),
                        fontsize=self.env.config.get('revtree',
                                                     'fontsize',
                                                     '14pt'),
                        fontfamily=self.env.config.get('revtree',
                                                       'fontname',
                                                       'arial'),
                        tree=dict(brc=svgrevtree.export(),
                                  max_rev=svgrevtree.max_rev),
                        url=req.href(),
                        style=style)
            dump = json.dumps(data)

            # Send response
            req.send_response(200)
            req.send_header('Content-Type', "application/json")
            req.send_header('Content-Length', len(dump))
            req.write(dump)