Ejemplo n.º 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)
Ejemplo n.º 2
0
    def _get_ui_authors(self):
        """Generates the list of displayable authors """
        repos = Repository(self.env)

        # Authors
        authors = sorted(repos.get_authors())
        authors.insert(0, '')

        return authors
Ejemplo n.º 3
0
    def _get_ui_branches(self, reverse=False):
        """Generates the list of displayable branches """
        repos = Repository(self.env)

        branches = repos.get_branch_names_with_prop()

        branches = sorted(branches, reverse=reverse, cmp=self.cmp_func)
        branches.insert(0, ('all', None))

        return branches
Ejemplo n.º 4
0
    def _process_log_request(self, req):
        '''
        Process log request information.

        This method is invoked when cursor is over a RevTree changeset,
        returning corresponding revision log information.

        :param req: Trac request object
        :returns: template, template data, type of response
        '''

        try:
            rev = int(req.args['logrev'])
            repos = Repository.get_svn_repository(self.env)
            if not repos:
                raise TracError("Revtree only supports Subversion "
                                "repositories")
            chgset = repos.get_changeset(rev)
            wikimsg = wiki_to_html(to_unicode(chgset.message),
                                   self.env,
                                   req,
                                   None,
                                   True,
                                   False)
            data = {
                'chgset': True,
                'revision': rev,
                'time': format_datetime(chgset.date).replace('()', ''),
                'age': pretty_timedelta(chgset.date, None, 3600),
                'author': to_unicode(chgset.author) or u'anonymous',
                'message': wikimsg
            }

            return 'revtree_log.html', {'log': data}, 'application/xhtml+xml'
        except Exception as e:
            raise TracError("Invalid revision log request: %s" % e)
Ejemplo n.º 5
0
    def _process_revtree(self, req):
        """Handle revtree generation requests"""
        tracrepos = self.env.get_repository()
        youngest = int(tracrepos.get_youngest_rev())
        oldest = max(self.oldest, int(tracrepos.get_oldest_rev()))
        if self.abstime:
            timebase = int(time.time())
        else:
            timebase = to_timestamp(tracrepos.get_changeset(youngest).date)
        revstore = RevtreeStore(self.env, req.authname, \
                                (oldest, youngest), 
                                timebase, self.style)
        if req.args.has_key('reset') and req.args['reset']:
            revstore.clear(req.session)
        else:
            revstore.load(req.session)
        if req.args:
            revstore.populate(req.args)
        revstore.compute_range(timebase)
        data = revstore.get_values()
                
        try:
            if not revstore.can_be_rendered():
                raise EmptyRangeError
            repos = Repository(self.env, req.authname)
            repos.build(self.bcre, revstore.revrange, revstore.timerange)
            (branches, authors) = \
                self._select_parameters(repos, req, revstore)
            svgrevtree = self.rt.get_revtree(repos, req)
            if revstore['branch']:
                sbranches = [revstore['branch']]
                sbranches.extend(filter(lambda t: t not in sbranches, 
                                        self.trunks))
            else:
                sbranches = None
            sauthors = revstore['author'] and [revstore['author']] or None
            if revstore['showdel']:
                hidetermbranch = False
            else:
                hidetermbranch = True
            svgrevtree.create(req, 
                              revisions=revstore.revrange, 
                              branches=sbranches, authors=sauthors, 
                              hidetermbranch=hidetermbranch, 
                              style=revstore['style'])
            svgrevtree.build()
            svgrevtree.render(self.scale*0.6)
            style = req.href.chrome('revtree/css/revtree.css')
            svgstyle = '<?xml-stylesheet href="%s" type="text/css"?>' % style
            data.update({
                'svg': Markup(unicode(str(svgrevtree), 'utf-8')),
                'svgstyle': Markup(svgstyle)
            })
            # create and order the drop-down list content, starting with the
            # global values 
            branches = repos.branches().keys()
            authors = repos.authors()
            # save the user parameters only if the tree can be rendered
            revstore.save(req.session)
        except EmptyRangeError:
            data.update({'errormsg': \
                         "Selected filters cannot render a revision tree"})
            # restore default parameters
            repos = Repository(self.env, req.authname)
            repos.build(self.bcre, revrange=(oldest, youngest))
            branches = repos.branches().keys()
            authors = repos.authors()
            
        revrange = repos.revision_range()
        revisions = self._get_ui_revisions((oldest, youngest), revrange)
        branches.sort()
        # prepend the trunks to the selected branches
        for b in filter(lambda t: t not in branches, self.trunks):
                branches.insert(0, b)
        branches = filter(None, branches)
        branches.insert(0, '')
        authors.sort()
        authors = filter(None, authors)
        authors.insert(0, '')

        dauthors = [dict(name=a, label=a or 'All') for a in authors]
        dbranches = [dict(name=b, label=b or 'All') for b in branches]
        
        data.update({
            'title': 'Revision Tree',
            'periods': self._get_periods(),
            'revmin': str(revrange[0]),
            'revmax': str(revrange[1]),
            'revisions': revisions,
            'branches': dbranches,
            'authors': dauthors
        })
                                                                               
        # add javascript for AJAX tooltips 
        add_script(req, 'revtree/js/svgtip.js')
        # add custom stylesheet
        add_stylesheet(req, 'revtree/css/revtree.css')
        return 'revtree.html', {'rt': data}, 'application/xhtml+xml'
Ejemplo n.º 6
0
    def _process_revtree(self, req):
        """Handle revtree generation requests"""
        tracrepos = self.env.get_repository()
        youngest = int(tracrepos.get_youngest_rev())
        oldest = max(self.oldest, int(tracrepos.get_oldest_rev()))
        if self.abstime:
            timebase = int(time.time())
        else:
            timebase = to_timestamp(tracrepos.get_changeset(youngest).date)
        revstore = RevtreeStore(self.env, req.authname, \
                                (oldest, youngest),
                                timebase, self.style)
        if req.args.has_key('reset') and req.args['reset']:
            revstore.clear(req.session)
        else:
            revstore.load(req.session)
        if req.args:
            revstore.populate(req.args)
        revstore.compute_range(timebase)
        data = revstore.get_values()

        try:
            if not revstore.can_be_rendered():
                raise EmptyRangeError
            repos = Repository(self.env, req.authname)
            repos.build(self.bcre, revstore.revrange, revstore.timerange)
            (branches, authors) = \
                self._select_parameters(repos, req, revstore)
            svgrevtree = self.rt.get_revtree(repos, req)
            if revstore['branch']:
                sbranches = [revstore['branch']]
                sbranches.extend(
                    filter(lambda t: t not in sbranches, self.trunks))
            else:
                sbranches = None
            sauthors = revstore['author'] and [revstore['author']] or None
            if revstore['showdel']:
                hidetermbranch = False
            else:
                hidetermbranch = True
            svgrevtree.create(req,
                              revisions=revstore.revrange,
                              branches=sbranches,
                              authors=sauthors,
                              hidetermbranch=hidetermbranch,
                              style=revstore['style'])
            svgrevtree.build()
            svgrevtree.render(self.scale * 0.6)
            style = req.href.chrome('revtree/css/revtree.css')
            svgstyle = '<?xml-stylesheet href="%s" type="text/css"?>' % style
            data.update({
                'svg': Markup(unicode(str(svgrevtree), 'utf-8')),
                'svgstyle': Markup(svgstyle)
            })
            # create and order the drop-down list content, starting with the
            # global values
            branches = repos.branches().keys()
            authors = repos.authors()
            # save the user parameters only if the tree can be rendered
            revstore.save(req.session)
        except EmptyRangeError:
            data.update({'errormsg': \
                         "Selected filters cannot render a revision tree"})
            # restore default parameters
            repos = Repository(self.env, req.authname)
            repos.build(self.bcre, revrange=(oldest, youngest))
            branches = repos.branches().keys()
            authors = repos.authors()

        revrange = repos.revision_range()
        revisions = self._get_ui_revisions((oldest, youngest), revrange)
        branches.sort()
        # prepend the trunks to the selected branches
        for b in filter(lambda t: t not in branches, self.trunks):
            branches.insert(0, b)
        branches = filter(None, branches)
        branches.insert(0, '')
        authors.sort()
        authors = filter(None, authors)
        authors.insert(0, '')

        dauthors = [dict(name=a, label=a or 'All') for a in authors]
        dbranches = [dict(name=b, label=b or 'All') for b in branches]

        data.update({
            'title': 'Revision Tree',
            'periods': self._get_periods(),
            'revmin': str(revrange[0]),
            'revmax': str(revrange[1]),
            'revisions': revisions,
            'branches': dbranches,
            'authors': dauthors
        })

        # add javascript for AJAX tooltips
        add_script(req, 'revtree/js/svgtip.js')
        # add custom stylesheet
        add_stylesheet(req, 'revtree/css/revtree.css')
        return 'revtree.html', {'rt': data}, 'application/xhtml+xml'
Ejemplo n.º 7
0
    def _process_revtree(self, req):
        """Handle revtree generation requests"""
        tracrepos = self.env.get_repository()
        youngest = int(tracrepos.get_youngest_rev())
        if self.abstime:
            timebase = int(time.time())
        else:
            timebase = int(tracrepos.get_changeset(youngest).date)
        revstore = RevtreeStore(self.env, req.authname, (self.oldest, youngest), timebase, self.style)
        revstore.load(req.session)
        revstore.populate(req.args)
        revstore.compute_range(timebase)

        # fill in the HDF
        for field in revstore.fields:
            req.hdf["revtree." + field] = revstore[field]
        req.hdf["title"] = "Revision Tree"
        req.hdf["revtree.periods"] = self._get_periods()

        # add javascript for AJAX tooltips
        add_script(req, "revtree/js/jquery.js")
        add_script(req, "revtree/js/svgtip.js")

        try:
            if not revstore.can_be_rendered():
                raise EmptyRangeError

            repos = Repository(self.env, req.authname)
            repos.build(self.bcre, revstore.revrange, revstore.timerange)

            (branches, authors) = self._select_parameters(repos, req, revstore)

            svgrevtree = RevtreeSystem(self.env).get_revtree(repos)
            svgrevtree.create(
                req,
                revstore.revrange,
                revstore.get_branches(),
                revstore.get_authors(),
                revstore.get_hidetermbranch(),
                revstore.get_style(),
            )
            svgrevtree.build()
            svgrevtree.render(self.scale * 0.6)
            req.hdf.set_unescaped("revtree.svg.image", str(svgrevtree))

            # create and order the drop-down list content, starting with the
            # global values
            branches = repos.branches().keys()
            authors = repos.authors()
            branches.sort()
            authors.sort()
            # prepend the trunks to the selected branches
            for b in self.trunks:
                if b not in branches:
                    branches.insert(0, b)
            branches.insert(0, revstore.anybranch)
            authors.insert(0, revstore.anyauthor)

            # save the user parameters only if the tree can be rendered
            revstore.save(req.session)

        except EmptyRangeError:
            req.hdf["revtree.errormsg"] = "Selected filters cannot render" " a revision tree"
            # restore default parameters
            repos = Repository(self.env, req.authname)
            repos.build(self.bcre, revrange=(self.oldest, youngest))
            branches = repos.branches().keys()
            branches.sort()
            branches.reverse()
            authors = repos.authors()
            authors.sort()

        revrange = repos.revision_range()
        revisions = self._get_ui_revisions((self.oldest, youngest), revrange)

        # fill in the HDF
        req.hdf["revtree.revmin"] = revrange[0]
        req.hdf["revtree.revmax"] = revrange[1]
        req.hdf["revtree.revisions"] = revisions
        req.hdf["revtree.branches"] = branches
        req.hdf["revtree.authors"] = authors

        add_stylesheet(req, "revtree/css/revtree.css")
        return "revtree.cs", "application/xhtml+xml"
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
    def _process_revtree(self, req):
        """Handle revtree generation requests"""
        tracrepos = self.env.get_repository()
        youngest = int(tracrepos.get_youngest_rev())
        if self.abstime:
            timebase = int(time.time())
        else:
            timebase = int(tracrepos.get_changeset(youngest).date)
        revstore = RevtreeStore(self.env, req.authname, \
                                (self.oldest, youngest),
                                timebase, self.style)
        revstore.load(req.session)
        revstore.populate(req.args)
        revstore.compute_range(timebase)

        # fill in the HDF
        for field in revstore.fields:
            req.hdf['revtree.' + field] = revstore[field]
        req.hdf['title'] = 'Revision Tree'
        req.hdf['revtree.periods'] = self._get_periods()

        # add javascript for AJAX tooltips
        add_script(req, 'revtree/js/jquery.js')
        add_script(req, 'revtree/js/svgtip.js')

        try:
            if not revstore.can_be_rendered():
                raise EmptyRangeError

            repos = Repository(self.env, req.authname)
            repos.build(self.bcre, revstore.revrange, revstore.timerange)

            (branches, authors) = \
                self._select_parameters(repos, req, revstore)

            svgrevtree = RevtreeSystem(self.env).get_revtree(repos)
            svgrevtree.create(req, revstore.revrange, revstore.get_branches(),
                              revstore.get_authors(),
                              revstore.get_hidetermbranch(),
                              revstore.get_style())
            svgrevtree.build()
            svgrevtree.render(self.scale * 0.6)
            req.hdf.set_unescaped('revtree.svg.image', str(svgrevtree))

            # create and order the drop-down list content, starting with the
            # global values
            branches = repos.branches().keys()
            authors = repos.authors()
            branches.sort()
            authors.sort()
            # prepend the trunks to the selected branches
            for b in self.trunks:
                if b not in branches:
                    branches.insert(0, b)
            branches.insert(0, revstore.anybranch)
            authors.insert(0, revstore.anyauthor)

            # save the user parameters only if the tree can be rendered
            revstore.save(req.session)

        except EmptyRangeError:
            req.hdf['revtree.errormsg'] = "Selected filters cannot render" \
                                          " a revision tree"
            # restore default parameters
            repos = Repository(self.env, req.authname)
            repos.build(self.bcre, revrange=(self.oldest, youngest))
            branches = repos.branches().keys()
            branches.sort()
            branches.reverse()
            authors = repos.authors()
            authors.sort()

        revrange = repos.revision_range()
        revisions = self._get_ui_revisions((self.oldest, youngest), revrange)

        # fill in the HDF
        req.hdf['revtree.revmin'] = revrange[0]
        req.hdf['revtree.revmax'] = revrange[1]
        req.hdf['revtree.revisions'] = revisions
        req.hdf['revtree.branches'] = branches
        req.hdf['revtree.authors'] = authors

        add_stylesheet(req, 'revtree/css/revtree.css')
        return 'revtree.cs', 'application/xhtml+xml'