Edgewall Software

Ticket #7067: manpage.py

File manpage.py, 17.5 KB (added by p.ohanlon@…, 4 years ago)

ManpageRender? python code install to: /usr/lib/python2.4/site-packages/trac/mimeview

Line 
1<!DOCTYPE html
2    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
5<head>
6 <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">
7
8@import url(/css/uclonline.css);
9</style>
10 <script type="text/javascript" src="/nets/mmedia/chrome/common/js/trac.js"></script>
11</head>
12<body>
13<div id="tb-mid_green"> 
14
15    <div id="section_heading"> 
16       <div id="section_head">
17         <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 />
18           <a href="http://www.cs.ucl.ac.uk/"><span id="section_header_white">DEPARTMENT OF COMPUTER SCIENCE</span></a><br />
19           <a href="http://nrg.cs.ucl.ac.uk/"><span id="section_subheader_white">Networked Multimedia</span></a>
20       </div> 
21    </div> 
22
23    <div id="logo_holder"> 
24      <div id="logo"><a href="http://www.cs.ucl.ac.uk/"><img src="/extra/ucl0025_new.gif" alt="UCL Logo" /></a></div> 
25    </div> 
26
27</div> 
28
29
30
31
32
33
34
35
36<div id="metanav" class="nav" style="background-color:#E5EACE">
37<form id="search" action="/nets/mmedia/search" method="get" style="background-color:#F3F5E7">
38 <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>
39 
40  <label for="proj-search">Search:</label>
41  <input type="text" id="proj-search" name="q" size="10" accesskey="f" value="" />
42  <input type="submit" value="Search" />
43  <input type="hidden" name="wiki" value="on" />
44  <input type="hidden" name="changeset" value="on" />
45  <input type="hidden" name="ticket" value="on" />
46 
47</form>
48</div>
49
50<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>
51
52
53<div id="main">
54
55
56
57
58
59
60<div id="ctxtnav" class="nav"></div>
61
62<div id="content" class="attachment">
63
64
65 <h1><a href="/nets/mmedia/ticket/173">Ticket #173</a>: manpage.py</h1>
66 <div id="preview">
67   <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>
68<td><span class="p_commentline"># -*- coding: iso-8859-1 -*-</span></td>
69</tr><tr><th id="L2"><a href="#L2">2</a></th>
70<td><span class="p_commentline">#</span></td>
71</tr><tr><th id="L3"><a href="#L3">3</a></th>
72<td><span class="p_commentline"># Copyright (C) 2004-2006 Edgewall Software</span></td>
73</tr><tr><th id="L4"><a href="#L4">4</a></th>
74<td><span class="p_commentline"># Copyright (C) 2008 Piers O'Hanlon</span></td>
75</tr><tr><th id="L5"><a href="#L5">5</a></th>
76<td><span class="p_commentline"># All rights reserved.</span></td>
77</tr><tr><th id="L6"><a href="#L6">6</a></th>
78<td><span class="p_commentline">#</span></td>
79</tr><tr><th id="L7"><a href="#L7">7</a></th>
80<td><span class="p_commentline"># This software is licensed as described in the file COPYING, which</span></td>
81</tr><tr><th id="L8"><a href="#L8">8</a></th>
82<td><span class="p_commentline"># you should have received as part of this distribution. The terms</span></td>
83</tr><tr><th id="L9"><a href="#L9">9</a></th>
84<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>
85</tr><tr><th id="L10"><a href="#L10">10</a></th>
86<td><span class="p_commentline">#</span></td>
87</tr><tr><th id="L11"><a href="#L11">11</a></th>
88<td><span class="p_commentline"># This software consists of voluntary contributions made by many</span></td>
89</tr><tr><th id="L12"><a href="#L12">12</a></th>
90<td><span class="p_commentline"># individuals. For the exact contribution history, see the revision</span></td>
91</tr><tr><th id="L13"><a href="#L13">13</a></th>
92<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>
93</tr><tr><th id="L14"><a href="#L14">14</a></th>
94<td><span class="p_commentline">#</span></td>
95</tr><tr><th id="L15"><a href="#L15">15</a></th>
96<td><span class="p_commentline"># To enable this extension you need to add </span></td>
97</tr><tr><th id="L16"><a href="#L16">16</a></th>
98<td><span class="p_commentline">#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'trac.mimeview.manpage', </span></td>
99</tr><tr><th id="L17"><a href="#L17">17</a></th>
100<td><span class="p_commentline"># to the following file - to the default_components variable:</span></td>
101</tr><tr><th id="L18"><a href="#L18">18</a></th>
102<td><span class="p_commentline">#../db_default.py:440</span></td>
103</tr><tr><th id="L19"><a href="#L19">19</a></th>
104<td><span class="p_commentline"># default_components = ('trac.About', 'trac.attachment', </span></td>
105</tr><tr><th id="L20"><a href="#L20">20</a></th>
106<td><span class="p_commentline">#</span></td>
107</tr><tr><th id="L21"><a href="#L21">21</a></th>
108<td><span class="p_commentline"># Author: Piers O'Hanlon &lt;p.ohanlon@cs.ucl.ac.uk&gt;</span></td>
109</tr><tr><th id="L22"><a href="#L22">22</a></th>
110<td></td>
111</tr><tr><th id="L23"><a href="#L23">23</a></th>
112<td><span class="p_tripledouble">"""Trac support for nroff man pages</span></td>
113</tr><tr><th id="L24"><a href="#L24">24</a></th>
114<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>
115</tr><tr><th id="L25"><a href="#L25">25</a></th>
116<td><span class="p_tripledouble">"""</span></td>
117</tr><tr><th id="L26"><a href="#L26">26</a></th>
118<td></td>
119</tr><tr><th id="L27"><a href="#L27">27</a></th>
120<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>
121</tr><tr><th id="L28"><a href="#L28">28</a></th>
122<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>
123</tr><tr><th id="L29"><a href="#L29">29</a></th>
124<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>
125</tr><tr><th id="L30"><a href="#L30">30</a></th>
126<td></td>
127</tr><tr><th id="L31"><a href="#L31">31</a></th>
128<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>
129</tr><tr><th id="L32"><a href="#L32">32</a></th>
130<td></td>
131</tr><tr><th id="L33"><a href="#L33">33</a></th>
132<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>
133</tr><tr><th id="L34"><a href="#L34">34</a></th>
134<td>&nbsp; &nbsp; <span class="p_tripledouble">"""Renders nroff man page as HTML."""</span></td>
135</tr><tr><th id="L35"><a href="#L35">35</a></th>
136<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>
137</tr><tr><th id="L36"><a href="#L36">36</a></th>
138<td></td>
139</tr><tr><th id="L37"><a href="#L37">37</a></th>
140<td>&nbsp; &nbsp; <span class="p_identifier">expand_tabs</span> <span class="p_operator">=</span> <span class="p_identifier">False</span></td>
141</tr><tr><th id="L38"><a href="#L38">38</a></th>
142<td></td>
143</tr><tr><th id="L39"><a href="#L39">39</a></th>
144<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>
145</tr><tr><th id="L40"><a href="#L40">40</a></th>
146<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>
147</tr><tr><th id="L41"><a href="#L41">41</a></th>
148<td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="p_word">return</span> <span class="p_number">8</span></td>
149</tr><tr><th id="L42"><a href="#L42">42</a></th>
150<td>&nbsp; &nbsp; &nbsp; &nbsp; <span class="p_word">return</span> <span class="p_number">0</span></td>
151</tr><tr><th id="L43"><a href="#L43">43</a></th>
152<td></td>
153</tr><tr><th id="L44"><a href="#L44">44</a></th>
154<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>
155</tr><tr><th id="L45"><a href="#L45">45</a></th>
156<td>&nbsp; &nbsp; &nbsp; &nbsp; <span class="p_commentline">#cmdline = '/usr/bin/groff -Tutf8 -a -mandoc '</span></td>
157</tr><tr><th id="L46"><a href="#L46">46</a></th>
158<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>
159</tr><tr><th id="L47"><a href="#L47">47</a></th>
160<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>
161</tr><tr><th id="L48"><a href="#L48">48</a></th>
162<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>
163</tr><tr><th id="L49"><a href="#L49">49</a></th>
164<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>
165</tr><tr><th id="L50"><a href="#L50">50</a></th>
166<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>
167</tr><tr><th id="L51"><a href="#L51">51</a></th>
168<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>
169</tr><tr><th id="L52"><a href="#L52">52</a></th>
170<td></td>
171</tr><tr><th id="L53"><a href="#L53">53</a></th>
172<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>
173</tr><tr><th id="L54"><a href="#L54">54</a></th>
174<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>
175</tr><tr><th id="L55"><a href="#L55">55</a></th>
176<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>
177</tr><tr><th id="L56"><a href="#L56">56</a></th>
178<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>
179</tr><tr><th id="L57"><a href="#L57">57</a></th>
180<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>
181</tr><tr><th id="L58"><a href="#L58">58</a></th>
182<td></td>
183</tr><tr><th id="L59"><a href="#L59">59</a></th>
184<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>
185</tr><tr><th id="L60"><a href="#L60">60</a></th>
186<td></td>
187</tr></tbody></table>
188 </div>
189 <div class="buttons">
190  <form method="get" action=""><div id="delete">
191   <input type="hidden" name="action" value="delete" />
192   <input type="submit" value="Delete attachment" />
193  </div></form>
194 </div>
195
196
197</div>
198<script type="text/javascript">searchHighlight()</script>
199<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>
200
201</div>
202
203<div id="footer">
204 <p class="left">
205  Powered by <a href="/nets/mmedia/about"><strong>Trac 0.9.3</strong></a><br />
206  By <a href="http://www.edgewall.com/">Edgewall Software</a>.
207 </p>
208 <p class="right">
209  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>
210 </p>
211</div>
212
213 
214
215<!-- Begin footer --> 
216
217<div id="hr"><hr class="no" /> </div>   
218<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> 
219
220<div id="inlinelist_new" align=center>
221
222      <ul>
223        <li><a href="http://www.ucl.ac.uk/disclaimer/" title="Disclaimer">Disclaimer</a> |  </li>
224        <li><a href="http://www.ucl.ac.uk/accessibility/" title="Accessibility">Accessibility</a> | </li>
225                <li><a href="http://www.ucl.ac.uk/priv/" title="Privacy">Privacy</a> | </li>
226
227        <li><a href="http://www.ucl.ac.uk/advanced-search/" title="Advanced Search">Advanced Search</a> | </li>
228        <li><a href="http://www.ucl.ac.uk/help/" title="Help">Help</a></li>
229      </ul>
230<br />
231
232</div> 
233
234<!-- End footer -->
235
236
237
238 </body>
239</html>
240