def format_epilog(self, epilog): if epilog: return "\n" + ("-" * int(self.width / 2)) + "\n" + "".join([ TitledHelpFormatter.format_epilog(self, d) for d in epilog.split("\n\n") ]) else: return ""
def format_epilog(self,epilog): if epilog: return "\n"+("-"*int(self.width/2))+"\n"+"".join( [TitledHelpFormatter.format_epilog(self,d) for d in epilog.split("\n\n")]) else: return ""
def parse_args(available_configs): todb = [] one_args = {} def buggy_callback(option, opt, value, parser): todb.append(value) def one_arg_callback(option, opt, value, parser): k, v = value.split('=', 1) try: v = int(v) except: pass one_args[k] = v epilog = """ In the above options, MODULE is always a module name in the abstraction_level:module_name format (e.g. caba:vci_ram). Run soclib-cc --examples to see some common command-line examples. """ f = TitledHelpFormatter() f.format_epilog = lambda x: x try: parser = OptionParser( usage= "%prog [ -m mode ] [ -t config ] [ -vqd ] [ -c -o output input | -p pf_desc ]", epilog=epilog, formatter=f) except TypeError: parser = OptionParser( usage= "%prog [ -m mode ] [ -t config ] [ -vqd ] [ -c -o output input | -p pf_desc ]" ) parser.add_option('--examples', dest='examples', action='store_true', help="Show some example commands") group = OptionGroup(parser, "Pretty printing") parser.add_option_group(group) group.add_option('-q', '--quiet', dest='quiet', action='store_true', help="Print nothing but errors") group.add_option('-v', '--verbose', dest='verbose', action='store_true', help="Chat a lot") group.add_option('-d', '--debug', dest='debug', action='store_true', help="Print too much things") group.add_option('-P', '--progress_bar', dest='progress_bar', action='store_true', help="Print evolution with a progress bar") group = OptionGroup( parser, "Environment tweaks", "These options can change the build flags or the " "index of modules") parser.add_option_group(group) group.add_option('-I', dest='includes', metavar="DIR", action='append', nargs=1, help="Append directory to .sd search path") group.add_option('-m', '--mode', dest='mode', action='store', nargs=1, default='release', help="Select mode: *release|debug|prof", choices=("release", "debug", "prof")) group.add_option('-t', '--type', dest='type', action='store', choices=available_configs, help="Use a different configuration: <*%s>" % (', '.join(available_configs))) group.add_option( '-b', '--buggy', nargs=1, type="string", metavar="MODULE", action='callback', callback=buggy_callback, help= "Put MODULE in debug mode (disable opt, set SOCLIB_MODULE_DEBUG preprocessor variable)" ) group = OptionGroup( parser, "Information gathering", "These options show various information " "about the currently indexed modules " "and SoCLib environment") parser.add_option_group(group) group.add_option('--getpath', dest='getpath', action='store_true', help="Print soclib path") group.add_option('-l', dest='list_descs', action='store_const', const="long", help="List known descriptions == --list-descs=long") group.add_option( '--list-descs', dest='list_descs', metavar="FORMAT", action='store', nargs=1, choices=("long", "names"), help="List known descriptions. Format may be 'long' or 'names'") group.add_option('--list-files', dest='list_files', metavar="MODULE", action='store', nargs=1, type='string', help="List files belonging to a given module") group.add_option('--complete-name', dest='complete_name', metavar="MODULE", action='store', nargs=1, type='string', help="Complete module name starting with ...") group.add_option('--complete-separator', dest='complete_separator', metavar="SEP", action='store', nargs=1, type='string', default=':', help="Complete words splitted by this arg") group.add_option('--getflags', dest='getflags', metavar="KIND", action='store', choices=("cflags", ), help="Get flags of some KIND <cflags>") group.add_option('--embedded-cflags', dest='embedded_cflags', action='store_true', help="Print software include directories C flags") group = OptionGroup( parser, "Compilation tweaks", "These options change various behaviors of the compilation itself") parser.add_option_group(group) group.add_option('-j', '--jobs', dest='jobs', metavar="N", action='store', type='int', default=0, help="Allow N parallel jobs") group.add_option('--work', dest='workpath', metavar="DIR", action='store', help="When using ModelSim, use this work DIR") group = OptionGroup(parser, "What to do", "These options tell soclib-cc what to do") parser.add_option_group(group) group.add_option('-c', '--compile', dest='compile', action='store_true', help="Do a simple compilation, not a linkage") group.add_option('-x', '--clean', dest='clean', action='store_true', help="Clean all outputs, only compatible with -p") group.add_option('-X', '--clean-cache', dest='clean_cache', action='store_true', help="Clean .desc file cache") group.add_option('-o', '--output', dest='output', action='store', type='string', help="Select output file") group.add_option( '-F', '--format', dest='formatter', action='store', nargs=1, type='string', help='Use a given formatter class name to format build actions') group.add_option('--tags', dest='tags', action='store_true', help="Ouput tags database, only compatible with -p") group.add_option( '--tags-type', dest='tags_type', metavar="FORMAT", action='store', nargs=1, choices=("cscope", "ctags"), default="cscope", help="Specify tags format: cscope or ctags [default is %default]") group.add_option( '--tags-output', dest='tags_output', metavar="FILE", action='store', nargs=1, type="string", help="Specify tags filename (e.g. 'cscope.out', 'tags', etc.)") group.add_option('-p', '--platform', dest='platform', metavar="PLATFORM_DESC", action='store', type='string', help="Use a platform description PLATFORM_DESC") group.add_option( '-1', '--one-module', nargs=1, type="string", metavar="MODULE", action='store', dest='one_module', help="Only try to compile MODULE (try -a for the parameters)") group.add_option('-a', '--arg', nargs=1, type="string", metavar="KEY=VALUE", action='callback', callback=one_arg_callback, help="Specify arguments for one-module build") group = OptionGroup(parser, "Debugging") parser.add_option_group(group) group.add_option('--dump-config', dest='dump_config', action='store_true', help="Dump configuration") group.add_option('--bug-report', dest='bug_report', action='store_true', help="Create a bug-reporting log") group.add_option( '--auto-bug-report', dest='auto_bug_report', metavar="METHOD", action='store', nargs=1, help="Auto report bug. Methods allowed: openbrowser, *none", choices=("openbrowser", "none")) parser.set_defaults(auto_bug_report="none", includes=[], workpath='work', embedded_cflags=False) opts, args = parser.parse_args() return opts, args, todb, one_args, parser