Package Ganga :: Package Utility :: Module ospath_fix
[hide private]
[frames] | no frames]

Source Code for Module Ganga.Utility.ospath_fix

 1  # on some python 2.3 distributions the os.path.realpath() is broken and the symlinks are 
 2  # resolved wrt to the current working directory 
 3   
 4  import os.path 
 5   
6 -def realpath(filename):
7 """Return the canonical path of the specified filename, eliminating any 8 symbolic links encountered in the path.""" 9 if os.path.isabs(filename): 10 bits = ['/'] + filename.split('/')[1:] 11 else: 12 bits = [''] + filename.split('/') 13 14 for i in range(2, len(bits)+1): 15 component = os.path.join(*bits[0:i]) 16 # Resolve symbolic links. 17 if os.path.islink(component): 18 resolved = _resolve_link(component) 19 if resolved is None: 20 # Infinite loop -- return original component + rest of the path 21 return os.path.abspath(os.path.join(*([component] + bits[i:]))) 22 else: 23 newpath = os.path.join(*([resolved] + bits[i:])) 24 return realpath(newpath) 25 26 return os.path.abspath(filename)
27 28 48 49 os.path.realpath = realpath 50 os.path._resolve_link = _resolve_link 51