Mercurial > hg > webaudioevaluationtool
comparison scripts/score_parser.py @ 1805:bcbc8bc12afe
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 | 032bcca680a5 |
| children | 2ea78697aadf |
comparison
equal
deleted
inserted
replaced
| 1804:b84d94791764 | 1805:bcbc8bc12afe |
|---|---|
| 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) |
