MCPcopy
hub / github.com/corpnewt/gibMacOS / check_path

Method check_path

Scripts/utils.py:103–135  ·  view source on GitHub ↗
(self, path)

Source from the content-addressed store, hash-verified

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

Callers 3

select_packageMethod · 0.80
mainMethod · 0.80
mainMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected