From 51d40aa5accc446953df4db8a93243233d29e44a Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 7 Mar 2019 12:03:01 +0100 Subject: write_default_config: allow specifying target user and directory --- util.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/util.py b/util.py index 333ecc3..70afcef 100644 --- a/util.py +++ b/util.py @@ -3,8 +3,10 @@ import os import yaml -def write_default_config(disk, global_params): - home = '/home/test' +def write_default_config(disk, global_params, user='test', uid=1001, gid=None): + if gid is None: + gid = uid + home = '/home/{}'.format(user) params_file = os.path.join(home, '.kpov_params.yaml') default_params = {} for k in [ @@ -14,13 +16,13 @@ def write_default_config(disk, global_params): if k in global_params: default_params[k] = global_params[k] disk.write(params_file, yaml.dump(default_params)) - disk.chown(1001, 1001, params_file) + disk.chown(uid, gid, params_file) mydir = os.path.dirname(os.path.abspath(__file__)) # write testing script and helper for f in ['test_task.py', 'kpov_util.py']: src = os.path.join(mydir, f) - dst = os.path.join('/home/test', f) + dst = os.path.join(home, f) disk.write(dst, open(src).read()) disk.chmod(0o755, dst) - disk.copy_in(os.path.join(mydir, 'random_data'), '/home/test') + disk.copy_in(os.path.join(mydir, 'random_data'), home) -- cgit v1.2.1