1
0
mirror of https://github.com/altlinux/gpupdate.git synced 2025-03-21 18:50:38 +03:00

util.mk_homedir_path to create paths in user's directory

This commit is contained in:
Игорь Чудов 2019-12-10 18:58:29 +04:00
parent 37d0c89156
commit 289ef8cc16
Signed by untrusted user: nir
GPG Key ID: 0F3883600CAE7AAC

View File

@ -141,3 +141,14 @@ def get_homedir(username):
'''
return pwd.getpwnam(username).pw_dir
def mk_homedir_path(username, homedir_path):
homedir = get_homedir(username)
uid = pwd.getpwnam(username).pw_uid
elements = homedir_path.split('/')
longer_path = homedir
for elem in elements:
os.makedirs(longer_path, exist_ok=True)
os.chown(homedir, uid=uid, gid=-1)
longer_path = os.path.join(longer_path, elem)
logging.debug('Created directory {} for user {}'.format(longer_path, username))