1
0
mirror of https://github.com/gryf/fs-uae-wrapper.git synced 2025-12-19 12:28:12 +01:00

Fix for interpolate_variables function

This commit is contained in:
2017-01-08 15:38:59 +01:00
parent 83185011aa
commit 388a8cc835
3 changed files with 15 additions and 15 deletions

View File

@@ -195,7 +195,6 @@ class Base(object):
for num in range(10): for num in range(10):
include_list.append('hard_drive_%d' % num) include_list.append('hard_drive_%d' % num)
conf_abs_dir = os.path.dirname(os.path.abspath(self.conf_file))
changed_options = {} changed_options = {}
for key, val in utils.get_config(self.conf_file).items(): for key, val in utils.get_config(self.conf_file).items():
@@ -212,7 +211,7 @@ class Base(object):
continue continue
if val.startswith('$CONFIG'): 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 changed_options[key] = abspath
continue continue

View File

@@ -145,8 +145,9 @@ def interpolate_variables(string, config_path, base=None):
""" """
if '$CONFIG' in string: if '$CONFIG' in string:
string = string.replace('$CONFIG', conf_path = os.path.dirname(os.path.abspath(config_path))
os.path.dirname(os.path.abspath(config_path))) string = os.path.abspath(string.replace('$CONFIG', conf_path))
if '$HOME' in string: if '$HOME' in string:
string = string.replace('$HOME', os.path.expandvars('$HOME')) string = string.replace('$HOME', os.path.expandvars('$HOME'))

View File

@@ -241,26 +241,26 @@ class TestCmdOptions(TestCase):
itrpl = utils.interpolate_variables itrpl = utils.interpolate_variables
string = 'foo = $CONFIG/../path/to/smth' string = '$CONFIG/../path/to/smth'
self.assertEqual(itrpl(string, '/home/user/Config.fs-uae'), self.assertEqual(itrpl(string, '/home/user/Config.fs-uae'),
'foo = /home/user/../path/to/smth') '/home/path/to/smth')
string = 'bar = $HOME' string = '$HOME'
expandv.return_value = '/home/user' expandv.return_value = '/home/user'
self.assertEqual(itrpl(string, '/home/user/Config.fs-uae'), 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' find_exe.return_value = '/usr/bin/fs-uae'
self.assertEqual(itrpl(string, '/home/user/Config.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' getenv.return_value = '/home/user/Docs'
self.assertEqual(itrpl(string, '/home/user/Config.fs-uae'), 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'), self.assertEqual(itrpl(string, '/home/user/Config.fs-uae'),
'baz = $BASE') '$BASE')
self.assertEqual(itrpl(string, '/home/user/Config.fs-uae', 'base'), self.assertEqual(itrpl(string, '/home/user/Config.fs-uae', 'base'),
'baz = base') 'base')