comparison scripts/score_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
17 folder_name = "../saves" # Looks in 'saves/' folder from 'scripts/' folder 17 folder_name = "../saves" # Looks in 'saves/' folder from 'scripts/' folder
18 print "Use: python score_parser.py [rating_folder_location]" 18 print "Use: python score_parser.py [rating_folder_location]"
19 print "Using default path: " + folder_name 19 print "Using default path: " + folder_name
20 elif len(sys.argv) == 2: 20 elif len(sys.argv) == 2:
21 folder_name = sys.argv[1] # First command line argument is folder 21 folder_name = sys.argv[1] # First command line argument is folder
22
23 # check if folder_name exists
24 if not os.path.exists(folder_name):
25 #the file is not there
26 print "Folder '"+folder_name+"' does not exist."
27 sys.exit() # terminate script execution
28 elif not os.access(os.path.dirname(folder_name), os.W_OK):
29 #the file does exist but write privileges are not given
30 print "No write privileges in folder '"+folder_name+"'."
31
32
33 # CODE
22 34
23 # get every XML file in folder 35 # get every XML file in folder
24 for file in os.listdir(folder_name): 36 for file in os.listdir(folder_name):
25 if file.endswith(".xml"): 37 if file.endswith(".xml"):
26 tree = ET.parse(folder_name + '/' + file) 38 tree = ET.parse(folder_name + '/' + file)