[dots] Write result to output file



commit d84f5a6d10d1c601d044f73a8d76eee0f625a494
Author: Fernando Herrera <fherrera onirica com>
Date:   Mon Jun 7 21:49:56 2010 +0200

    Write result to output file

 dots/dotscmd.py |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/dots/dotscmd.py b/dots/dotscmd.py
index 60e82ca..0a3f089 100755
--- a/dots/dotscmd.py
+++ b/dots/dotscmd.py
@@ -56,7 +56,7 @@ if len(args) != 1:
 	parser.error("incorrect number of arguments")
 	exit(1)
 
-if not os.access(args[0], os.R_OK):
+if not os.access(args[0], os.R_OK) or not os.path.isfile (args[0]):
 	print ("Cannot open input file " + args[0])
 	exit(1)
 	
@@ -103,7 +103,20 @@ config_builder['outputFormat']['LinesPerPage'] = options.lines
 config_builder['outputFormat']['braillePageNumberAt'] =  options.page_position
 
 d.translate (config_builder)
-print d.get_braille_text ()
+
+if options.output is not None:
+	output_file = options.output
+else:
+	output_file = os.path.basename (args[0]) + ".brl"
+
+try:
+		f = open (output_file, 'w')
+except IOError, (errno, strerror):
+        print "Cannot write to %s: %s" % (output_file, strerror)
+	exit(1)
+
+f.write(d.get_braille_text ())
+f.close()
 
 
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]