PageRenderTime 10ms CodeModel.GetById 6ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/lib/python/indra/util/helpformatter.py

https://bitbucket.org/lindenlab/viewer-beta/
Python | 52 lines | 42 code | 0 blank | 10 comment | 0 complexity | dde7bc38afc464600e694d674260c548 MD5 | raw file
 1"""\
 2@file helpformatter.py
 3@author Phoenix
 4@brief Class for formatting optparse descriptions.
 5
 6$LicenseInfo:firstyear=2007&license=mit$
 7
 8Copyright (c) 2007-2009, Linden Research, Inc.
 9
10Permission is hereby granted, free of charge, to any person obtaining a copy
11of this software and associated documentation files (the "Software"), to deal
12in the Software without restriction, including without limitation the rights
13to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14copies of the Software, and to permit persons to whom the Software is
15furnished to do so, subject to the following conditions:
16
17The above copyright notice and this permission notice shall be included in
18all copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26THE SOFTWARE.
27$/LicenseInfo$
28"""
29
30import optparse
31import textwrap
32
33class Formatter(optparse.IndentedHelpFormatter):
34    def __init__(
35        self, 
36        p_indentIncrement = 2, 
37        p_maxHelpPosition = 24,
38        p_width = 79,
39        p_shortFirst = 1) :
40        optparse.HelpFormatter.__init__(
41            self, 
42            p_indentIncrement,
43            p_maxHelpPosition, 
44            p_width, 
45            p_shortFirst)
46    def format_description(self, p_description):
47        t_descWidth = self.width - self.current_indent
48        t_indent = " " * (self.current_indent + 2)
49        return "\n".join(
50            [textwrap.fill(descr, t_descWidth, initial_indent = t_indent,
51                           subsequent_indent = t_indent)
52             for descr in p_description.split("\n")] )