mirror of
https://github.com/gryf/fs-uae-wrapper.git
synced 2025-12-19 12:28:12 +01:00
Introduced new configuration variable $WRAPPER
Calculation of file path may be performed in two different places - first is the original location of the config file, second is on copied one. Adding new option WRAPPER will take the same role as $CONFIG, except it will be only parsed on copied configuration file. An alternative would be to check existence in both places, but I'd like to have it explicit.
This commit is contained in:
17
README.rst
17
README.rst
@@ -98,6 +98,23 @@ If no ``wrapper`` option would be passed either as an config option or
|
||||
command line argument, all command line options will be passed to the fs-uae
|
||||
executable as-is.
|
||||
|
||||
There is also new config variable introduced: ``$WRAPPER`` which have the same
|
||||
role as ``$CONFIG``, but apply for copied config. For instance - in module
|
||||
archive there are filesystem extracted to new location - to access this
|
||||
filesystem relatively to the copied configuration file it is enough to provide
|
||||
a config option:
|
||||
|
||||
.. code:: ini
|
||||
|
||||
[config]
|
||||
wrapper = archive
|
||||
...
|
||||
|
||||
hard_drive_0 = $WRAPPER/my_hardrive
|
||||
|
||||
which means, that we are expecting to have system files on ``my_hardrive`` in
|
||||
directory, where configuration will be copied.
|
||||
|
||||
Modules
|
||||
=======
|
||||
|
||||
|
||||
@@ -45,8 +45,8 @@ class Base(object):
|
||||
if not self._validate_options():
|
||||
return False
|
||||
|
||||
self._normalize_options()
|
||||
self.dir = tempfile.mkdtemp()
|
||||
self._normalize_options()
|
||||
self._set_assets_paths()
|
||||
|
||||
return True
|
||||
@@ -144,7 +144,7 @@ class Base(object):
|
||||
def _get_saves_dir(self):
|
||||
"""
|
||||
Return path to save state directory or None in cases:
|
||||
- there is no save state dir set relative to config file
|
||||
- there is no save state dir set relative to copied config file
|
||||
- save state dir is set globally
|
||||
- save state dir is set relative to the config file
|
||||
- save state dir doesn't exists
|
||||
@@ -153,9 +153,9 @@ class Base(object):
|
||||
if not self.all_options.get('save_states_dir'):
|
||||
return None
|
||||
|
||||
if self.all_options['save_states_dir'].startswith('$CONFIG') and \
|
||||
if self.all_options['save_states_dir'].startswith('$WRAPPER') and \
|
||||
'..' not in self.all_options['save_states_dir']:
|
||||
save = self.all_options['save_states_dir'].replace('$CONFIG/', '')
|
||||
save = self.all_options['save_states_dir'].replace('$WRAPPER/', '')
|
||||
else:
|
||||
return None
|
||||
|
||||
@@ -171,45 +171,49 @@ class Base(object):
|
||||
def _normalize_options(self):
|
||||
"""
|
||||
Search and replace values for options which starts with $CONFIG with
|
||||
absolute path for all options, except:
|
||||
- save_states_dir
|
||||
absolute path for all options.
|
||||
|
||||
Configuration file will be placed in new directory, therefore it is
|
||||
needed to calculate new paths so that emulator can find assets.
|
||||
"""
|
||||
exclude_list = ['save_states_dir']
|
||||
include_list = ['wrapper_archive', 'accelerator_rom', 'base_dir',
|
||||
'cdrom_drive_0', 'cdroms_dir', 'controllers_dir',
|
||||
'cpuboard_flash_ext_file', 'cpuboard_flash_file',
|
||||
'floppies_dir', 'floppy_overlays_dir', 'fmv_rom',
|
||||
'graphics_card_rom', 'hard_drives_dir',
|
||||
'kickstart_file', 'kickstarts_dir', 'logs_dir',
|
||||
'screenshots_output_dir', 'state_dir']
|
||||
options = ['wrapper_archive', 'accelerator_rom', 'base_dir',
|
||||
'cdrom_drive_0', 'cdroms_dir', 'controllers_dir',
|
||||
'cpuboard_flash_ext_file', 'cpuboard_flash_file',
|
||||
'floppies_dir', 'floppy_overlays_dir', 'fmv_rom',
|
||||
'graphics_card_rom', 'hard_drives_dir', 'kickstart_file',
|
||||
'kickstarts_dir', 'logs_dir', 'save_states_dir',
|
||||
'screenshots_output_dir']
|
||||
|
||||
for num in range(20):
|
||||
include_list.append('cdrom_image_%d' % num)
|
||||
include_list.append('floppy_image_%d' % num)
|
||||
options.append('cdrom_image_%d' % num)
|
||||
options.append('floppy_image_%d' % num)
|
||||
|
||||
for num in range(4):
|
||||
include_list.append('floppy_drive_%d' % num)
|
||||
options.append('floppy_drive_%d' % num)
|
||||
|
||||
for num in range(10):
|
||||
include_list.append('hard_drive_%d' % num)
|
||||
options.append('hard_drive_%d' % num)
|
||||
|
||||
changed_options = {}
|
||||
|
||||
for key, val in utils.get_config(self.conf_file).items():
|
||||
if key in exclude_list:
|
||||
continue
|
||||
|
||||
if key not in include_list:
|
||||
if key not in options:
|
||||
continue
|
||||
|
||||
if val.startswith('/'):
|
||||
continue
|
||||
|
||||
if val.startswith('~'):
|
||||
continue
|
||||
|
||||
if val.startswith('$HOME'):
|
||||
continue
|
||||
|
||||
if val.startswith('$WRAPPER'):
|
||||
changed_options[key] = val.replace('$WRAPPER', self.dir)
|
||||
continue
|
||||
|
||||
if val.startswith('$CONFIG'):
|
||||
abspath = utils.interpolate_variables(val, self.conf_file)
|
||||
changed_options[key] = abspath
|
||||
|
||||
2
setup.py
2
setup.py
@@ -7,7 +7,7 @@ from setuptools import setup
|
||||
|
||||
setup(name='fs-uae-wrapper',
|
||||
packages=['fs_uae_wrapper'],
|
||||
version='0.7.1',
|
||||
version='0.8',
|
||||
description='Automate archives and state for fs-uae',
|
||||
author='Roman Dobosz',
|
||||
author_email='gryf73@gmail.com',
|
||||
|
||||
@@ -80,6 +80,18 @@ class TestBase(TestCase):
|
||||
bobj._normalize_options()
|
||||
self.assertDictEqual(bobj.fsuae_options, {})
|
||||
|
||||
get_config.return_value = {'cdroms_dir': '$WRAPPER/path'}
|
||||
bobj.fsuae_options = utils.CmdOption()
|
||||
bobj.dir = self.dirname
|
||||
bobj._normalize_options()
|
||||
self.assertDictEqual(bobj.fsuae_options,
|
||||
{'cdroms_dir': os.path.join(bobj.dir, 'path')})
|
||||
|
||||
get_config.return_value = {'cdroms_dir': '~/path'}
|
||||
bobj.fsuae_options = utils.CmdOption()
|
||||
bobj._normalize_options()
|
||||
self.assertDictEqual(bobj.fsuae_options, {})
|
||||
|
||||
def test_set_assets_paths(self):
|
||||
|
||||
bobj = base.Base('Config.fs-uae', utils.CmdOption(), {})
|
||||
@@ -201,13 +213,13 @@ class TestBase(TestCase):
|
||||
bobj.all_options['save_states_dir'] = '/some/path'
|
||||
self.assertIsNone(bobj._get_saves_dir())
|
||||
|
||||
bobj.all_options['save_states_dir'] = '$CONFIG/../saves'
|
||||
bobj.all_options['save_states_dir'] = '$WRAPPER/../saves'
|
||||
self.assertIsNone(bobj._get_saves_dir())
|
||||
|
||||
bobj.all_options['save_states_dir'] = '/foo/$CONFIG/saves'
|
||||
bobj.all_options['save_states_dir'] = '/foo/$WRAPPER/saves'
|
||||
self.assertIsNone(bobj._get_saves_dir())
|
||||
|
||||
bobj.all_options['save_states_dir'] = '$CONFIG/saves'
|
||||
bobj.all_options['save_states_dir'] = '$WRAPPER/saves'
|
||||
self.assertIsNone(bobj._get_saves_dir())
|
||||
|
||||
path = os.path.join(self.dirname, 'saves')
|
||||
@@ -219,7 +231,7 @@ class TestBase(TestCase):
|
||||
os.mkdir(path)
|
||||
self.assertEqual(bobj._get_saves_dir(), 'saves')
|
||||
|
||||
bobj.all_options['save_states_dir'] = '$CONFIG/saves/'
|
||||
bobj.all_options['save_states_dir'] = '$WRAPPER/saves/'
|
||||
self.assertEqual(bobj._get_saves_dir(), 'saves')
|
||||
|
||||
@mock.patch('fs_uae_wrapper.path.which')
|
||||
|
||||
Reference in New Issue
Block a user