Add support for expanding environment variables.
authorJeppe Johansen <jgj@gomspace.com>
Wed, 8 May 2019 14:56:33 +0000 (16:56 +0200)
committerJeppe Johansen <jgj@gomspace.com>
Wed, 8 May 2019 14:56:33 +0000 (16:56 +0200)
Signed-off-by: Jeppe Johansen <jgj@gomspace.com>
sbysrc/sby_core.py

index a66ea1409ae74e719f7a4b2118aa657ea3213267..54e6c179454dd72513b5397228ed9d6162311104 100644 (file)
@@ -37,6 +37,14 @@ if os.name == "posix":
 signal.signal(signal.SIGINT, force_shutdown)
 signal.signal(signal.SIGTERM, force_shutdown)
 
+def process_filename(filename):
+    if filename.startswith("~/"):
+        filename = os.environ['HOME'] + filename[1:]
+
+    filename = os.path.expandvars(filename)
+
+    return filename
+
 class SbyTask:
     def __init__(self, job, info, deps, cmdline, logfile=None, logstderr=True):
         self.running = False
@@ -290,8 +298,7 @@ class SbyJob:
                 self.error("destination filename must be a relative path without /../: %s" % dstfile)
             dstfile = self.workdir + "/src/" + dstfile
 
-            if srcfile.startswith("~/"):
-                srcfile = os.environ['HOME'] + srcfile[1:]
+            srcfile = process_filename(srcfile)
 
             basedir = os.path.dirname(dstfile)
             if basedir != "" and not os.path.exists(basedir):