diff options
author | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-04-27 11:46:51 +0100 |
---|---|---|
committer | Thomas Mangin <thomas.mangin@exa.net.uk> | 2020-04-27 11:51:53 +0100 |
commit | 2bf12b579e083a8b527d3202ced365b8adf32625 (patch) | |
tree | bce48dcc8aede9d3578c374f86a7932319de58e0 /python/vyos/util.py | |
parent | cff252427c1aa9c8fe0cf7a305c2a5a294c71773 (diff) | |
download | vyos-1x-2bf12b579e083a8b527d3202ced365b8adf32625.tar.gz vyos-1x-2bf12b579e083a8b527d3202ced365b8adf32625.zip |
template: T2388: move mkdir/chmod/chown within render()
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r-- | python/vyos/util.py | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py index 4340332d3..bfbc88922 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -197,10 +197,24 @@ def chown(path, user, group): from pwd import getpwnam from grp import getgrnam - if os.path.exists(path): - uid = getpwnam(user).pw_uid - gid = getgrnam(group).gr_gid - os.chown(path, uid, gid) + if user is None or group is None: + return False + + if not os.path.exists(path): + return False + + uid = getpwnam(user).pw_uid + gid = getgrnam(group).gr_gid + os.chown(path, uid, gid) + return True + + +def chmod(path, bitmask): + if not os.path.exists(path): + return + if bitmask is None: + return + os.chmod(path, bitmask) def chmod_600(path): @@ -231,6 +245,13 @@ def chmod_755(path): os.chmod(path, bitmask) +def makedir(path, user=None, group=None): + if not os.path.exists(path): + return + os.mkdir(path) + chown(path, user, group) + + def colon_separated_to_dict(data_string, uniquekeys=False): """ Converts a string containing newline-separated entries of colon-separated key-value pairs into a dict. |