def main(argv=sys.argv[1:]):
    """The main method."""

    global ext_lang

    parser = argparse.ArgumentParser(description=description,
                                     epilog=epilog)
    parser.add_argument('files', metavar='FILES', nargs='*',
                        help='the files to process')
    parser.add_argument('--version', action='version', version=version)
    parser.add_argument('-i', '--in-place', action='store_true',
                        help='modify files inplace')
    parser.add_argument('--print-langs', action='store_true',
                        help='print out all the supported languages')
    parser.add_argument('--lang', action='store', default='auto',
                        help='use the language with given extention')
    args = parser.parse_args(argv)

    # Print the current set of working languages.
    if args.print_langs:
        parser.print_usage()
        sys.stdout.write('\n')
        sys.stdout.write(textwrap.fill(textwrap.dedent("""\
        The following languages are supported:
        """)) + '\n')
        for cls in sorted({getattr(langs, nm) for nm in langs.__all__}):
            l = cls.__name__
            out = cls.__doc__.split('\n\n')[0]
            out = out + ' (' + ', '.join(cls.ext) + ')'

            prefix2 = ' '.join([''] * 20)
            prefix1 = prefix2[:2] + l + prefix2[2 + len(l):]

            wrapped = textwrap.fill(out, initial_indent=prefix1,
                                    subsequent_indent=prefix2)

            sys.stdout.write(wrapped + '\n')

        parser.exit(0)          # Exit once we're done

    if not args.files:
        parser.print_usage()

    for fname in args.files:
        # load the file
        with open(fname) as f:
            text = f.read()

        # generate the new output according to the language
        if args.lang == 'auto':
            l = language(fname)
        else:
            l = language(args.lang, True)
        text = l.gen(text)

        # emit the output
        if args.in_place:
            with open(fname, 'w') as f:
                f.write(text)
        else:
            sys.stdout.write(text)
def main ( argv = sys . argv [ 1 : ] ) : global ext_lang parser = argparse . ArgumentParser ( description = description , epilog = epilog ) parser . add_argument ( 'files' , metavar = 'FILES' , nargs = '*' , help = 'the files to process' ) parser . add_argument ( '--version' , action = 'version' , version = version ) parser . add_argument ( '-i' , '--in-place' , action = 'store_true' , help = 'modify files inplace' ) parser . add_argument ( '--print-langs' , action = 'store_true' , help = 'print out all the supported languages' ) parser . add_argument ( '--lang' , action = 'store' , default = 'auto' , help = 'use the language with given extention' ) args = parser . parse_args ( argv ) if args . print_langs : parser . print_usage ( ) sys . stdout . write ( '\n' ) sys . stdout . write ( textwrap . fill ( textwrap . dedent ( """\
        The following languages are supported:
        """ ) ) + '\n' ) for cls in sorted ( { getattr ( langs , nm ) for nm in langs . __all__ } ) : l = cls . __name__ out = cls . __doc__ . split ( '\n\n' ) [ 0 ] out = out + ' (' + ', ' . join ( cls . ext ) + ')' prefix2 = ' ' . join ( [ '' ] * 20 ) prefix1 = prefix2 [ : 2 ] + l + prefix2 [ 2 + len ( l ) : ] wrapped = textwrap . fill ( out , initial_indent = prefix1 , subsequent_indent = prefix2 ) sys . stdout . write ( wrapped + '\n' ) parser . exit ( 0 ) if not args . files : parser . print_usage ( ) for fname in args . files : with open ( fname ) as f : text = f . read ( ) if args . lang == 'auto' : l = language ( fname ) else : l = language ( args . lang , True ) text = l . gen ( text ) if args . in_place : with open ( fname , 'w' ) as f : f . write ( text ) else : sys . stdout . write ( text )
The main method.