Tweaking role path searching in v2 to be a bit more like v1

This commit is contained in:
James Cammarata
2015-01-29 10:55:00 -06:00
parent e4a7b973fd
commit 171a67cfef
3 changed files with 22 additions and 15 deletions

View File

@@ -18,9 +18,18 @@
import os
import stat
__all__ = ['is_executable']
__all__ = ['is_executable', 'unfrackpath']
def is_executable(path):
'''is the given path executable?'''
return (stat.S_IXUSR & os.stat(path)[stat.ST_MODE] or stat.S_IXGRP & os.stat(path)[stat.ST_MODE] or stat.S_IXOTH & os.stat(path)[stat.ST_MODE])
def unfrackpath(path):
'''
returns a path that is free of symlinks, environment
variables, relative path traversals and symbols (~)
example:
'$HOME/../../var/mail' becomes '/var/spool/mail'
'''
return os.path.normpath(os.path.realpath(os.path.expandvars(os.path.expanduser(path))))