Commits

Walter Dörwald  committed 1b4474e

Updated doc2txt script, to use argparse and to work again.

  • Participants
  • Parent commits 7b03530

Comments (0)

Files changed (1)

File src/ll/xist/scripts/doc2txt.py

 
 
 """
-Module that uses the w3m browser to generate a text version
-of a doc fragment.
-Usage: python doc2txt.py spam.xml spam.txt
+Module that uses :func:`html.astext` to generate a text version of a doc fragment.
+Usage: doc2txt spam.xml spam.txt
        to generate spam.txt from spam.xml
 """
 
 __docformat__ = "reStructuredText"
 
 
-import sys, getopt
+import sys, argparse
 
 from ll.xist import xsc, parse
-from ll.xist.ns import html, doc, text
+from ll.xist.ns import html, doc
 
 
 __docformat__ = "plaintext"
 		)
 	)
 
-	e = e.conv(target=text)
+	e = e.conv()
 
 	file = open(outfilename, "wb")
 	file.write(html.astext(e, width=width))
 
 
 def main(args=None):
-	if args is None:
-		args = sys.argv[1:]
-	title = None
-	width = 72
-	(options, args) = getopt.getopt(args, "t:i:w:", ["title=", "import=", "width="])
+	p = argparse.ArgumentParser(description="Convert an XML file using the ll.xist.ns.doc namespace into plain text")
+	p.add_argument("source", help="input XML file")
+	p.add_argument("target", help="output plain text file")
+	p.add_argument("-t", "--title", dest="title", help="Title for the document")
+	p.add_argument("-w", "--width", dest="width", help="Width of the plain text output", default=72)
 
-	for (option, value) in options:
-		if option=="-t" or option=="--title":
-			title = value
-		elif option=="-i" or option=="--import":
-			__import__(value)
-		if option=="-w" or option=="--width":
-			width = int(value)
+	args = p.parse_args()
 
-	xsc2txt(args[0], args[1], title, width)
+	xsc2txt(args.source, args.target, args.title, args.width)
 
 
 if __name__ == "__main__":