[viewvc-dev] GNU Enscript and ViewVC 1.1...or Pygments

Sandy Pérez González <[email protected]>
Newsgroups gmane.comp.version-control.cvs.viewcvs.devel
Organization Onekin
Message-ID <405005744.20080523183322__38922.0896563076$1211560483$gmane$org@yahoo.es>
After some attempts, now GNU Enscript works fine using the ViewVC’s
standalone server. When I try to access through Apache it does not
work. Definitely, I threw in the towel with GNU Enscript and Apache.

But, I have made another attempt with Pygments (http://pygments.org/).
And, again, it works fine using the ViewVC’s standalone server but not
using Apache. So, I think both (GNU Enscript and Pygments) are fine as
well as ViewVC. In my opinion, what is wrong is Apache’s mod_python or
some of its dependencies.

To integrate Pygments with ViewVC I did some changes in the ViewVC’s
code. If GNU Enscript works fine for somebody, then, my changes for
integrate Pygments with ViewVC could work fine for somebody too. So, I
describe my changes here for these people interested in integrating
ViewVC and Pygments.

CHANGES:
---------------

In file <VIEWVC_HOME>/lib/viewvc.py, just after the declaration of
“MarkupEnscript” class, I added the following class:
###################################################
class MarkupPygments(MarkupShell):
  def __init__(self, cfg, fp, filename):
    pygments_cmd = [cfg.utilities.pygments or 'pygmentize',
                    '-f', 'html']
    
    if cfg.options.pygments_line_numbers:
        pygments_cmd.extend(['-O', 'noclasses=1,style=colorful,linenos=1', ''])
    else:
        pygments_cmd.extend(['-O', 'noclasses=1,style=colorful', ''])
      
    MarkupShell.__init__(self, cfg, fp, [pygments_cmd])
    self.filename = filename
    self.cfg = cfg

  def __call__(self, ctx):
    dir = compat.mkdtemp("", "viewvc")
    try:
      file = os.path.join(dir, self.filename)
      try:
        copy_stream(self.fp, open(file, 'wb'), self.cfg)
        self.fp.close()
        self.fp = None
        self.cmds[0][-1] = file
        MarkupShell.__call__(self, ctx)
      finally:
        os.unlink(file)
    finally:
      os.rmdir(dir)
###################################################

And, in the definition of “markup_or_annotate”, I modified the following “if” statement with the two last lines.
###################################################
      if not markup_fp:
        if cfg.options.use_enscript:
          markup_fp = MarkupEnscript(cfg, fp, request.path_parts[-1])
        elif cfg.options.use_highlight:
          markup_fp = MarkupHighlight(cfg, fp, request.path_parts[-1])
        elif cfg.options.use_source_highlight:
          markup_fp = MarkupSourceHighlight(cfg, fp, request.path_parts[-1])
        elif cfg.options.use_pygments:
          markup_fp = MarkupPygments(cfg, fp, request.path_parts[-1])
###################################################

In file <VIEWVC_HOME>/viewvc.conf, in “utilities” section, I added the following:
###################################################
# Pygments, a syntax highlighting program (see options.use_pygments)
pygments = 
# pygments = /usr/bin/pigments
###################################################

And in “options” section, I added the Pygments’ options:
###################################################
# should we use 'enscript' for syntax coloring?
use_enscript = 0

# should we use 'pygments' for syntax coloring?
# NOTE: use_enscript has to be 0 or enscript will be used instead
use_pygments = 1

# should we add line numbers?
pygments_line_numbers = 1

# should we use 'highlight' for syntax coloring?
# NOTE: use_enscript and use_pygments have to be 0
use_highlight = 0

# should we add line numbers?
highlight_line_numbers = 1

# convert tabs to ## spaces (use 0 for no conversion)
highlight_convert_tabs = 2

# should we use 'source-highlight' for syntax coloring?
# NOTE: use_enscript, use_pygments and use_highlight have to be 0
use_source_highlight = 0

# should we add line numbers?
source_highlight_line_numbers = 1
###################################################

These changes work fine using the ViewVC’s standalone server. So, I
think they could work fine for somebody, good luck. Pygments is a very
good code hightlighter, I enclose two screenshots.

Best regards,
   Sandy

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
xml.png (image/png, 27 KB) - not displayed
java.png (image/png, 33.6 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.