Last active
October 10, 2018 19:28
-
-
Save search5/530e890d527b718a45165a63d5d6d746 to your computer and use it in GitHub Desktop.
Python zipfile의 ZipInfo 인스턴스에 있는 external_attr을 받아서 파일 퍼미션을 구하는 함수
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
def permission(external_attr): | |
stat_ix = (4, 2, 1) | |
user_perm = 0 | |
for mode_num, mode in zip(stat_ix, (stat.S_IRUSR, stat.S_IWUSR, stat.S_IXUSR)): | |
if (external_attr & mode) > 0: | |
user_perm += mode_num | |
grp_perm = 0 | |
for mode_num, mode in zip(stat_ix, (stat.S_IRGRP, stat.S_IWGRP, stat.S_IXGRP)): | |
if (external_attr & mode) > 0: | |
grp_perm += mode_num | |
oth_perm = 0 | |
for mode_num, mode in zip(stat_ix, (stat.S_IROTH, stat.S_IWOTH, stat.S_IXOTH)): | |
if (external_attr & mode) > 0: | |
oth_perm += mode_num | |
return int('0o{0}{1}{2}'.format(user_perm, grp_perm, oth_perm), 8) | |
if __name__ == "__main__": | |
st_mode = (333534 >> 16) & 0xFFFF | |
perm = permission(st_mode) | |
(install_path / str(entry.filename)).chmod(perm) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment