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