From: David G. <go...@us...> - 2002-07-27 03:52:49
|
Update of /cvsroot/docutils/docutils/tools In directory usw-pr-cvs1:/tmp/cvs-serv9911/docutils/tools Modified Files: quicktest.py Log Message: Added a second command-line argument (output file); cleaned up. Index: quicktest.py =================================================================== RCS file: /cvsroot/docutils/docutils/tools/quicktest.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** quicktest.py 4 Jul 2002 01:29:40 -0000 1.5 --- quicktest.py 27 Jul 2002 03:52:46 -0000 1.6 *************** *** 27,33 **** Usage:: ! quicktest.py [options] [filename] ! ``filename`` is the name of the file to use as input (default is stdin). Options: --- 27,35 ---- Usage:: ! quicktest.py [options] [<source> [<destination>]] ! ``source`` is the name of the file to use as input (default is stdin). ! ``destination`` is the name of the file to create as output (default is ! stdout). Options: *************** *** 39,44 **** 'ready to be copied to a parser test module)'), ('rawxml', 'r', 'output raw XML'), ! ('styledxml=', 's', 'output raw XML with XSL style sheet reference ' ! '(filename supplied in the option argument)'), ('xml', 'x', 'output pretty XML (indented)'), ('attributes', '', 'dump document attributes after processing'), --- 41,46 ---- 'ready to be copied to a parser test module)'), ('rawxml', 'r', 'output raw XML'), ! ('styledxml=', 's', 'output raw XML with XSL style sheet ' ! 'reference (filename supplied in the option argument)'), ('xml', 'x', 'output pretty XML (indented)'), ('attributes', '', 'dump document attributes after processing'), *************** *** 75,80 **** return '%s\n%s\n%s' % ( '<?xml version="1.0" encoding="ISO-8859-1"?>', ! '<?xml-stylesheet type="text/xsl" href="%s"?>' % optargs['styledxml'], ! docnode.toxml()) def _prettyxml(input, document, optargs): --- 77,82 ---- return '%s\n%s\n%s' % ( '<?xml version="1.0" encoding="ISO-8859-1"?>', ! '<?xml-stylesheet type="text/xsl" href="%s"?>' ! % optargs['styledxml'], docnode.toxml()) def _prettyxml(input, document, optargs): *************** *** 97,101 **** def escape(text): """ ! Return `text` in a form compatible with triple-double-quoted Python strings. """ text = text.replace('\\', '\\\\') # escape backslashes --- 99,103 ---- def escape(text): """ ! Return `text` in triple-double-quoted Python string form. """ text = text.replace('\\', '\\\\') # escape backslashes *************** *** 155,185 **** else: raise getopt.GetoptError, "getopt should have saved us!" ! if len(args) > 1: ! print "Only one file at a time, thanks." usage() sys.exit(1) ! if len(args) == 1: ! inputFile = open(args[0]) ! else: ! inputFile = sys.stdin ! return inputFile, outputFormat, optargs def macGetArgs(): import EasyDialogs EasyDialogs.Message("""\ ! In the following window, please: ! 1. Choose an output format from the "Option" list. ! 2. Click "Add" (if you don't, the default format will ! be "pretty"). ! 3. Click "Add existing file..." and choose an input file. ! 4. Click "OK".""") optionlist = [(longopt, description) for (longopt, shortopt, description) in options] ! argv = EasyDialogs.GetArgv(optionlist=optionlist, addnewfile=0, addfolder=0) return posixGetArgs(argv) def main(): ! inputFile, outputFormat, optargs = getArgs() # process cmdline arguments options = OptionParser().get_default_values() options.debug = optargs['debug'] --- 157,190 ---- else: raise getopt.GetoptError, "getopt should have saved us!" ! if len(args) > 2: ! print 'Maximum 2 arguments allowed.' usage() sys.exit(1) ! inputFile = sys.stdin ! outputFile = sys.stdout ! if args: ! inputFile = open(args.pop(0)) ! if args: ! outputFile = open(args.pop(0), 'w') ! return inputFile, outputFile, outputFormat, optargs def macGetArgs(): import EasyDialogs EasyDialogs.Message("""\ ! Use the next dialog to build a command line: ! 1. Choose an output format from the [Option] list ! 2. Click [Add] ! 3. Choose an input file: [Add existing file...] ! 4. Save the output: [Add new file...] ! 5. [OK]""") optionlist = [(longopt, description) for (longopt, shortopt, description) in options] ! argv = EasyDialogs.GetArgv(optionlist=optionlist, addfolder=0) return posixGetArgs(argv) def main(): ! # process cmdline arguments: ! inputFile, outputFile, outputFormat, optargs = getArgs() options = OptionParser().get_default_values() options.debug = optargs['debug'] *************** *** 189,193 **** parser.parse(input, document) output = format(outputFormat, input, document, optargs) ! print output, if optargs['attributes']: import pprint --- 194,198 ---- parser.parse(input, document) output = format(outputFormat, input, document, optargs) ! outputFile.write(output) if optargs['attributes']: import pprint |