comparison scripts/comment_parser.py @ 1066:a2a245542ae6

Scripts: test if folder name (default or provided via command line) exists
author Brecht De Man <BrechtDeMan@users.noreply.github.com>
date Tue, 11 Aug 2015 10:15:17 +0200
parents 99cb3436759e
children 2ea78697aadf
comparison
equal deleted inserted replaced
1065:b2492aeafe8b 1066:a2a245542ae6
3 3
4 import xml.etree.ElementTree as ET 4 import xml.etree.ElementTree as ET
5 import os 5 import os
6 import csv 6 import csv
7 7
8 # XML results files location (modify as needed): 8
9 folder_name = "../saves" # Looks in 'saves/' folder from 'scripts/' folder 9 # COMMAND LINE ARGUMENTS
10
11 assert len(sys.argv)<3, "comment_parser takes at most 1 command line argument\n"+\
12 "Use: python score_parser.py [rating_folder_location]"
13
14 # XML results files location
15 if len(sys.argv) == 1:
16 folder_name = "../saves" # Looks in 'saves/' folder from 'scripts/' folder
17 print "Use: python comment_parser.py [XML_files_location]"
18 print "Using default path: " + folder_name
19 elif len(sys.argv) == 2:
20 folder_name = sys.argv[1] # First command line argument is folder
21
22 # check if folder_name exists
23 if not os.path.exists(folder_name):
24 #the file is not there
25 print "Folder '"+folder_name+"' does not exist."
26 sys.exit() # terminate script execution
27 elif not os.access(os.path.dirname(folder_name), os.W_OK):
28 #the file does exist but write privileges are not given
29 print "No write privileges in folder '"+folder_name+"'."
30
31
32 # CODE
10 33
11 # get every XML file in folder 34 # get every XML file in folder
12 for file in os.listdir(folder_name): 35 for file in os.listdir(folder_name):
13 if file.endswith(".xml"): 36 if file.endswith(".xml"):
14 tree = ET.parse(folder_name + '/' + file) 37 tree = ET.parse(folder_name + '/' + file)