python 蟒蛇修改文件或文件夹权限
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 蟒蛇修改文件或文件夹权限相关的知识,希望对你有一定的参考价值。
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))
以上是关于python 蟒蛇修改文件或文件夹权限的主要内容,如果未能解决你的问题,请参考以下文章