| 71 | # Helper function to locate and open the target file (passed in as a string). |
| 72 | # Returns the full path to the file as a string. |
| 73 | def findFileOrThrow(strBasename): |
| 74 | # Keep constant names in C-style convention, for readability |
| 75 | # when comparing to C(/C++) code. |
| 76 | if os.path.isfile(strBasename): |
| 77 | return strBasename |
| 78 | |
| 79 | LOCAL_FILE_DIR = "data" + os.sep |
| 80 | GLOBAL_FILE_DIR = os.path.dirname(os.path.abspath(__file__)) + os.sep + "data" + os.sep |
| 81 | |
| 82 | strFilename = LOCAL_FILE_DIR + strBasename |
| 83 | if os.path.isfile(strFilename): |
| 84 | return strFilename |
| 85 | |
| 86 | strFilename = GLOBAL_FILE_DIR + strBasename |
| 87 | if os.path.isfile(strFilename): |
| 88 | return strFilename |
| 89 | |
| 90 | raise IOError('Could not find target file ' + strBasename) |