summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2019-03-07 12:03:01 +0100
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2019-03-07 12:03:01 +0100
commit51d40aa5accc446953df4db8a93243233d29e44a (patch)
tree3dc85fee37d485ac6fac7414dac5934712751d81
parent646369852af3a367c9c97d104c2895ec70d17fca (diff)
write_default_config: allow specifying target user and directory
-rw-r--r--util.py12
1 files 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)