<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
 <title>#173: manpage.py - Media Tools - Trac</title><link rel="start" href="/nets/mmedia/wiki" /><link rel="search" href="/nets/mmedia/search" /><link rel="help" href="/nets/mmedia/wiki/TracGuide" /><link rel="stylesheet" href="/nets/mmedia/chrome/common/css/trac.css" type="text/css" /><link rel="stylesheet" href="/nets/mmedia/chrome/common/css/code.css" type="text/css" /><link rel="icon" href="/nets/mmedia/chrome/common/rat.ico" type="image/x-icon" /><link rel="shortcut icon" href="/nets/mmedia/chrome/common/rat.ico" type="image/x-icon" /><link rel="up" href="/nets/mmedia/ticket/173" title="Ticket #173" /><link rel="alternate" href="/nets/mmedia/attachment/ticket/173/manpage.py?format=raw" title="Original Format" type="text/x-python" /><style type="text/css">

@import url(/css/uclonline.css);
</style>
 <script type="text/javascript" src="/nets/mmedia/chrome/common/js/trac.js"></script>
</head>
<body>
<div id="tb-mid_green"> 

    <div id="section_heading"> 
       <div id="section_head">
         <span id="section_header_top"><font size="6"><a href="/nets/mmedia/wiki"><b><font color="#5C4033">Media Tools Repository</font></b></a></font><br />
           <a href="http://www.cs.ucl.ac.uk/"><span id="section_header_white">DEPARTMENT OF COMPUTER SCIENCE</span></a><br />
           <a href="http://nrg.cs.ucl.ac.uk/"><span id="section_subheader_white">Networked Multimedia</span></a>
       </div> 
    </div> 

    <div id="logo_holder"> 
      <div id="logo"><a href="http://www.cs.ucl.ac.uk/"><img src="/extra/ucl0025_new.gif" alt="UCL Logo" /></a></div> 
    </div> 

</div> 








<div id="metanav" class="nav" style="background-color:#E5EACE">
<form id="search" action="/nets/mmedia/search" method="get" style="background-color:#F3F5E7">
 <li class="first">logged in as piers</li><li><a href="/nets/mmedia/logout">Logout</a></li><li><a href="/nets/mmedia/settings">Settings</a></li><li><a href="/nets/mmedia/wiki/TracGuide" accesskey="6">Help/Guide</a></li><li class="last"><a href="/nets/mmedia/about">About Trac</a></li>
 
  <label for="proj-search">Search:</label>
  <input type="text" id="proj-search" name="q" size="10" accesskey="f" value="" />
  <input type="submit" value="Search" />
  <input type="hidden" name="wiki" value="on" />
  <input type="hidden" name="changeset" value="on" />
  <input type="hidden" name="ticket" value="on" />
 
</form>
</div>

<div id="mainnav" class="nav"><ul><li class="first"><a href="/nets/mmedia/wiki" accesskey="1">Wiki</a></li><li><a href="/nets/mmedia/timeline" accesskey="2">Timeline</a></li><li><a href="/nets/mmedia/roadmap" accesskey="3">Roadmap</a></li><li><a href="/nets/mmedia/browser">Browse Source</a></li><li><a href="/nets/mmedia/report">View Tickets</a></li><li><a href="/nets/mmedia/newticket" accesskey="7">New Ticket</a></li><li><a href="/nets/mmedia/search" accesskey="4">Search</a></li><li class="last"><a href="/nets/mmedia/admin">Admin</a></li></ul></div>


<div id="main">






<div id="ctxtnav" class="nav"></div>

<div id="content" class="attachment">


 <h1><a href="/nets/mmedia/ticket/173">Ticket #173</a>: manpage.py</h1>
 <div id="preview">
   <table class="code"><thead><tr><th class="lineno">Line</th><th class="content">&nbsp;</th></tr></thead><tbody><tr><th id="L1"><a href="#L1">1</a></th>
<td><span class="p_commentline"># -*- coding: iso-8859-1 -*-</span></td>
</tr><tr><th id="L2"><a href="#L2">2</a></th>
<td><span class="p_commentline">#</span></td>
</tr><tr><th id="L3"><a href="#L3">3</a></th>
<td><span class="p_commentline"># Copyright (C) 2004-2006 Edgewall Software</span></td>
</tr><tr><th id="L4"><a href="#L4">4</a></th>
<td><span class="p_commentline"># Copyright (C) 2008 Piers O'Hanlon</span></td>
</tr><tr><th id="L5"><a href="#L5">5</a></th>
<td><span class="p_commentline"># All rights reserved.</span></td>
</tr><tr><th id="L6"><a href="#L6">6</a></th>
<td><span class="p_commentline">#</span></td>
</tr><tr><th id="L7"><a href="#L7">7</a></th>
<td><span class="p_commentline"># This software is licensed as described in the file COPYING, which</span></td>
</tr><tr><th id="L8"><a href="#L8">8</a></th>
<td><span class="p_commentline"># you should have received as part of this distribution. The terms</span></td>
</tr><tr><th id="L9"><a href="#L9">9</a></th>
<td><span class="p_commentline"># are also available at <a href="http://trac.edgewall.com/license.html">http://trac.edgewall.com/license.html</a>.</span></td>
</tr><tr><th id="L10"><a href="#L10">10</a></th>
<td><span class="p_commentline">#</span></td>
</tr><tr><th id="L11"><a href="#L11">11</a></th>
<td><span class="p_commentline"># This software consists of voluntary contributions made by many</span></td>
</tr><tr><th id="L12"><a href="#L12">12</a></th>
<td><span class="p_commentline"># individuals. For the exact contribution history, see the revision</span></td>
</tr><tr><th id="L13"><a href="#L13">13</a></th>
<td><span class="p_commentline"># history and logs, available at <a href="http://projects.edgewall.com/trac">http://projects.edgewall.com/trac</a>/.</span></td>
</tr><tr><th id="L14"><a href="#L14">14</a></th>
<td><span class="p_commentline">#</span></td>
</tr><tr><th id="L15"><a href="#L15">15</a></th>
<td><span class="p_commentline"># To enable this extension you need to add </span></td>
</tr><tr><th id="L16"><a href="#L16">16</a></th>
<td><span class="p_commentline">#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'trac.mimeview.manpage', </span></td>
</tr><tr><th id="L17"><a href="#L17">17</a></th>
<td><span class="p_commentline"># to the following file - to the default_components variable:</span></td>
</tr><tr><th id="L18"><a href="#L18">18</a></th>
<td><span class="p_commentline">#../db_default.py:440</span></td>
</tr><tr><th id="L19"><a href="#L19">19</a></th>
<td><span class="p_commentline"># default_components = ('trac.About', 'trac.attachment', </span></td>
</tr><tr><th id="L20"><a href="#L20">20</a></th>
<td><span class="p_commentline">#</span></td>
</tr><tr><th id="L21"><a href="#L21">21</a></th>
<td><span class="p_commentline"># Author: Piers O'Hanlon &lt;p.ohanlon@cs.ucl.ac.uk&gt;</span></td>
</tr><tr><th id="L22"><a href="#L22">22</a></th>
<td></td>
</tr><tr><th id="L23"><a href="#L23">23</a></th>
<td><span class="p_tripledouble">"""Trac support for nroff man pages</span></td>
</tr><tr><th id="L24"><a href="#L24">24</a></th>
<td><span class="p_tripledouble">See GNU groff for more info: <a href="http://www.gnu.org/software/groff">http://www.gnu.org/software/groff</a>/</span></td>
</tr><tr><th id="L25"><a href="#L25">25</a></th>
<td><span class="p_tripledouble">"""</span></td>
</tr><tr><th id="L26"><a href="#L26">26</a></th>
<td></td>
</tr><tr><th id="L27"><a href="#L27">27</a></th>
<td><span class="p_word">from</span>&nbsp;<span class="p_identifier">trac</span><span class="p_operator">.</span><span class="p_identifier">core</span> <span class="p_word">import</span> <span class="p_operator">*</span></td>
</tr><tr><th id="L28"><a href="#L28">28</a></th>
<td><span class="p_word">from</span>&nbsp;<span class="p_identifier">trac</span><span class="p_operator">.</span><span class="p_identifier">mimeview</span><span class="p_operator">.</span><span class="p_identifier">api</span> <span class="p_word">import</span> <span class="p_identifier">IHTMLPreviewRenderer</span></td>
</tr><tr><th id="L29"><a href="#L29">29</a></th>
<td><span class="p_word">from</span>&nbsp;<span class="p_identifier">trac</span><span class="p_operator">.</span><span class="p_identifier">util</span> <span class="p_word">import</span> <span class="p_identifier">escape</span><span class="p_operator">,</span> <span class="p_identifier">NaivePopen</span><span class="p_operator">,</span> <span class="p_identifier">Deuglifier</span></td>
</tr><tr><th id="L30"><a href="#L30">30</a></th>
<td></td>
</tr><tr><th id="L31"><a href="#L31">31</a></th>
<td><span class="p_identifier">__all__</span>&nbsp;<span class="p_operator">=</span> <span class="p_operator">[</span><span class="p_character">'ManpageRenderer'</span><span class="p_operator">]</span></td>
</tr><tr><th id="L32"><a href="#L32">32</a></th>
<td></td>
</tr><tr><th id="L33"><a href="#L33">33</a></th>
<td><span class="p_word">class</span>&nbsp;<span class="p_classname">ManpageRenderer</span><span class="p_operator">(</span><span class="p_identifier">Component</span><span class="p_operator">):</span></td>
</tr><tr><th id="L34"><a href="#L34">34</a></th>
<td>&nbsp; &nbsp; <span class="p_tripledouble">"""Renders nroff man page as HTML."""</span></td>
</tr><tr><th id="L35"><a href="#L35">35</a></th>
<td>&nbsp; &nbsp; <span class="p_identifier">implements</span><span class="p_operator">(</span><span class="p_identifier">IHTMLPreviewRenderer</span><span class="p_operator">)</span></td>
</tr><tr><th id="L36"><a href="#L36">36</a></th>
<td></td>
</tr><tr><th id="L37"><a href="#L37">37</a></th>
<td>&nbsp; &nbsp; <span class="p_identifier">expand_tabs</span> <span class="p_operator">=</span> <span class="p_identifier">False</span></td>
</tr><tr><th id="L38"><a href="#L38">38</a></th>
<td></td>
</tr><tr><th id="L39"><a href="#L39">39</a></th>
<td>&nbsp; &nbsp; <span class="p_word">def</span> <span class="p_defname">get_quality_ratio</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">,</span> <span class="p_identifier">mimetype</span><span class="p_operator">):</span></td>
</tr><tr><th id="L40"><a href="#L40">40</a></th>
<td>&nbsp; &nbsp; &nbsp; &nbsp; <span class="p_word">if</span> <span class="p_identifier">mimetype</span> <span class="p_operator">==</span> <span class="p_character">'application/x-troff-man'</span><span class="p_operator">:</span></td>
</tr><tr><th id="L41"><a href="#L41">41</a></th>
<td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="p_word">return</span> <span class="p_number">8</span></td>
</tr><tr><th id="L42"><a href="#L42">42</a></th>
<td>&nbsp; &nbsp; &nbsp; &nbsp; <span class="p_word">return</span> <span class="p_number">0</span></td>
</tr><tr><th id="L43"><a href="#L43">43</a></th>
<td></td>
</tr><tr><th id="L44"><a href="#L44">44</a></th>
<td>&nbsp; &nbsp; <span class="p_word">def</span> <span class="p_defname">render</span><span class="p_operator">(</span><span class="p_identifier">self</span><span class="p_operator">,</span> <span class="p_identifier">req</span><span class="p_operator">,</span> <span class="p_identifier">mimetype</span><span class="p_operator">,</span> <span class="p_identifier">content</span><span class="p_operator">,</span> <span class="p_identifier">filename</span><span class="p_operator">=</span><span class="p_word">None</span><span class="p_operator">,</span> <span class="p_identifier">rev</span><span class="p_operator">=</span><span class="p_word">None</span><span class="p_operator">):</span></td>
</tr><tr><th id="L45"><a href="#L45">45</a></th>
<td>&nbsp; &nbsp; &nbsp; &nbsp; <span class="p_commentline">#cmdline = '/usr/bin/groff -Tutf8 -a -mandoc '</span></td>
</tr><tr><th id="L46"><a href="#L46">46</a></th>
<td>&nbsp; &nbsp; &nbsp; &nbsp; <span class="p_identifier">cmdline</span> <span class="p_operator">=</span> <span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">config</span><span class="p_operator">.</span><span class="p_identifier">get</span><span class="p_operator">(</span><span class="p_character">'mimeviewer'</span><span class="p_operator">,</span> <span class="p_character">'groff_path'</span><span class="p_operator">)</span></td>
</tr><tr><th id="L47"><a href="#L47">47</a></th>
<td>&nbsp; &nbsp; &nbsp; &nbsp; <span class="p_word">if</span> <span class="p_identifier">len</span><span class="p_operator">(</span><span class="p_identifier">cmdline</span><span class="p_operator">)</span> <span class="p_operator">==</span> <span class="p_number">0</span><span class="p_operator">:</span></td>
</tr><tr><th id="L48"><a href="#L48">48</a></th>
<td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="p_identifier">cmdline</span> <span class="p_operator">=</span> <span class="p_character">'/usr/bin/groff'</span></td>
</tr><tr><th id="L49"><a href="#L49">49</a></th>
<td>&nbsp; &nbsp; &nbsp; &nbsp; <span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">env</span><span class="p_operator">.</span><span class="p_identifier">log</span><span class="p_operator">.</span><span class="p_identifier">debug</span><span class="p_operator">(</span><span class="p_string">"groff got command line: %s"</span> <span class="p_operator">%</span> <span class="p_identifier">cmdline</span><span class="p_operator">)</span></td>
</tr><tr><th id="L50"><a href="#L50">50</a></th>
<td>&nbsp; &nbsp; &nbsp; &nbsp; <span class="p_identifier">cmdline</span> <span class="p_operator">+=</span> <span class="p_character">' -Thtml -P -r -P -l -mandoc '</span></td>
</tr><tr><th id="L51"><a href="#L51">51</a></th>
<td>&nbsp; &nbsp; &nbsp; &nbsp; <span class="p_identifier">self</span><span class="p_operator">.</span><span class="p_identifier">env</span><span class="p_operator">.</span><span class="p_identifier">log</span><span class="p_operator">.</span><span class="p_identifier">debug</span><span class="p_operator">(</span><span class="p_string">"groff command line: %s"</span> <span class="p_operator">%</span> <span class="p_identifier">cmdline</span><span class="p_operator">)</span></td>
</tr><tr><th id="L52"><a href="#L52">52</a></th>
<td></td>
</tr><tr><th id="L53"><a href="#L53">53</a></th>
<td>&nbsp; &nbsp; &nbsp; &nbsp; <span class="p_identifier">np</span> <span class="p_operator">=</span> <span class="p_identifier">NaivePopen</span><span class="p_operator">(</span><span class="p_identifier">cmdline</span><span class="p_operator">,</span> <span class="p_identifier">content</span><span class="p_operator">,</span> <span class="p_identifier">capturestderr</span><span class="p_operator">=</span><span class="p_number">1</span><span class="p_operator">)</span></td>
</tr><tr><th id="L54"><a href="#L54">54</a></th>
<td>&nbsp; &nbsp; &nbsp; &nbsp; <span class="p_word">if</span> <span class="p_identifier">np</span><span class="p_operator">.</span><span class="p_identifier">errorlevel</span> <span class="p_word">or</span> <span class="p_identifier">np</span><span class="p_operator">.</span><span class="p_identifier">err</span><span class="p_operator">:</span></td>
</tr><tr><th id="L55"><a href="#L55">55</a></th>
<td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="p_identifier">err</span> <span class="p_operator">=</span> <span class="p_character">'Running (%s) failed: %s, %s.'</span> <span class="p_operator">%</span> <span class="p_operator">(</span><span class="p_identifier">cmdline</span><span class="p_operator">,</span> <span class="p_identifier">np</span><span class="p_operator">.</span><span class="p_identifier">errorlevel</span><span class="p_operator">,</span></td>
</tr><tr><th id="L56"><a href="#L56">56</a></th>
<td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="p_identifier">np</span><span class="p_operator">.</span><span class="p_identifier">err</span><span class="p_operator">)</span></td>
</tr><tr><th id="L57"><a href="#L57">57</a></th>
<td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="p_word">raise</span> <span class="p_identifier">Exception</span><span class="p_operator">,</span> <span class="p_identifier">err</span></td>
</tr><tr><th id="L58"><a href="#L58">58</a></th>
<td></td>
</tr><tr><th id="L59"><a href="#L59">59</a></th>
<td>&nbsp; &nbsp; &nbsp; &nbsp; <span class="p_word">return</span> <span class="p_identifier">np</span><span class="p_operator">.</span><span class="p_identifier">out</span></td>
</tr><tr><th id="L60"><a href="#L60">60</a></th>
<td></td>
</tr></tbody></table>
 </div>
 <div class="buttons">
  <form method="get" action=""><div id="delete">
   <input type="hidden" name="action" value="delete" />
   <input type="submit" value="Delete attachment" />
  </div></form>
 </div>


</div>
<script type="text/javascript">searchHighlight()</script>
<div id="altlinks"><h3>Download in other formats:</h3><ul><li class="first last"><a href="/nets/mmedia/attachment/ticket/173/manpage.py?format=raw">Original Format</a></li></ul></div>

</div>

<div id="footer">
 <p class="left">
  Powered by <a href="/nets/mmedia/about"><strong>Trac 0.9.3</strong></a><br />
  By <a href="http://www.edgewall.com/">Edgewall Software</a>.
 </p>
 <p class="right">
  Visit the AVATS project website at<br /><a href="http://www.cs.ucl.ac.uk/research/avats/">http://www.cs.ucl.ac.uk/research/avats/</a>
 </p>
</div>

 

<!-- Begin footer --> 

<div id="hr"><hr class="no" /> </div>   
<p class="contact_new" align=center>University College London - Gower Street - London - WC1E 6BT - <img src="/extra/phone.gif" width="13" height="9" id="phone" alt="Telephone:" /> +44 (0)20 7679 2000 - Copyright &copy; 1999-2006 UCL</p> 

<div id="inlinelist_new" align=center>

      <ul>
        <li><a href="http://www.ucl.ac.uk/disclaimer/" title="Disclaimer">Disclaimer</a> |  </li>
        <li><a href="http://www.ucl.ac.uk/accessibility/" title="Accessibility">Accessibility</a> | </li>
		<li><a href="http://www.ucl.ac.uk/priv/" title="Privacy">Privacy</a> | </li>

        <li><a href="http://www.ucl.ac.uk/advanced-search/" title="Advanced Search">Advanced Search</a> | </li>
        <li><a href="http://www.ucl.ac.uk/help/" title="Help">Help</a></li>
      </ul>
<br />

</div> 

<!-- End footer -->



 </body>
</html>

