<?xml version="1.0" encoding="utf-8"?>

<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
<title type="text">Code, mostly.</title>
<subtitle type="html"><![CDATA[
software snippets that someone might use
]]></subtitle>
<id>http://127.0.0.1/~tbrown/tlog/index.atom</id>
<link rel="alternate" type="text/html" href="http://127.0.0.1/~tbrown/tlog" />
<link rel="self" type="application/atom+xml" href="http://127.0.0.1/~tbrown/tlog/index.atom" />


<author>
<name>Terry Brown</name>
<uri>http://127.0.0.1/~tbrown/tlog/index.atom</uri>
<email>terry_n_brown@yahoo.com</email>
</author>
<rights>Copyright 2009 Terry Brown</rights>
<generator uri="http://pyblosxom.sourceforge.net/" version="1.5 dev">
PyBlosxom http://pyblosxom.sourceforge.net/ 1.5 dev
</generator>

<updated>2009-12-26T18:21:23Z</updated>
<!-- icon?  logo?  -->

<entry>
<title type="html">Eco-button for linux
</title>
<category term="/code/python" />
<id>http://127.0.0.1/~tbrown/tlog/2009/12/26/ecobutton-linux</id>
<updated>2009-12-26T18:21:23Z</updated>
<published>2009-12-26T18:21:23Z</published>
<link rel="alternate" type="text/html" href="http://127.0.0.1/~tbrown/tlog/code/python/ecobutton-linux.html" />
<content type="html">&lt;p&gt;Having received an &lt;a class=&quot;reference external&quot; href=&quot;http:&#x2F;&#x2F;www.flashwear.com&#x2F;online_store&#x2F;usb_eco_button.cfm&quot;&gt;eco-button&lt;&#x2F;a&gt; I wondered what it would take to get it to do anything in Linux.  I was thinking about modifying a simple USB driver or something arcane like that, but it turned out to be much simpler.  When you plug the eco-button in to a USB port and press it it generates a stream of &lt;tt class=&quot;docutils literal&quot;&gt;XF86Sleep&lt;&#x2F;tt&gt; keypress events.  It doesn&#x27;t show up under &lt;tt class=&quot;docutils literal&quot;&gt;lsusb&lt;&#x2F;tt&gt; which makes me think it might be injecting keyboard input, but anyway, it sends a clear and usable signal.&lt;&#x2F;p&gt;
&lt;p&gt;If your system is setup to sleep when the extended keyboard&#x27;s sleep key is pressed the eco-button might work out of the box for your.  If not, here are three simple steps to make it go.&lt;&#x2F;p&gt;
&lt;ol class=&quot;arabic simple&quot;&gt;
&lt;li&gt;Have your window-manager bind the &lt;tt class=&quot;docutils literal&quot;&gt;XF86Sleep&lt;&#x2F;tt&gt; key to run the following python program.  Put the text below in a file, called perhaps &lt;tt class=&quot;docutils literal&quot;&gt;&#x2F;home&#x2F;joeuser&#x2F;bin&#x2F;ecobutton&lt;&#x2F;tt&gt;, and then tell your window-manager to run it when the &lt;tt class=&quot;docutils literal&quot;&gt;XF86Sleep&lt;&#x2F;tt&gt; is pressed.  You&#x27;ll need to make the program executeable (&lt;tt class=&quot;docutils literal&quot;&gt;chmod +x &#x2F;home&#x2F;joeuser&#x2F;bin&#x2F;ecobutton&lt;&#x2F;tt&gt;).  When you&#x27;re setting up the hotkey, you can press the eco-button itself of course, to send the &lt;tt class=&quot;docutils literal&quot;&gt;XF86Sleep&lt;&#x2F;tt&gt; keystroke.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;blockquote&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span style=&quot;color: #408080; font-style: italic&quot;&gt;#!&#x2F;usr&#x2F;bin&#x2F;python&lt;&#x2F;span&gt;

&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;import&lt;&#x2F;span&gt; &lt;span style=&quot;color: #0000FF; font-weight: bold&quot;&gt;os&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;import&lt;&#x2F;span&gt; &lt;span style=&quot;color: #0000FF; font-weight: bold&quot;&gt;time&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;import&lt;&#x2F;span&gt; &lt;span style=&quot;color: #0000FF; font-weight: bold&quot;&gt;fcntl&lt;&#x2F;span&gt;

aFile &lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt; &lt;span style=&quot;color: #008000&quot;&gt;open&lt;&#x2F;span&gt;(os&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;path&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;expanduser(&lt;span style=&quot;color: #BA2121&quot;&gt;&amp;quot;~&#x2F;.ecobutton.lck&amp;quot;&lt;&#x2F;span&gt;), &lt;span style=&quot;color: #BA2121&quot;&gt;&amp;#39;w&amp;#39;&lt;&#x2F;span&gt;)
fd &lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt; aFile&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;fileno()
fcntl&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;lockf(fd, fcntl&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;LOCK_EX &lt;span style=&quot;color: #666666&quot;&gt;|&lt;&#x2F;span&gt; fcntl&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;LOCK_NB)
&lt;span style=&quot;color: #408080; font-style: italic&quot;&gt;# program aborts at this point if another already has lock&lt;&#x2F;span&gt;
os&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;system(&lt;span style=&quot;color: #BA2121&quot;&gt;&amp;quot;sudo &#x2F;usr&#x2F;sbin&#x2F;pm-hibernate&amp;quot;&lt;&#x2F;span&gt;)
time&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;sleep(&lt;span style=&quot;color: #666666&quot;&gt;10&lt;&#x2F;span&gt;)  &lt;span style=&quot;color: #408080; font-style: italic&quot;&gt;# stay running to preserve lock&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
&lt;&#x2F;blockquote&gt;
&lt;ol class=&quot;arabic&quot; start=&quot;2&quot;&gt;
&lt;li&gt;&lt;p class=&quot;first&quot;&gt;Make sure the &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;pm-utils&lt;&#x2F;span&gt;&lt;&#x2F;tt&gt; package, or whatever package provides &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;pm-hibernate&lt;&#x2F;span&gt;&lt;&#x2F;tt&gt;, is installed on your system.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;p class=&quot;first&quot;&gt;Use &lt;tt class=&quot;docutils literal&quot;&gt;visudo&lt;&#x2F;tt&gt; to add an entry like this at &lt;em&gt;the end&lt;&#x2F;em&gt; of &lt;tt class=&quot;docutils literal&quot;&gt;&#x2F;etc&#x2F;sudoers&lt;&#x2F;tt&gt; (replace &lt;tt class=&quot;docutils literal&quot;&gt;joeuser&lt;&#x2F;tt&gt; with your username):&lt;&#x2F;p&gt;
&lt;pre class=&quot;literal-block&quot;&gt;
joeuser ALL=(ALL) NOPASSWD: &#x2F;usr&#x2F;sbin&#x2F;pm-hibernate
&lt;&#x2F;pre&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;That&#x27;s it.  Because the eco-button generates a stream of &lt;tt class=&quot;docutils literal&quot;&gt;XF86Sleep&lt;&#x2F;tt&gt; key-presses the python program uses a lockfile to ensure &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;pm-hibernate&lt;&#x2F;span&gt;&lt;&#x2F;tt&gt; is only run once.  That&#x27;s probably unnecessary, &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;pm-hibernate&lt;&#x2F;span&gt;&lt;&#x2F;tt&gt; may do its own locking anyway.&lt;&#x2F;p&gt;
&lt;p&gt;Of course all of this is just a convoluted way of invoking the hibernate function, and to a degree it&#x27;s just code for its own sake, making the button work in Linux.  On the other hand it really has reduced my energy usage, because it inspired me to test Ubuntu&#x27;s hibernate function (which wasn&#x27;t working well last time I looked, 2-3 years ago, but is now fine), and the glowing button thing reminds me to use it.&lt;&#x2F;p&gt;
</content>
</entry>

<entry>
<title type="html">N-up layout extension for Inkscape.
</title>
<category term="/code/python/inkscape" />
<id>http://127.0.0.1/~tbrown/tlog/2009/09/23/inkscape-nup-layout</id>
<updated>2009-09-23T15:51:22Z</updated>
<published>2009-09-23T15:51:22Z</published>
<link rel="alternate" type="text/html" href="http://127.0.0.1/~tbrown/tlog/code/python/inkscape/inkscape-nup-layout.html" />
<content type="html">&lt;p&gt;I&#x27;d forgotten about this until someone changed the tags on the wishlist &amp;quot;bug&amp;quot; which acts as a home for this code:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;a class=&quot;reference external&quot; href=&quot;https:&#x2F;&#x2F;bugs.launchpad.net&#x2F;inkscape&#x2F;+bug&#x2F;169955&quot;&gt;https:&#x2F;&#x2F;bugs.launchpad.net&#x2F;inkscape&#x2F;+bug&#x2F;169955&lt;&#x2F;a&gt;&lt;&#x2F;blockquote&gt;
&lt;p&gt;Basically an inkscape extension for n-up layouts, great for postcards and labels.&lt;&#x2F;p&gt;
&lt;img alt=&quot;nup-inkscape.png&quot; src=&quot;nup-inkscape.png&quot; &#x2F;&gt;
</content>
</entry>

<entry>
<title type="html">Syntax highlighting for Pyblosxom
</title>
<category term="/code/python/pyblosxom" />
<id>http://127.0.0.1/~tbrown/tlog/2009/08/15/pyblosxom-syntax-highlighting</id>
<updated>2009-08-15T14:02:20Z</updated>
<published>2009-08-15T14:02:20Z</published>
<link rel="alternate" type="text/html" href="http://127.0.0.1/~tbrown/tlog/code/python/pyblosxom/pyblosxom-syntax-highlighting.html" />
<content type="html">&lt;p&gt;After running around in circles a bit I&#x27;ve found it&#x27;s quite easy to
get syntax highlighting in Pyblosxom if you&#x27;re using the rst plugin.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;ol class=&quot;arabic&quot;&gt;
&lt;li&gt;&lt;p class=&quot;first&quot;&gt;Install the rst plugin.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;p class=&quot;first&quot;&gt;Make sure pygments is installed on your system.  It&#x27;s available as
a package for Ubuntu, so you can just do:&lt;&#x2F;p&gt;
&lt;pre class=&quot;literal-block&quot;&gt;
sudo apt-get install python-pygments
&lt;&#x2F;pre&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;p class=&quot;first&quot;&gt;Get &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;rst-directive.py&lt;&#x2F;span&gt;&lt;&#x2F;tt&gt; from the &lt;a class=&quot;reference external&quot; href=&quot;http:&#x2F;&#x2F;dev.pocoo.org&#x2F;projects&#x2F;pygments&#x2F;&quot;&gt;pygments&lt;&#x2F;a&gt; distribution (or from the
end of this article).  It&#x27;s
in the &#x27;external&#x27; folder.  It may not be included in the package
for your system, but you can get the file by itself by browsing
the pygments site.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;p class=&quot;first&quot;&gt;Rename it &lt;tt class=&quot;docutils literal&quot;&gt;rst_directive.py&lt;&#x2F;tt&gt; because that seems more sensible,
and put it in you plugins folder.  You would think you would need
to import it from the rst plugin, but you don&#x27;t, because
Pyblosxom will have imported it just because it&#x27;s in the plugins
folder.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;&lt;p class=&quot;first&quot;&gt;Edit rst_directive.py and change:&lt;&#x2F;p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;INLINESTYLES &lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt; &lt;span style=&quot;color: #008000&quot;&gt;False&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
&lt;p&gt;to&lt;&#x2F;p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;INLINESTYLES &lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt; &lt;span style=&quot;color: #008000&quot;&gt;True&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
&lt;p&gt;Doing so causes pygments to use &lt;tt class=&quot;docutils literal&quot;&gt;&amp;lt;span &lt;span class=&quot;pre&quot;&gt;style=&amp;quot;color:&lt;&#x2F;span&gt; #BA2121&amp;quot;&amp;gt;&lt;&#x2F;tt&gt;
instead of &lt;tt class=&quot;docutils literal&quot;&gt;&amp;lt;span &lt;span class=&quot;pre&quot;&gt;class=&amp;quot;comment&amp;quot;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;tt&gt; etc., but it saves a lot of
trouble trying to ensure the CSS file is available.&lt;&#x2F;p&gt;
&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;That&#x27;s it.  &lt;em&gt;Now&lt;&#x2F;em&gt; in your rst you can use the &lt;cite&gt;sourcecode&lt;&#x2F;cite&gt; directive:&lt;&#x2F;p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;That&amp;#39;s it.  &lt;span style=&quot;font-style: italic&quot;&gt;*Now*&lt;&#x2F;span&gt; in your rst you can use the &lt;span style=&quot;color: #19177C&quot;&gt;`sourcecode`&lt;&#x2F;span&gt; directive:

.. &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;sourcecode:&lt;&#x2F;span&gt; python

  import foo  # get access to foo
  foo.bar(&amp;quot;test&amp;quot;) or raise SystemExit
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
&lt;p&gt;to  syntax highlight rst (above), python (below), and all the other languages and markups pygments knows.&lt;&#x2F;p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;import&lt;&#x2F;span&gt; &lt;span style=&quot;color: #0000FF; font-weight: bold&quot;&gt;foo&lt;&#x2F;span&gt;  &lt;span style=&quot;color: #408080; font-style: italic&quot;&gt;# get access to foo&lt;&#x2F;span&gt;
foo&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;bar(&lt;span style=&quot;color: #BA2121&quot;&gt;&amp;quot;test&amp;quot;&lt;&#x2F;span&gt;) &lt;span style=&quot;color: #AA22FF; font-weight: bold&quot;&gt;or&lt;&#x2F;span&gt; &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;raise&lt;&#x2F;span&gt; &lt;span style=&quot;color: #D2413A; font-weight: bold&quot;&gt;SystemExit&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
&lt;p&gt;&lt;a class=&quot;reference external&quot; href=&quot;http:&#x2F;&#x2F;bel-epa.com&#x2F;bloxom&#x2F;pylons&#x2F;firstpost.html&quot;&gt;Graham Higgins&lt;&#x2F;a&gt;&#x27;s post may have set me off on the right track here, at least by making me aware of pygments.&lt;&#x2F;p&gt;
&lt;div class=&quot;section&quot; id=&quot;syntax-highlighting-on-external-files&quot;&gt;
&lt;h4&gt;Syntax highlighting on external files&lt;&#x2F;h4&gt;
&lt;p&gt;To make pygment&#x27;s &lt;cite&gt;sourcecode&lt;&#x2F;cite&gt; directive even more useful I added a
quick tweak to allow inclusion of a file like this:&lt;&#x2F;p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;.. &lt;span style=&quot;color: #AA22FF; font-weight: bold&quot;&gt;sourcecode&lt;&#x2F;span&gt;:: &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;python&lt;&#x2F;span&gt;
  &lt;span style=&quot;color: #0000FF; font-weight: bold&quot;&gt;:filename:&lt;&#x2F;span&gt; &lt;span style=&quot;color: #0000FF&quot;&gt;..&#x2F;tlog&#x2F;plugins&#x2F;rst_directive.py&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
&lt;p&gt;In this form the inline content is ignored and the content of
&lt;cite&gt;filename&lt;&#x2F;cite&gt; is formatted instead.&lt;&#x2F;p&gt;
&lt;p&gt;Here&#x27;s the complete, modified, &lt;cite&gt;rst_directive.py&lt;&#x2F;cite&gt; (original from &lt;cite&gt;external&lt;&#x2F;cite&gt;
folder on pygments Trac site).  Put it in your
plugins directory.  Modifications are:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;ul class=&quot;simple&quot;&gt;
&lt;li&gt;&lt;tt class=&quot;docutils literal&quot;&gt;INLINESTYLES = True&lt;&#x2F;tt&gt;&lt;&#x2F;li&gt;
&lt;li&gt;the &lt;tt class=&quot;docutils literal&quot;&gt;if &lt;span class=&quot;pre&quot;&gt;&#x27;filename&#x27;...&lt;&#x2F;span&gt;&lt;&#x2F;tt&gt; block&lt;&#x2F;li&gt;
&lt;li&gt;setting &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;...options[&#x27;filename&#x27;]&lt;&#x2F;span&gt; = directives.path&lt;&#x2F;tt&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;&#x2F;blockquote&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span style=&quot;color: #408080; font-style: italic&quot;&gt;# -*- coding: utf-8 -*-&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;    The Pygments reStructuredText directive&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;&#x2F;span&gt;

&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;    This fragment is a Docutils_ 0.4 directive that renders source code&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;    (to HTML only, currently) via Pygments.&lt;&#x2F;span&gt;

&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;    To use it, adjust the options below and copy the code into a module&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;    that you import on initialization.  The code then automatically&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;    registers a ``sourcecode`` directive that you can use instead of&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;    normal code blocks like this::&lt;&#x2F;span&gt;

&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;        .. sourcecode:: python&lt;&#x2F;span&gt;

&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;            My code goes here.&lt;&#x2F;span&gt;

&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;    If you want to have different code styles, e.g. one with line numbers&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;    and one without, add formatters with their names in the VARIANTS dict&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;    below.  You can invoke them instead of the DEFAULT one by using a&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;    directive option::&lt;&#x2F;span&gt;

&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;        .. sourcecode:: python&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;            :linenos:&lt;&#x2F;span&gt;

&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;            My code goes here.&lt;&#x2F;span&gt;

&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;    Look at the `directive documentation`_ to get all the gory details.&lt;&#x2F;span&gt;

&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;    .. _Docutils: http:&#x2F;&#x2F;docutils.sf.net&#x2F;&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;    .. _directive documentation:&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;       http:&#x2F;&#x2F;docutils.sourceforge.net&#x2F;docs&#x2F;howto&#x2F;rst-directives.html&lt;&#x2F;span&gt;

&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;    :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS.&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;    :license: BSD, see LICENSE for details.&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #BA2121; font-style: italic&quot;&gt;&amp;quot;&amp;quot;&amp;quot;&lt;&#x2F;span&gt;

&lt;span style=&quot;color: #408080; font-style: italic&quot;&gt;# Options&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #408080; font-style: italic&quot;&gt;# ~~~~~~~&lt;&#x2F;span&gt;

&lt;span style=&quot;color: #408080; font-style: italic&quot;&gt;# Set to True if you want inline CSS styles instead of classes&lt;&#x2F;span&gt;
INLINESTYLES &lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt; &lt;span style=&quot;color: #008000&quot;&gt;True&lt;&#x2F;span&gt;

&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;from&lt;&#x2F;span&gt; &lt;span style=&quot;color: #0000FF; font-weight: bold&quot;&gt;pygments.formatters&lt;&#x2F;span&gt; &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;import&lt;&#x2F;span&gt; HtmlFormatter

&lt;span style=&quot;color: #408080; font-style: italic&quot;&gt;# The default formatter&lt;&#x2F;span&gt;
DEFAULT &lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt; HtmlFormatter(noclasses&lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt;INLINESTYLES)

&lt;span style=&quot;color: #408080; font-style: italic&quot;&gt;# Add name -&amp;gt; formatter pairs for every variant you want to use&lt;&#x2F;span&gt;
VARIANTS &lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt; {
    &lt;span style=&quot;color: #BA2121&quot;&gt;&amp;#39;linenos&amp;#39;&lt;&#x2F;span&gt;: HtmlFormatter(noclasses&lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt;INLINESTYLES, linenos&lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #008000&quot;&gt;True&lt;&#x2F;span&gt;),
}


&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;from&lt;&#x2F;span&gt; &lt;span style=&quot;color: #0000FF; font-weight: bold&quot;&gt;docutils&lt;&#x2F;span&gt; &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;import&lt;&#x2F;span&gt; nodes
&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;from&lt;&#x2F;span&gt; &lt;span style=&quot;color: #0000FF; font-weight: bold&quot;&gt;docutils.parsers.rst&lt;&#x2F;span&gt; &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;import&lt;&#x2F;span&gt; directives

&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;from&lt;&#x2F;span&gt; &lt;span style=&quot;color: #0000FF; font-weight: bold&quot;&gt;pygments&lt;&#x2F;span&gt; &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;import&lt;&#x2F;span&gt; highlight
&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;from&lt;&#x2F;span&gt; &lt;span style=&quot;color: #0000FF; font-weight: bold&quot;&gt;pygments.lexers&lt;&#x2F;span&gt; &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;import&lt;&#x2F;span&gt; get_lexer_by_name, TextLexer

&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;def&lt;&#x2F;span&gt; &lt;span style=&quot;color: #0000FF&quot;&gt;pygments_directive&lt;&#x2F;span&gt;(name, arguments, options, content, lineno,
                       content_offset, block_text, state, state_machine):

    &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;if&lt;&#x2F;span&gt; &lt;span style=&quot;color: #BA2121&quot;&gt;&amp;#39;filename&amp;#39;&lt;&#x2F;span&gt; &lt;span style=&quot;color: #AA22FF; font-weight: bold&quot;&gt;in&lt;&#x2F;span&gt; options:
        &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;if&lt;&#x2F;span&gt; options[&lt;span style=&quot;color: #BA2121&quot;&gt;&amp;#39;filename&amp;#39;&lt;&#x2F;span&gt;]:
            content &lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt; [line&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;rstrip(&lt;span style=&quot;color: #BA2121&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BB6622; font-weight: bold&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BA2121&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;) &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;for&lt;&#x2F;span&gt; line &lt;span style=&quot;color: #AA22FF; font-weight: bold&quot;&gt;in&lt;&#x2F;span&gt; &lt;span style=&quot;color: #008000&quot;&gt;file&lt;&#x2F;span&gt;(options[&lt;span style=&quot;color: #BA2121&quot;&gt;&amp;#39;filename&amp;#39;&lt;&#x2F;span&gt;])] 
        &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;del&lt;&#x2F;span&gt; options[&lt;span style=&quot;color: #BA2121&quot;&gt;&amp;#39;filename&amp;#39;&lt;&#x2F;span&gt;] 

    &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;try&lt;&#x2F;span&gt;:
        lexer &lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt; get_lexer_by_name(arguments[&lt;span style=&quot;color: #666666&quot;&gt;0&lt;&#x2F;span&gt;])
    &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;except&lt;&#x2F;span&gt; &lt;span style=&quot;color: #D2413A; font-weight: bold&quot;&gt;ValueError&lt;&#x2F;span&gt;:
        &lt;span style=&quot;color: #408080; font-style: italic&quot;&gt;# no lexer found - use the text one instead of an exception&lt;&#x2F;span&gt;
        lexer &lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt; TextLexer()

    &lt;span style=&quot;color: #408080; font-style: italic&quot;&gt;# take an arbitrary option if more than one is given&lt;&#x2F;span&gt;
    formatter &lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt; options &lt;span style=&quot;color: #AA22FF; font-weight: bold&quot;&gt;and&lt;&#x2F;span&gt; VARIANTS[options&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;keys()[&lt;span style=&quot;color: #666666&quot;&gt;0&lt;&#x2F;span&gt;]] &lt;span style=&quot;color: #AA22FF; font-weight: bold&quot;&gt;or&lt;&#x2F;span&gt; DEFAULT
    parsed &lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt; highlight(&lt;span style=&quot;color: #BA2121&quot;&gt;u&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BB6622; font-weight: bold&quot;&gt;\n&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BA2121&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;join(content), lexer, formatter)
    &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;return&lt;&#x2F;span&gt; [nodes&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;raw(&lt;span style=&quot;color: #BA2121&quot;&gt;&amp;#39;&amp;#39;&lt;&#x2F;span&gt;, parsed, format&lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BA2121&quot;&gt;&amp;#39;html&amp;#39;&lt;&#x2F;span&gt;)]

pygments_directive&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;arguments &lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt; (&lt;span style=&quot;color: #666666&quot;&gt;1&lt;&#x2F;span&gt;, &lt;span style=&quot;color: #666666&quot;&gt;0&lt;&#x2F;span&gt;, &lt;span style=&quot;color: #666666&quot;&gt;1&lt;&#x2F;span&gt;)
pygments_directive&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;content &lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt; &lt;span style=&quot;color: #666666&quot;&gt;1&lt;&#x2F;span&gt;
pygments_directive&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;options &lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt; &lt;span style=&quot;color: #008000&quot;&gt;dict&lt;&#x2F;span&gt;([(key, directives&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;flag) &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;for&lt;&#x2F;span&gt; key &lt;span style=&quot;color: #AA22FF; font-weight: bold&quot;&gt;in&lt;&#x2F;span&gt; VARIANTS])

pygments_directive&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;options[&lt;span style=&quot;color: #BA2121&quot;&gt;&amp;#39;filename&amp;#39;&lt;&#x2F;span&gt;] &lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt; directives&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;path

directives&lt;span style=&quot;color: #666666&quot;&gt;.&lt;&#x2F;span&gt;register_directive(&lt;span style=&quot;color: #BA2121&quot;&gt;&amp;#39;sourcecode&amp;#39;&lt;&#x2F;span&gt;, pygments_directive)
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
&lt;&#x2F;div&gt;
</content>
</entry>

<entry>
<title type="html">Testing mostly pingback
</title>
<category term="" />
<id>http://127.0.0.1/~tbrown/tlog/2009/08/10/pingbacktest</id>
<updated>2009-08-10T15:41:13Z</updated>
<published>2009-08-10T15:41:13Z</published>
<link rel="alternate" type="text/html" href="http://127.0.0.1/~tbrown/tlog/pingbacktest.html" />
<content type="html">&lt;p&gt;And maybe trackback, maybe.&lt;&#x2F;p&gt;
</content>
</entry>

<entry>
<title type="html">``zipas`` - ensure .zip file contains an outer wrapper folder
</title>
<category term="/code/bash" />
<id>http://127.0.0.1/~tbrown/tlog/2009/08/07/zipas</id>
<updated>2009-08-07T20:01:28Z</updated>
<published>2009-08-07T20:01:28Z</published>
<link rel="alternate" type="text/html" href="http://127.0.0.1/~tbrown/tlog/code/bash/zipas.html" />
<content type="html">&lt;p&gt;A trivial &lt;tt class=&quot;docutils literal&quot;&gt;bash&lt;&#x2F;tt&gt; script to create a .zip file where everything&#x27;s in
a top-level folder.  Saves creating a folder temporarily, and copying
&#x2F; linking things into it:&lt;&#x2F;p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span style=&quot;color: #408080; font-style: italic&quot;&gt;#!&#x2F;bin&#x2F;sh&lt;&#x2F;span&gt;

&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;if&lt;&#x2F;span&gt; &lt;span style=&quot;color: #666666&quot;&gt;[&lt;&#x2F;span&gt; @# -lt 2 &lt;span style=&quot;color: #666666&quot;&gt;]&lt;&#x2F;span&gt;; &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;then &lt;&#x2F;span&gt;cat &lt;span style=&quot;color: #BA2121&quot;&gt;&amp;lt;&amp;lt;EOF&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #BA2121&quot;&gt;usage: $0 &amp;lt;wrapper-folder&amp;gt; &amp;lt;target files&amp;gt;&lt;&#x2F;span&gt;

&lt;span style=&quot;color: #BA2121&quot;&gt;e.g. zipas jul0907 *.c&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #BA2121&quot;&gt;EOF&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;else&lt;&#x2F;span&gt;

&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color: #19177C&quot;&gt;PATHNAME&lt;&#x2F;span&gt;&lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #BA2121&quot;&gt;&amp;quot;$1&amp;quot;&lt;&#x2F;span&gt;
  &lt;span style=&quot;color: #19177C&quot;&gt;HEADNAME&lt;&#x2F;span&gt;&lt;span style=&quot;color: #666666&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;${&lt;&#x2F;span&gt;&lt;span style=&quot;color: #19177C&quot;&gt;PATHNAME&lt;&#x2F;span&gt;%%&#x2F;*&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;}&lt;&#x2F;span&gt;  &lt;span style=&quot;color: #408080; font-style: italic&quot;&gt;# i.e &amp;#39;foo&amp;#39; from &amp;#39;foo&#x2F;bar&#x2F;inner&amp;#39;&lt;&#x2F;span&gt;

  &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;if&lt;&#x2F;span&gt; &lt;span style=&quot;color: #666666&quot;&gt;[&lt;&#x2F;span&gt; -a &lt;span style=&quot;color: #BA2121&quot;&gt;&amp;quot;$HEADNAME&amp;quot;&lt;&#x2F;span&gt; &lt;span style=&quot;color: #666666&quot;&gt;]&lt;&#x2F;span&gt;; &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;then&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color: #008000&quot;&gt;echo&lt;&#x2F;span&gt; &lt;span style=&quot;color: #BA2121&quot;&gt;&amp;quot;ERROR: &amp;#39;$HEADNAME&amp;#39; exists&amp;quot;&lt;&#x2F;span&gt;
  &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;else&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color: #008000&quot;&gt;shift&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #008000&quot;&gt;    &lt;&#x2F;span&gt;mkdir -p &lt;span style=&quot;color: #19177C&quot;&gt;$PATHNAME&lt;&#x2F;span&gt;
    &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;for &lt;&#x2F;span&gt;i in &lt;span style=&quot;color: #19177C&quot;&gt;$@&lt;&#x2F;span&gt;; &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;do&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;      &lt;&#x2F;span&gt;ln -s &lt;span style=&quot;color: #BA2121&quot;&gt;&amp;quot;$PWD&#x2F;$i&amp;quot;&lt;&#x2F;span&gt; &lt;span style=&quot;color: #BA2121&quot;&gt;&amp;quot;$PATHNAME&#x2F;$i&amp;quot;&lt;&#x2F;span&gt;
    &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;done&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;    &lt;&#x2F;span&gt;zip -r &lt;span style=&quot;color: #19177C&quot;&gt;$HEADNAME&lt;&#x2F;span&gt;.zip &lt;span style=&quot;color: #19177C&quot;&gt;$HEADNAME&lt;&#x2F;span&gt;
    rm -rf &lt;span style=&quot;color: #BA2121&quot;&gt;&amp;quot;$HEADNAME&amp;quot;&lt;&#x2F;span&gt;
  &lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;fi&lt;&#x2F;span&gt;
&lt;span style=&quot;color: #008000; font-weight: bold&quot;&gt;fi&lt;&#x2F;span&gt;
&lt;&#x2F;pre&gt;&lt;&#x2F;div&gt;
</content>
</entry>
</feed>

