Created
August 21, 2014 19:51
-
-
Save major/2de0053313bc515b1e30 to your computer and use it in GitHub Desktop.
ansible #8640/#8642
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [root@builder ~]# python test.py /var/www/html | |
| #8642 -----> | |
| /var | |
| /var/www | |
| /var/www/html | |
| #8640 -----> | |
| / | |
| //var | |
| //var/www | |
| //var/www/html | |
| [root@builder ~]# python test.py test_dir | |
| #8642 -----> | |
| test_dir | |
| #8640 -----> | |
| / | |
| //root | |
| //root/test_dir |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import sys | |
| path = sys.argv[1] | |
| print "#8642 ----->" | |
| curpath = '' | |
| for dirname in path.strip('/').split('/'): | |
| curpath = '/'.join([curpath, dirname]) | |
| if not os.path.isabs(path): | |
| curpath = curpath.lstrip('/') | |
| print curpath | |
| print "#8640 ----->" | |
| curpath = '' | |
| for dirname in os.path.realpath(path).split('/'): | |
| curpath = '/'.join([curpath, dirname]) | |
| print curpath |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adding this test:
print "# proper join/split ----->" curpath = '' for dirname in os.path.split(os.path.realpath(path)): curpath = os.path.join(curpath, dirname) print curpathOutput: