↓ Skip to main content
  1. Blog/

Cfengine3 lexer for Pygments

·226 words·2 mins·
Diego Zamboni
Author
Diego Zamboni

I have written a Cfengine3 lexer for Pygments, the open source syntax-highlighter used by Gist and many other sites. It seems to work fine on all the cfengine policy files I have tested, but if you find anything that doesn't quite work as expected, please let me know. This is my first-ever Pygments lexer, so if you are an expert and can advise me on better ways of doing things, I'd very much appreciate the feedback too.

Update: Since version 1.5, Pygments includes this lexer. If you are using 1.5 or later, you already have the CFEngine lexer. You can sometimes find a newer version of the lexer in my fork of the Pygments project (updates are infrequent, only when there are changes in the CFEngine language).

Here's how to install it (again, I don't know if this is the better or easier way):
  1. Obtain the Pygments source code.
  2. Put the pygments_cfengine_lexer.py file into the pygments/lexers/ directory
  3. run (cd pygments/lexers; python _mapping.py)
  4. run ./setup.py install

If you already have Pygments installed, you should follow these instructions:

  1. Put the pygments_cfengine_lexer.py file in the installed pygments/lexers/ directory (on my Mac, this is /Library/Python/2.6/site-packages/Pygments-1.4-py2.6.egg/pygments/lexers, under Linux it should be something like /usr/lib/python2.6/site-packages/Pygments..../pygments/lexers)
  2. cd into that directory
  3. run "python _mapping.py"

Then run pygmentize on any .cf file, and it should output properly highlighted code. You can view a sample here.

CFEngine talks at PICC'12 conference

·159 words·1 min
There will be several CFEngine-related classes and talks at the PICC'12 conference (Professional IT Community Conference) on May 11-12th, in New Jersey. I will be talking about using CFEngine as part of your security infrastructure. My colleague Joe Netzel will be talking about migration from CFEngine 2 to CFEngine 3, so if you are using CF2 and have been considering (or dreading) the migration, make sure to come by! Aleksey Tsalolikhin will give an introductory class to CFEngine. And Mark Burgess will give a class not related to CFEngine, but to the perils and skills needed to survive as a technical person in the "business world".