Last active
November 14, 2018 07:38
-
-
Save ayuLiao/9bb072b7e6b55ec8ee729867575493ac to your computer and use it in GitHub Desktop.
python修改文件或文件夹权限
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 modify_permiss(self, path, name,R=True): | |
| ''' | |
| change file or directory permission | |
| :param name: linux user name\ | |
| :param R: Recursive modify permission | |
| :return: | |
| ''' | |
| idshell = 'id %s'%(name) | |
| code, output = self.execshell(idshell) | |
| if 'No such' not in output: | |
| uid = re.findall('uid=(.*?)\(', output)[0] | |
| gid = re.findall('gid=(.*?)\(', output)[0] | |
| gname = re.findall('\((.*?)\)', output)[1] | |
| if R: | |
| chownshell = 'chown -R %s:%s %s'%(name, gname, path) | |
| code, output = self.execshell(chownshell) | |
| else: | |
| os.chown(path, int(uid), int(gid)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment