| 100 | return (var1, var2) |
| 101 | |
| 102 | def check_path(self, path): |
| 103 | # Let's loop until we either get a working path, or no changes |
| 104 | test_path = path |
| 105 | last_path = None |
| 106 | while True: |
| 107 | # Bail if we've looped at least once and the path didn't change |
| 108 | if last_path != None and last_path == test_path: return None |
| 109 | last_path = test_path |
| 110 | # Check if we stripped everything out |
| 111 | if not len(test_path): return None |
| 112 | # Check if we have a valid path |
| 113 | if os.path.exists(test_path): |
| 114 | return os.path.abspath(test_path) |
| 115 | # Check for quotes |
| 116 | if test_path[0] == test_path[-1] and test_path[0] in ('"',"'"): |
| 117 | test_path = test_path[1:-1] |
| 118 | continue |
| 119 | # Check for a tilde and expand if needed |
| 120 | if test_path[0] == "~": |
| 121 | tilde_expanded = os.path.expanduser(test_path) |
| 122 | if tilde_expanded != test_path: |
| 123 | # Got a change |
| 124 | test_path = tilde_expanded |
| 125 | continue |
| 126 | # Let's check for spaces - strip from the left first, then the right |
| 127 | if test_path[0] in (" ","\t"): |
| 128 | test_path = test_path[1:] |
| 129 | continue |
| 130 | if test_path[-1] in (" ","\t"): |
| 131 | test_path = test_path[:-1] |
| 132 | continue |
| 133 | # Maybe we have escapes to handle? |
| 134 | test_path = "\\".join([x.replace("\\", "") for x in test_path.split("\\\\")]) |
| 135 | |
| 136 | def grab(self, prompt, **kwargs): |
| 137 | # Takes a prompt, a default, and a timeout and shows it with that timeout |