CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/HLTrigger/Configuration/scripts/extend_argparse.py

Go to the documentation of this file.
00001 import argparse as _argparse
00002 import textwrap as _textwrap
00003 
00004 # argparse's formatters remove newlines from comand descriptions, so we define a new one
00005 class HelpFormatterRespectNewlines(_argparse.HelpFormatter):
00006     """Help message formatter which retains line breaks in argument descriptions.
00007 
00008     Only the name of this class is considered a public API. All the methods
00009     provided by the class are considered an implementation detail.
00010     """
00011 
00012     def _split_lines(self, text, width):
00013         lines = []
00014         for line in text.splitlines():
00015           line = self._whitespace_matcher.sub(' ', line).strip()
00016           lines.extend( _textwrap.wrap(line, width) )
00017         return lines
00018 
00019 # argparse's formatters are not really able to discover the terminale size, so we override them
00020 def FixedWidthFormatter(formatter, width):
00021   """Adaptor for argparse formatters using an explicit fixed width
00022   """
00023   def f(*args, **keywords):
00024     # add or replace the "width" parameter
00025     keywords['width'] = width
00026     return formatter(*args, **keywords)
00027 
00028   return f
00029