changeset 284:f32e58635091

Scripts: test if folder name (default or provided via command line) exists
author Brecht De Man <b.deman@qmul.ac.uk>
date Tue, 11 Aug 2015 10:15:17 +0200
parents a1c1f032ff0a
children 037393e98cd9
files scripts/comment_parser.py scripts/score_parser.py scripts/score_plot.py scripts/timeline_view.py
diffstat 4 files changed, 62 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/comment_parser.py	Mon Aug 10 18:45:45 2015 +0200
+++ b/scripts/comment_parser.py	Tue Aug 11 10:15:17 2015 +0200
@@ -5,8 +5,31 @@
 import os
 import csv
 
-# XML results files location (modify as needed):
-folder_name = "../saves"    # Looks in 'saves/' folder from 'scripts/' folder
+
+# COMMAND LINE ARGUMENTS
+
+assert len(sys.argv)<3, "comment_parser takes at most 1 command line argument\n"+\
+                        "Use: python score_parser.py [rating_folder_location]"
+
+# XML results files location
+if len(sys.argv) == 1:
+    folder_name = "../saves"    # Looks in 'saves/' folder from 'scripts/' folder
+    print "Use: python  comment_parser.py [XML_files_location]"
+    print "Using default path: " + folder_name
+elif len(sys.argv) == 2:
+    folder_name = sys.argv[1]   # First command line argument is folder
+
+# check if folder_name exists
+if not os.path.exists(folder_name):
+    #the file is not there
+    print "Folder '"+folder_name+"' does not exist."
+    sys.exit() # terminate script execution
+elif not os.access(os.path.dirname(folder_name), os.W_OK):
+    #the file does exist but write privileges are not given
+    print "No write privileges in folder '"+folder_name+"'."
+
+
+# CODE
 
 # get every XML file in folder
 for file in os.listdir(folder_name): 
--- a/scripts/score_parser.py	Mon Aug 10 18:45:45 2015 +0200
+++ b/scripts/score_parser.py	Tue Aug 11 10:15:17 2015 +0200
@@ -20,6 +20,18 @@
 elif len(sys.argv) == 2:
     folder_name = sys.argv[1]   # First command line argument is folder
 
+# check if folder_name exists
+if not os.path.exists(folder_name):
+    #the file is not there
+    print "Folder '"+folder_name+"' does not exist."
+    sys.exit() # terminate script execution
+elif not os.access(os.path.dirname(folder_name), os.W_OK):
+    #the file does exist but write privileges are not given
+    print "No write privileges in folder '"+folder_name+"'."
+
+    
+# CODE
+
 # get every XML file in folder
 for file in os.listdir(folder_name):
     if file.endswith(".xml"):
--- a/scripts/score_plot.py	Mon Aug 10 18:45:45 2015 +0200
+++ b/scripts/score_plot.py	Tue Aug 11 10:15:17 2015 +0200
@@ -55,9 +55,10 @@
             print "            Enables plot of individual ratings" 
             print ""
             print "PLOT OPTIONS"
-            print "    legend | -l"
+            print "    leg | legend | -l"
             print "            For individual plot: show legend with individual file names"
-            print "    "
+            print "    numeric value between 0 and 1, e.g. 0.95"
+            print "            For confidence interval plot: confidence value"
             assert False, ""# stop immediately after showing help #TODO cleaner way
             
         # PLOT TYPES
@@ -81,6 +82,8 @@
                       "confidence plot is enabled"
             if float(arg)>0 and float(arg)<1:
                 confidence = float(arg)
+            else: 
+                print "WARNING: The confidence value needs to be between 0 and 1"
         
          # FOLDER NAME
          else: 
@@ -92,11 +95,18 @@
 if not enable_boxplot and not enable_confidence and not enable_individual:
     enable_boxplot = True
 
+# check if folder_name exists
+if not os.path.exists(rating_folder):
+    #the file is not there
+    print "Folder '"+rating_folder+"' does not exist."
+    sys.exit() # terminate script execution
+elif not os.access(os.path.dirname(rating_folder), os.W_OK):
+    #the file does exist but write rating_folder are not given
+    print "No write privileges in folder '"+rating_folder+"'."
+
+
 # CONFIGURATION
 
-# Enter folder where rating CSV files are (generated with score_parser.py or same format).
-rating_folder = '../saves/ratings/' # folder with rating csv files
-
 # Font settings
 font = {'weight' : 'bold',
         'size'   : 10}
--- a/scripts/timeline_view.py	Mon Aug 10 18:45:45 2015 +0200
+++ b/scripts/timeline_view.py	Tue Aug 11 10:15:17 2015 +0200
@@ -17,6 +17,16 @@
     print "Using default path: " + folder_name
 elif len(sys.argv) == 2:
     folder_name = sys.argv[1]   # First command line argument is folder
+    
+# check if folder_name exists
+if not os.path.exists(folder_name):
+    #the file is not there
+    print "Folder '"+folder_name+"' does not exist."
+    sys.exit() # terminate script execution
+elif not os.access(os.path.dirname(folder_name), os.W_OK):
+    #the file does exist but write privileges are not given
+    print "No write privileges in folder '"+folder_name+"'."
+
 
 # CONFIGURATION