diff --git a/fs_uae_wrapper/base.py b/fs_uae_wrapper/base.py index 74d7b0d..919ecb7 100644 --- a/fs_uae_wrapper/base.py +++ b/fs_uae_wrapper/base.py @@ -195,7 +195,6 @@ class Base(object): for num in range(10): include_list.append('hard_drive_%d' % num) - conf_abs_dir = os.path.dirname(os.path.abspath(self.conf_file)) changed_options = {} for key, val in utils.get_config(self.conf_file).items(): @@ -212,7 +211,7 @@ class Base(object): continue if val.startswith('$CONFIG'): - abspath = os.path.abspath(val.replace('$CONFIG', conf_abs_dir)) + abspath = utils.interpolate_variables(val, self.conf_file) changed_options[key] = abspath continue diff --git a/fs_uae_wrapper/utils.py b/fs_uae_wrapper/utils.py index 812804a..583687f 100644 --- a/fs_uae_wrapper/utils.py +++ b/fs_uae_wrapper/utils.py @@ -145,8 +145,9 @@ def interpolate_variables(string, config_path, base=None): """ if '$CONFIG' in string: - string = string.replace('$CONFIG', - os.path.dirname(os.path.abspath(config_path))) + conf_path = os.path.dirname(os.path.abspath(config_path)) + string = os.path.abspath(string.replace('$CONFIG', conf_path)) + if '$HOME' in string: string = string.replace('$HOME', os.path.expandvars('$HOME')) diff --git a/tests/test_utils.py b/tests/test_utils.py index 054760c..76b8f62 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -241,26 +241,26 @@ class TestCmdOptions(TestCase): itrpl = utils.interpolate_variables - string = 'foo = $CONFIG/../path/to/smth' + string = '$CONFIG/../path/to/smth' self.assertEqual(itrpl(string, '/home/user/Config.fs-uae'), - 'foo = /home/user/../path/to/smth') - string = 'bar = $HOME' + '/home/path/to/smth') + string = '$HOME' expandv.return_value = '/home/user' self.assertEqual(itrpl(string, '/home/user/Config.fs-uae'), - 'bar = /home/user') + '/home/user') - string = 'foo = $APP/$EXE' + string = '$APP/$EXE' find_exe.return_value = '/usr/bin/fs-uae' self.assertEqual(itrpl(string, '/home/user/Config.fs-uae'), - 'foo = /usr/bin/fs-uae//usr/bin/fs-uae') + '/usr/bin/fs-uae//usr/bin/fs-uae') - string = 'docs = $DOCUMENTS' + string = '$DOCUMENTS' getenv.return_value = '/home/user/Docs' self.assertEqual(itrpl(string, '/home/user/Config.fs-uae'), - 'docs = /home/user/Docs') + '/home/user/Docs') - string = 'baz = $BASE' + string = '$BASE' self.assertEqual(itrpl(string, '/home/user/Config.fs-uae'), - 'baz = $BASE') + '$BASE') self.assertEqual(itrpl(string, '/home/user/Config.fs-uae', 'base'), - 'baz = base') + 'base')