[dots] Check for input file and table



commit fe9fe24379e58a3bf743bab902b83b6d3d4197e0
Author: Fernando Herrera <fherrera onirica com>
Date:   Mon Jun 7 21:36:30 2010 +0200

    Check for input file and table

 dots/dotscmd.py |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/dots/dotscmd.py b/dots/dotscmd.py
index d5cf87b..60e82ca 100755
--- a/dots/dotscmd.py
+++ b/dots/dotscmd.py
@@ -17,6 +17,10 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+import os
+from sys import exit
+import host_settings
+
 from optparse import OptionParser
 from config_builder import ConfigBuilder
 from document_builder import document_new 
@@ -50,12 +54,27 @@ parser.add_option("-x", "--page-position", dest="page_position", metavar="POS",
 (options, args) = parser.parse_args()
 if len(args) != 1:
 	parser.error("incorrect number of arguments")
+	exit(1)
+
+if not os.access(args[0], os.R_OK):
+	print ("Cannot open input file " + args[0])
+	exit(1)
+	
 
 if options.table is None:
 	parser.error("a translation table must be specified")
+	exit(1)
 
 if options.page_position is not "top" and not "bottom":
 	parser.error("page postion can only be top or bottom")
+	exit(1)
+
+if not os.access(options.table, os.R_OK) and not os.access(os.path.join (host_settings.tablesdir, options.table), os.R_OK):
+	print ("Cannot open table " + options.table)
+	print ("Installed tables are:")
+	for file in os.listdir(host_settings.tablesdir):
+		print "\t" + file
+	exit(1)
 
 d = document_new (args[0])
 config_builder = ConfigBuilder()



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