mirror of
https://github.com/gryf/fs-uae-wrapper.git
synced 2026-02-03 14:55:53 +01:00
Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 00e3cf9801 | |||
| 388a8cc835 | |||
| 83185011aa | |||
| 152446abbe | |||
| a918e4c9ff | |||
| 7931022777 | |||
| 1a67b355ae | |||
| 6a026ecff1 | |||
| bd0e3ea56a | |||
| 8a6ddda7c8 | |||
| a14871c52f | |||
| 8528d28a42 | |||
| ab4042f880 | |||
| 8892940339 | |||
| 853dca385e | |||
| 334b56bad3 | |||
| 6d84fc4b8a | |||
| c5ce27e637 | |||
| ae6e00ea1c | |||
| f1fb43ca64 |
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
*.pyc
|
||||||
|
*.egg-info
|
||||||
|
.cache
|
||||||
|
.coverage
|
||||||
|
.tox
|
||||||
|
MANIFEST
|
||||||
|
build
|
||||||
|
dist
|
||||||
84
README.rst
84
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
|
command line argument, all command line options will be passed to the fs-uae
|
||||||
executable as-is.
|
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
|
Modules
|
||||||
=======
|
=======
|
||||||
|
|
||||||
@@ -106,6 +123,7 @@ Currently, three wrapper modules are available:
|
|||||||
- plain
|
- plain
|
||||||
- cd32
|
- cd32
|
||||||
- archive
|
- archive
|
||||||
|
- savestate
|
||||||
|
|
||||||
plain
|
plain
|
||||||
-----
|
-----
|
||||||
@@ -135,11 +153,11 @@ Options used:
|
|||||||
``wrapper_archiver`` archiver. If this option is enabled,
|
``wrapper_archiver`` archiver. If this option is enabled,
|
||||||
``wrapper_archiver`` will be required.
|
``wrapper_archiver`` will be required.
|
||||||
|
|
||||||
Let's see some sample config for a game, which is saved as
|
Module ``cd32`` is used for running ``fs-uae`` with compressed CD images. For
|
||||||
``ChaosEngine.fs-uae``:
|
better understanding how it works, let's go through solid example. Here is an
|
||||||
|
fragment of configuration file is saved as ``ChaosEngine.fs-uae``:
|
||||||
|
|
||||||
.. code:: ini
|
.. code:: ini
|
||||||
:number-lines:
|
|
||||||
|
|
||||||
[config]
|
[config]
|
||||||
wrapper = cd32
|
wrapper = cd32
|
||||||
@@ -156,8 +174,9 @@ Let's see some sample config for a game, which is saved as
|
|||||||
|
|
||||||
joystick_port_1_mode = cd32 gamepad
|
joystick_port_1_mode = cd32 gamepad
|
||||||
platform = cd32
|
platform = cd32
|
||||||
|
...
|
||||||
|
|
||||||
Next, the invocation of the wrapper would be as follows:
|
Command line invocation of the wrapper would be as follows:
|
||||||
|
|
||||||
.. code:: shell-session
|
.. code:: shell-session
|
||||||
|
|
||||||
@@ -165,8 +184,7 @@ Next, the invocation of the wrapper would be as follows:
|
|||||||
|
|
||||||
Now, there several thing will happen:
|
Now, there several thing will happen:
|
||||||
|
|
||||||
- Config file will be read, and wrapper module will be find (because we already
|
- Config file will be read, and wrapper module will be found
|
||||||
put it on line 2)
|
|
||||||
- New temporary directory will be created
|
- New temporary directory will be created
|
||||||
- Archive with game assists will be extracted in that directory
|
- Archive with game assists will be extracted in that directory
|
||||||
- Configuration file will be copied into that directory, and renamed to
|
- Configuration file will be copied into that directory, and renamed to
|
||||||
@@ -201,10 +219,16 @@ Options used:
|
|||||||
``wrapper_archiver`` archiver. If this option is enabled,
|
``wrapper_archiver`` archiver. If this option is enabled,
|
||||||
``wrapper_archiver`` will be required.
|
``wrapper_archiver`` will be required.
|
||||||
|
|
||||||
|
This module is quite useful in two use cases. First is a usual work with
|
||||||
|
Workbench, where there is a need to keep changes of filesystem. Second is the
|
||||||
|
opposite - if there is a need to test some software, but not necessary keep it
|
||||||
|
in a Workbench, than it will act as a temporary copy of the system, so that
|
||||||
|
next time fs-uae will be run, there will be no files of tested software
|
||||||
|
cluttering around.
|
||||||
|
|
||||||
Example configuration:
|
Example configuration:
|
||||||
|
|
||||||
.. code:: ini
|
.. code:: ini
|
||||||
:number-lines:
|
|
||||||
|
|
||||||
[config]
|
[config]
|
||||||
wrapper = archive
|
wrapper = archive
|
||||||
@@ -234,12 +258,46 @@ This module will do several steps (similar as with ``cd32`` wrapper):
|
|||||||
- optionally create new archive under the same name as the original one and
|
- optionally create new archive under the same name as the original one and
|
||||||
replace it with original one.
|
replace it with original one.
|
||||||
|
|
||||||
This module is quite useful in two use cases. First is a usual work with
|
savestate
|
||||||
Workbench, where there is a need to keep changes of filesystem. Second is the
|
---------
|
||||||
opposite - if there is a need to test some software, but not necessary keep it
|
|
||||||
in a Workbench, than it will act as a temporary copy of the system, so that
|
Options used:
|
||||||
next time fs-uae will be run, there will be no files of tested software
|
|
||||||
cluttering around.
|
* ``wrapper`` (required) with ``archive`` as an value
|
||||||
|
* ``wrapper_archiver`` (required) archiver to use for storage save state
|
||||||
|
|
||||||
|
This module is primarily used to run emulator with read only media attached
|
||||||
|
(like images of floppies or uncompressed CD-ROMs) and its purpose is to
|
||||||
|
preserve save state which will be created as an archive alongside with original
|
||||||
|
configuration file in selected archive format. Note, that there is required to
|
||||||
|
provide ``wrapper_archiver``, since option ``wrapper_save_state`` is implicitly
|
||||||
|
set to value ``1`` in this module.
|
||||||
|
|
||||||
|
Example configuration:
|
||||||
|
|
||||||
|
.. code:: ini
|
||||||
|
:number-lines:
|
||||||
|
|
||||||
|
[config]
|
||||||
|
wrapper = savestate
|
||||||
|
wrapper_archiver = 7z
|
||||||
|
...
|
||||||
|
|
||||||
|
And execution is as usual:
|
||||||
|
|
||||||
|
.. code:: shell-session
|
||||||
|
|
||||||
|
$ fs-uae-wrapper Sanity-Arte.fs-uae
|
||||||
|
|
||||||
|
The steps would be as follows:
|
||||||
|
|
||||||
|
- create temporary directory
|
||||||
|
- extract save state (if ``wrapper_save_state`` is set to ``1`` and archive
|
||||||
|
with save exists)
|
||||||
|
- copy configuration under name ``Config.fs-uae``
|
||||||
|
- run the fs-uae emulator
|
||||||
|
- optionally create archive with save state (if save state directory place is
|
||||||
|
*not* a global one)
|
||||||
|
|
||||||
License
|
License
|
||||||
=======
|
=======
|
||||||
|
|||||||
@@ -6,38 +6,30 @@ the temporary one.
|
|||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
|
||||||
|
|
||||||
from fs_uae_wrapper import base
|
from fs_uae_wrapper import base
|
||||||
from fs_uae_wrapper import utils
|
from fs_uae_wrapper import utils
|
||||||
|
|
||||||
|
|
||||||
class Archive(base.Base):
|
class Wrapper(base.ArchiveBase):
|
||||||
"""
|
"""
|
||||||
Class for performing extracting archive, copying emulator files, and
|
Class for performing extracting archive, copying emulator files, and
|
||||||
cleaning it back again
|
cleaning it back again
|
||||||
"""
|
"""
|
||||||
def __init__(self, conf_file, fsuae_options, configuration):
|
def __init__(self, conf_file, fsuae_options, configuration):
|
||||||
super(Archive, self).__init__(conf_file, fsuae_options, configuration)
|
super(Wrapper, self).__init__(conf_file, fsuae_options, configuration)
|
||||||
self.archive_type = None
|
self.archive_type = None
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""
|
"""
|
||||||
Main function which accepts configuration file for FS-UAE
|
Main function which accepts configuration file for FS-UAE
|
||||||
It will do as follows:
|
It will do as follows:
|
||||||
- set needed full path for asset files
|
|
||||||
- extract archive file
|
- extract archive file
|
||||||
- copy configuration
|
- copy configuration
|
||||||
- run the emulation
|
- run the emulation
|
||||||
- optionally make archive save state
|
- optionally make archive save state
|
||||||
|
|
||||||
Params:
|
|
||||||
conf_file: a relative path to provided configuration file
|
|
||||||
fsuae_options: is an CmdOption object created out of command line
|
|
||||||
parameters
|
|
||||||
configuration: is config dictionary created out of config file
|
|
||||||
"""
|
"""
|
||||||
if not super(Archive, self).run():
|
if not super(Wrapper, self).run():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not self._extract():
|
if not self._extract():
|
||||||
@@ -48,11 +40,7 @@ class Archive(base.Base):
|
|||||||
if not self._copy_conf():
|
if not self._copy_conf():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
kick_opts = self._kickstart_option()
|
if not self._run_emulator():
|
||||||
if kick_opts:
|
|
||||||
self.fsuae_options.update(kick_opts)
|
|
||||||
|
|
||||||
if not self._run_emulator(self.fsuae_options.list()):
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self._get_saves_dir():
|
if self._get_saves_dir():
|
||||||
@@ -61,17 +49,6 @@ class Archive(base.Base):
|
|||||||
|
|
||||||
return self._make_archive()
|
return self._make_archive()
|
||||||
|
|
||||||
def _validate_options(self):
|
|
||||||
|
|
||||||
validation_result = super(Archive, self)._validate_options()
|
|
||||||
|
|
||||||
if 'wrapper_archive' not in self.all_options:
|
|
||||||
sys.stderr.write("Configuration lacks of required "
|
|
||||||
"`wrapper_archive' option.\n")
|
|
||||||
validation_result = False
|
|
||||||
|
|
||||||
return validation_result
|
|
||||||
|
|
||||||
def _make_archive(self):
|
def _make_archive(self):
|
||||||
"""
|
"""
|
||||||
Produce archive and save it back. Than remove old one.
|
Produce archive and save it back. Than remove old one.
|
||||||
@@ -96,13 +73,3 @@ class Archive(base.Base):
|
|||||||
shutil.move(arch, self.arch_filepath)
|
shutil.move(arch, self.arch_filepath)
|
||||||
os.chdir(curdir)
|
os.chdir(curdir)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def run(config_file, fsuae_options, configuration):
|
|
||||||
"""Run fs-uae with provided config file and options"""
|
|
||||||
|
|
||||||
runner = Archive(config_file, fsuae_options, configuration)
|
|
||||||
try:
|
|
||||||
return runner.run()
|
|
||||||
finally:
|
|
||||||
runner.clean()
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
"""
|
"""
|
||||||
Base class for all wrapper modules
|
Base class for all wrapper modules
|
||||||
"""
|
"""
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import shutil
|
import shutil
|
||||||
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from fs_uae_wrapper import utils
|
from fs_uae_wrapper import utils
|
||||||
@@ -29,7 +30,6 @@ class Base(object):
|
|||||||
fsuae_options)
|
fsuae_options)
|
||||||
self.dir = None
|
self.dir = None
|
||||||
self.save_filename = None
|
self.save_filename = None
|
||||||
self.arch_filepath = None
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""
|
"""
|
||||||
@@ -46,7 +46,7 @@ class Base(object):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
self.dir = tempfile.mkdtemp()
|
self.dir = tempfile.mkdtemp()
|
||||||
|
self._normalize_options()
|
||||||
self._set_assets_paths()
|
self._set_assets_paths()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@@ -57,33 +57,6 @@ class Base(object):
|
|||||||
shutil.rmtree(self.dir)
|
shutil.rmtree(self.dir)
|
||||||
return
|
return
|
||||||
|
|
||||||
def _kickstart_option(self):
|
|
||||||
"""
|
|
||||||
This is kind of hack - since we potentially can have a relative path
|
|
||||||
to kickstart directory, there is a need for getting this option from
|
|
||||||
configuration files (which unfortunately can be spanned all over the
|
|
||||||
different places, see https://fs-uae.net/configuration-files) and
|
|
||||||
check whether or not one of 'kickstarts_dir', 'kickstart_file' or
|
|
||||||
'kickstart_ext_file' options are set. In either case if one of those
|
|
||||||
options are set and are relative, they should be set to absolute path,
|
|
||||||
so that kickstart files can be found by relocated configuration file.
|
|
||||||
"""
|
|
||||||
|
|
||||||
conf = utils.get_config(self.conf_file)
|
|
||||||
|
|
||||||
kick = {}
|
|
||||||
|
|
||||||
for key in ('kickstart_file', 'kickstart_ext_file', 'kickstarts_dir'):
|
|
||||||
val = conf.get(key)
|
|
||||||
if val:
|
|
||||||
if not os.path.isabs(val):
|
|
||||||
val = utils.interpolate_variables(val, self.conf_file)
|
|
||||||
kick[key] = os.path.abspath(val)
|
|
||||||
else:
|
|
||||||
kick[key] = val
|
|
||||||
|
|
||||||
return kick
|
|
||||||
|
|
||||||
def _set_assets_paths(self):
|
def _set_assets_paths(self):
|
||||||
"""
|
"""
|
||||||
Set full paths for archive file (without extension) and for save state
|
Set full paths for archive file (without extension) and for save state
|
||||||
@@ -93,12 +66,6 @@ class Base(object):
|
|||||||
conf_base = os.path.basename(self.conf_file)
|
conf_base = os.path.basename(self.conf_file)
|
||||||
conf_base = os.path.splitext(conf_base)[0]
|
conf_base = os.path.splitext(conf_base)[0]
|
||||||
|
|
||||||
arch = self.all_options.get('wrapper_archive')
|
|
||||||
if arch:
|
|
||||||
if os.path.isabs(arch):
|
|
||||||
self.arch_filepath = arch
|
|
||||||
else:
|
|
||||||
self.arch_filepath = os.path.join(conf_abs_dir, arch)
|
|
||||||
# set optional save_state
|
# set optional save_state
|
||||||
arch_ext = utils.get_arch_ext(self.all_options.get('wrapper_archiver'))
|
arch_ext = utils.get_arch_ext(self.all_options.get('wrapper_archiver'))
|
||||||
if arch_ext:
|
if arch_ext:
|
||||||
@@ -112,21 +79,11 @@ class Base(object):
|
|||||||
os.path.join(self.dir, 'Config.fs-uae'))
|
os.path.join(self.dir, 'Config.fs-uae'))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _extract(self):
|
def _run_emulator(self):
|
||||||
"""Extract archive to temp dir"""
|
"""execute fs-uae"""
|
||||||
|
|
||||||
title = self._get_title()
|
|
||||||
curdir = os.path.abspath('.')
|
curdir = os.path.abspath('.')
|
||||||
os.chdir(self.dir)
|
os.chdir(self.dir)
|
||||||
result = utils.extract_archive(self.arch_filepath, title)
|
utils.run_command(['fs-uae'] + self.fsuae_options.list())
|
||||||
os.chdir(curdir)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def _run_emulator(self, fsuae_options):
|
|
||||||
"""execute fs-uae in provided directory"""
|
|
||||||
curdir = os.path.abspath('.')
|
|
||||||
os.chdir(self.dir)
|
|
||||||
utils.run_command(['fs-uae'] + fsuae_options)
|
|
||||||
os.chdir(curdir)
|
os.chdir(curdir)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -161,7 +118,7 @@ class Base(object):
|
|||||||
curdir = os.path.abspath('.')
|
curdir = os.path.abspath('.')
|
||||||
|
|
||||||
if not utils.create_archive(self.save_filename, '', [save_path]):
|
if not utils.create_archive(self.save_filename, '', [save_path]):
|
||||||
sys.stderr.write('Error: archiving save state failed\n')
|
logging.error('Error: archiving save state failed.')
|
||||||
os.chdir(curdir)
|
os.chdir(curdir)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -187,7 +144,7 @@ class Base(object):
|
|||||||
def _get_saves_dir(self):
|
def _get_saves_dir(self):
|
||||||
"""
|
"""
|
||||||
Return path to save state directory or None in cases:
|
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 globally
|
||||||
- save state dir is set relative to the config file
|
- save state dir is set relative to the config file
|
||||||
- save state dir doesn't exists
|
- save state dir doesn't exists
|
||||||
@@ -196,9 +153,9 @@ class Base(object):
|
|||||||
if not self.all_options.get('save_states_dir'):
|
if not self.all_options.get('save_states_dir'):
|
||||||
return None
|
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']:
|
'..' 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:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -211,24 +168,131 @@ class Base(object):
|
|||||||
|
|
||||||
return save
|
return save
|
||||||
|
|
||||||
|
def _normalize_options(self):
|
||||||
|
"""
|
||||||
|
Search and replace values for options which starts with $CONFIG with
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
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):
|
||||||
|
options.append('cdrom_image_%d' % num)
|
||||||
|
options.append('floppy_image_%d' % num)
|
||||||
|
|
||||||
|
for num in range(4):
|
||||||
|
options.append('floppy_drive_%d' % num)
|
||||||
|
|
||||||
|
for num in range(10):
|
||||||
|
options.append('hard_drive_%d' % num)
|
||||||
|
|
||||||
|
changed_options = {}
|
||||||
|
|
||||||
|
for key, val in utils.get_config(self.conf_file).items():
|
||||||
|
|
||||||
|
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
|
||||||
|
continue
|
||||||
|
|
||||||
|
changed_options[key] = os.path.abspath(val)
|
||||||
|
|
||||||
|
self.fsuae_options.update(changed_options)
|
||||||
|
|
||||||
def _validate_options(self):
|
def _validate_options(self):
|
||||||
"""Validate mandatory options"""
|
"""Validate mandatory options"""
|
||||||
if 'wrapper' not in self.all_options:
|
if 'wrapper' not in self.all_options:
|
||||||
sys.stderr.write("Configuration lacks of required "
|
logging.error("Configuration lacks of required `wrapper' option.")
|
||||||
"`wrapper' option.\n")
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.all_options.get('wrapper_save_state', '0') == '0':
|
if self.all_options.get('wrapper_save_state', '0') == '0':
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if 'wrapper_archiver' not in self.all_options:
|
if 'wrapper_archiver' not in self.all_options:
|
||||||
sys.stderr.write("Configuration lacks of required "
|
logging.error("Configuration lacks of required "
|
||||||
"`wrapper_archiver' option.\n")
|
"`wrapper_archiver' option.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not path.which(self.all_options['wrapper_archiver']):
|
if not path.which(self.all_options['wrapper_archiver']):
|
||||||
sys.stderr.write("Cannot find archiver `%s'." %
|
logging.error("Cannot find archiver `%s'.",
|
||||||
self.all_options['wrapper_archiver'])
|
self.all_options['wrapper_archiver'])
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
class ArchiveBase(Base):
|
||||||
|
"""
|
||||||
|
Base class for archive based wrapper modules
|
||||||
|
"""
|
||||||
|
def __init__(self, conf_file, fsuae_options, configuration):
|
||||||
|
"""
|
||||||
|
Params:
|
||||||
|
conf_file: a relative path to provided configuration file
|
||||||
|
fsuae_options: is an CmdOption object created out of command line
|
||||||
|
parameters
|
||||||
|
configuration: is config dictionary created out of config file
|
||||||
|
"""
|
||||||
|
super(ArchiveBase, self).__init__(conf_file, fsuae_options,
|
||||||
|
configuration)
|
||||||
|
self.arch_filepath = None
|
||||||
|
|
||||||
|
def _set_assets_paths(self):
|
||||||
|
"""
|
||||||
|
Set full paths for archive file (without extension) and for save state
|
||||||
|
archive file
|
||||||
|
"""
|
||||||
|
super(ArchiveBase, self)._set_assets_paths()
|
||||||
|
|
||||||
|
conf_abs_dir = os.path.dirname(os.path.abspath(self.conf_file))
|
||||||
|
arch = self.all_options.get('wrapper_archive')
|
||||||
|
if arch:
|
||||||
|
if os.path.isabs(arch):
|
||||||
|
self.arch_filepath = arch
|
||||||
|
else:
|
||||||
|
self.arch_filepath = os.path.join(conf_abs_dir, arch)
|
||||||
|
|
||||||
|
def _extract(self):
|
||||||
|
"""Extract archive to temp dir"""
|
||||||
|
|
||||||
|
title = self._get_title()
|
||||||
|
curdir = os.path.abspath('.')
|
||||||
|
os.chdir(self.dir)
|
||||||
|
result = utils.extract_archive(self.arch_filepath, title)
|
||||||
|
os.chdir(curdir)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def _validate_options(self):
|
||||||
|
|
||||||
|
validation_result = super(ArchiveBase, self)._validate_options()
|
||||||
|
|
||||||
|
if 'wrapper_archive' not in self.all_options:
|
||||||
|
sys.stderr.write("Configuration lacks of required "
|
||||||
|
"`wrapper_archive' option.\n")
|
||||||
|
validation_result = False
|
||||||
|
|
||||||
|
return validation_result
|
||||||
|
|||||||
@@ -8,12 +8,10 @@ used as a base for save state (it will append '_save.7z' to the archive file
|
|||||||
name.
|
name.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import sys
|
|
||||||
|
|
||||||
from fs_uae_wrapper import base
|
from fs_uae_wrapper import base
|
||||||
|
|
||||||
|
|
||||||
class CD32(base.Base):
|
class Wrapper(base.ArchiveBase):
|
||||||
"""
|
"""
|
||||||
Class for performing extracting archive, copying emulator files, and
|
Class for performing extracting archive, copying emulator files, and
|
||||||
cleaning it back again
|
cleaning it back again
|
||||||
@@ -30,7 +28,7 @@ class CD32(base.Base):
|
|||||||
- run the emulation
|
- run the emulation
|
||||||
- archive save state
|
- archive save state
|
||||||
"""
|
"""
|
||||||
super(CD32, self).run()
|
super(Wrapper, self).run()
|
||||||
if not self._validate_options():
|
if not self._validate_options():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -41,34 +39,10 @@ class CD32(base.Base):
|
|||||||
if not method():
|
if not method():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
kick_opts = self._kickstart_option()
|
if not self._run_emulator():
|
||||||
if kick_opts:
|
|
||||||
self.fsuae_options.update(kick_opts)
|
|
||||||
|
|
||||||
if not self._run_emulator(self.fsuae_options.list()):
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self._get_saves_dir():
|
if self._get_saves_dir():
|
||||||
return self._save_save()
|
return self._save_save()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _validate_options(self):
|
|
||||||
validation_result = super(CD32, self)._validate_options()
|
|
||||||
|
|
||||||
if 'wrapper_archive' not in self.all_options:
|
|
||||||
sys.stderr.write("Configuration lacks of required "
|
|
||||||
"`wrapper_archive' option.\n")
|
|
||||||
validation_result = False
|
|
||||||
|
|
||||||
return validation_result
|
|
||||||
|
|
||||||
|
|
||||||
def run(config_file, fsuae_options, configuration):
|
|
||||||
"""Run fs-uae with provided config file and options"""
|
|
||||||
|
|
||||||
runner = CD32(config_file, fsuae_options, configuration)
|
|
||||||
try:
|
|
||||||
return runner.run()
|
|
||||||
finally:
|
|
||||||
runner.clean()
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ File archive classes
|
|||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
import re
|
import re
|
||||||
|
import logging
|
||||||
|
|
||||||
from fs_uae_wrapper import path
|
from fs_uae_wrapper import path
|
||||||
|
|
||||||
@@ -17,18 +17,20 @@ class Archive(object):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.archiver = path.which(self.ARCH)
|
self.archiver = path.which(self.ARCH)
|
||||||
self._compess = self.archiver
|
self._compress = self.archiver
|
||||||
self._decompess = self.archiver
|
self._decompress = self.archiver
|
||||||
|
|
||||||
def create(self, arch_name, files=None):
|
def create(self, arch_name, files=None):
|
||||||
"""
|
"""
|
||||||
Create archive. Return True on success, False otherwise.
|
Create archive. Return True on success, False otherwise.
|
||||||
"""
|
"""
|
||||||
files = files if files else ['.']
|
files = files if files else ['.']
|
||||||
result = subprocess.call([self._compess] + self.ADD + [arch_name]
|
logging.debug("Calling `%s %s %s %s'.", self._compress,
|
||||||
|
" ".join(self.ADD), arch_name, " ".join(files))
|
||||||
|
result = subprocess.call([self._compress] + self.ADD + [arch_name]
|
||||||
+ files)
|
+ files)
|
||||||
if result != 0:
|
if result != 0:
|
||||||
sys.stderr.write("Unable to create archive `%s'\n" % arch_name)
|
logging.error("Unable to create archive `%s'.", arch_name)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -37,13 +39,15 @@ class Archive(object):
|
|||||||
Extract archive. Return True on success, False otherwise.
|
Extract archive. Return True on success, False otherwise.
|
||||||
"""
|
"""
|
||||||
if not os.path.exists(arch_name):
|
if not os.path.exists(arch_name):
|
||||||
sys.stderr.write("Archive `%s' doesn't exists.\n" % arch_name)
|
logging.error("Archive `%s' doesn't exists.", arch_name)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
result = subprocess.call([self._decompess] + self.EXTRACT +
|
logging.debug("Calling `%s %s %s'.", self._compress,
|
||||||
|
" ".join(self.ADD), arch_name)
|
||||||
|
result = subprocess.call([self._decompress] + self.EXTRACT +
|
||||||
[arch_name])
|
[arch_name])
|
||||||
if result != 0:
|
if result != 0:
|
||||||
sys.stderr.write("Unable to extract archive `%s'\n" % arch_name)
|
logging.error("Unable to extract archive `%s'.", arch_name)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -55,10 +59,12 @@ class TarArchive(Archive):
|
|||||||
|
|
||||||
def create(self, arch_name, files=None):
|
def create(self, arch_name, files=None):
|
||||||
files = files if files else sorted(os.listdir('.'))
|
files = files if files else sorted(os.listdir('.'))
|
||||||
result = subprocess.call([self._compess] + self.ADD + [arch_name] +
|
logging.debug("Calling `%s %s %s %s'.", self._compress,
|
||||||
|
" ".join(self.ADD), arch_name, " ".join(files))
|
||||||
|
result = subprocess.call([self._compress] + self.ADD + [arch_name] +
|
||||||
files)
|
files)
|
||||||
if result != 0:
|
if result != 0:
|
||||||
sys.stderr.write("Unable to create archive `%s'\n" % arch_name)
|
logging.error("Unable to create archive `%s'.", arch_name)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -86,7 +92,7 @@ class ZipArchive(Archive):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(ZipArchive, self).__init__()
|
super(ZipArchive, self).__init__()
|
||||||
if self.archiver == 'zip':
|
if self.archiver == 'zip':
|
||||||
self._decompess = path.which('unzip')
|
self._decompress = path.which('unzip')
|
||||||
ZipArchive.ADD = ['-r']
|
ZipArchive.ADD = ['-r']
|
||||||
ZipArchive.EXTRACT = []
|
ZipArchive.EXTRACT = []
|
||||||
|
|
||||||
@@ -101,8 +107,8 @@ class LzxArchive(Archive):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(self, arch_name, files=None):
|
def create(self, arch_name, files=None):
|
||||||
sys.stderr.write('Cannot create LZX archive. Only extracting is'
|
logging.error('Cannot create LZX archive. Only extracting is'
|
||||||
'supported\n')
|
'supported.')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@@ -112,14 +118,16 @@ class RarArchive(Archive):
|
|||||||
def create(self, arch_name, files=None):
|
def create(self, arch_name, files=None):
|
||||||
files = files if files else sorted(os.listdir('.'))
|
files = files if files else sorted(os.listdir('.'))
|
||||||
if self.archiver == 'unrar':
|
if self.archiver == 'unrar':
|
||||||
sys.stderr.write('Cannot create RAR archive. Only extracting is'
|
logging.error('Cannot create RAR archive. Only extracting is'
|
||||||
'supported by unrar.\n')
|
'supported by unrar.')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
result = subprocess.call([self._compess] + self.ADD + [arch_name] +
|
logging.debug("Calling `%s %s %s %s'.", self._compress,
|
||||||
|
" ".join(self.ADD), arch_name, " ".join(files))
|
||||||
|
result = subprocess.call([self._compress] + self.ADD + [arch_name] +
|
||||||
files)
|
files)
|
||||||
if result != 0:
|
if result != 0:
|
||||||
sys.stderr.write("Unable to create archive `%s'\n" % arch_name)
|
logging.error("Unable to create archive `%s'.", arch_name)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -174,13 +182,13 @@ def get_archiver(arch_name):
|
|||||||
|
|
||||||
archiver = Archivers.get(ext)
|
archiver = Archivers.get(ext)
|
||||||
if not archiver:
|
if not archiver:
|
||||||
sys.stderr.write("Unable find archive type for `%s'\n" % arch_name)
|
logging.error("Unable find archive type for `%s'.", arch_name)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
archobj = archiver()
|
archobj = archiver()
|
||||||
if archobj.archiver is None:
|
if archobj.archiver is None:
|
||||||
sys.stderr.write("Unable find executable for operating on files"
|
logging.error("Unable find executable for operating on files `*%s'.",
|
||||||
" `*%s'\n" % ext)
|
ext)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return archobj
|
return archobj
|
||||||
|
|||||||
@@ -4,24 +4,24 @@
|
|||||||
Simple class for executing fs-uae with specified parameters. This is a
|
Simple class for executing fs-uae with specified parameters. This is a
|
||||||
failsafe class for running fs-uae.
|
failsafe class for running fs-uae.
|
||||||
"""
|
"""
|
||||||
import subprocess
|
from fs_uae_wrapper import base
|
||||||
import sys
|
from fs_uae_wrapper import utils
|
||||||
|
|
||||||
|
|
||||||
def run_plain(conf_file, fs_uae_options):
|
class Wrapper(base.Base):
|
||||||
"""
|
"""Simple class for running fs-uae"""
|
||||||
Run the emulation.
|
|
||||||
conf_file is a path to the configuration,
|
|
||||||
fs_uae_options is an dict-like object which contains commandline options to
|
|
||||||
be passed to fs-uae
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
subprocess.call(['fs-uae'] + [conf_file] + fs_uae_options.list())
|
|
||||||
except subprocess.CalledProcessError:
|
|
||||||
sys.stderr.write('Warning: fs-uae returned non 0 exit code\n')
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
"""
|
||||||
|
Main function which run FS-UAE
|
||||||
|
"""
|
||||||
|
self._run_emulator()
|
||||||
|
|
||||||
def run(config_file, fs_uae_options, _):
|
def _run_emulator(self):
|
||||||
"""Run fs-uae with provided config file and options"""
|
"""execute fs-uae"""
|
||||||
return run_plain(config_file, fs_uae_options)
|
utils.run_command(['fs-uae'] + [self.conf_file] +
|
||||||
|
self.fsuae_options.list())
|
||||||
|
|
||||||
|
def clean(self):
|
||||||
|
"""Do the cleanup. Here - just do nothing"""
|
||||||
|
return
|
||||||
|
|||||||
48
fs_uae_wrapper/savestate.py
Normal file
48
fs_uae_wrapper/savestate.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
"""
|
||||||
|
Wrapper module with preserved save state in archive file.
|
||||||
|
"""
|
||||||
|
from fs_uae_wrapper import base
|
||||||
|
|
||||||
|
|
||||||
|
class Wrapper(base.Base):
|
||||||
|
"""
|
||||||
|
Preserve save state.
|
||||||
|
"""
|
||||||
|
def __init__(self, conf_file, fsuae_options, configuration):
|
||||||
|
"""
|
||||||
|
Params:
|
||||||
|
conf_file: a relative path to provided configuration file
|
||||||
|
fsuae_options: is an CmdOption object created out of command line
|
||||||
|
parameters
|
||||||
|
configuration: is config dictionary created out of config file
|
||||||
|
"""
|
||||||
|
super(Wrapper, self).__init__(conf_file, fsuae_options, configuration)
|
||||||
|
self.arch_filepath = None
|
||||||
|
self.all_options['wrapper_save_state'] = '1'
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
"""
|
||||||
|
Main function which accepts configuration file for FS-UAE
|
||||||
|
It will do as follows:
|
||||||
|
- set needed full path for asset files
|
||||||
|
- copy configuration
|
||||||
|
- optionally extract save state archive
|
||||||
|
- run the emulation
|
||||||
|
- optionally make archive save state
|
||||||
|
"""
|
||||||
|
if not super(Wrapper, self).run():
|
||||||
|
return False
|
||||||
|
|
||||||
|
self._load_save()
|
||||||
|
|
||||||
|
if not self._copy_conf():
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not self._run_emulator():
|
||||||
|
return False
|
||||||
|
|
||||||
|
if self._get_saves_dir():
|
||||||
|
if not self._save_save():
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
@@ -2,9 +2,9 @@
|
|||||||
Misc utilities
|
Misc utilities
|
||||||
"""
|
"""
|
||||||
from distutils import spawn
|
from distutils import spawn
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
|
||||||
try:
|
try:
|
||||||
import configparser
|
import configparser
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@@ -115,10 +115,10 @@ def run_command(cmd):
|
|||||||
if not isinstance(cmd, list):
|
if not isinstance(cmd, list):
|
||||||
cmd = cmd.split()
|
cmd = cmd.split()
|
||||||
|
|
||||||
|
logging.debug("Executing `%s'.", " ".join(cmd))
|
||||||
code = subprocess.call(cmd)
|
code = subprocess.call(cmd)
|
||||||
if code != 0:
|
if code != 0:
|
||||||
sys.stderr.write('Command `{0}` returned non 0 exit '
|
logging.error('Command `%s` returned non 0 exit code.', cmd[0])
|
||||||
'code\n'.format(cmd[0]))
|
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -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'))
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ Wrapper for FS-UAE to perform some actions before and or after running the
|
|||||||
emulator, if appropriate option is enabled.
|
emulator, if appropriate option is enabled.
|
||||||
"""
|
"""
|
||||||
import importlib
|
import importlib
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@@ -11,6 +12,25 @@ from fs_uae_wrapper import utils
|
|||||||
from fs_uae_wrapper import WRAPPER_KEY
|
from fs_uae_wrapper import WRAPPER_KEY
|
||||||
|
|
||||||
|
|
||||||
|
def setup_logger(options):
|
||||||
|
"""Setup logger format and level"""
|
||||||
|
|
||||||
|
level = logging.WARNING
|
||||||
|
|
||||||
|
if options['wrapper_quiet']:
|
||||||
|
level = logging.ERROR
|
||||||
|
if options['wrapper_quiet'] > 1:
|
||||||
|
level = logging.CRITICAL
|
||||||
|
|
||||||
|
if options['wrapper_verbose']:
|
||||||
|
level = logging.INFO
|
||||||
|
if options['wrapper_verbose'] > 1:
|
||||||
|
level = logging.DEBUG
|
||||||
|
|
||||||
|
logging.basicConfig(level=level,
|
||||||
|
format="%(asctime)s %(levelname)s: %(message)s")
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
"""
|
"""
|
||||||
Look out for config file and for config options which would be blindly
|
Look out for config file and for config options which would be blindly
|
||||||
@@ -18,7 +38,16 @@ def parse_args():
|
|||||||
"""
|
"""
|
||||||
fs_conf = None
|
fs_conf = None
|
||||||
options = utils.CmdOption()
|
options = utils.CmdOption()
|
||||||
|
options['wrapper_verbose'] = 0
|
||||||
|
options['wrapper_quiet'] = 0
|
||||||
|
|
||||||
for parameter in sys.argv[1:]:
|
for parameter in sys.argv[1:]:
|
||||||
|
if parameter in ['-v', '-q']:
|
||||||
|
if parameter == '-v':
|
||||||
|
options['wrapper_verbose'] += 1
|
||||||
|
if parameter == '-q':
|
||||||
|
options['wrapper_quiet'] += 1
|
||||||
|
continue
|
||||||
try:
|
try:
|
||||||
options.add(parameter)
|
options.add(parameter)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@@ -33,7 +62,7 @@ def parse_args():
|
|||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
"""Print help"""
|
"""Print help"""
|
||||||
sys.stdout.write("Usage: %s [conf-file] [fs-uae-option...]\n\n"
|
sys.stdout.write("Usage: %s [conf-file] [-v] [-q] [fs-uae-option...]\n\n"
|
||||||
% sys.argv[0])
|
% sys.argv[0])
|
||||||
sys.stdout.write("Config file is not required, if `Config.fs-uae' "
|
sys.stdout.write("Config file is not required, if `Config.fs-uae' "
|
||||||
"exists in the current\ndirectory, although it might "
|
"exists in the current\ndirectory, although it might "
|
||||||
@@ -46,24 +75,27 @@ def usage():
|
|||||||
|
|
||||||
def run():
|
def run():
|
||||||
"""run wrapper module"""
|
"""run wrapper module"""
|
||||||
config_file, cmd_options = parse_args()
|
config_file, fsuae_options = parse_args()
|
||||||
|
setup_logger(fsuae_options)
|
||||||
|
del fsuae_options['wrapper_verbose']
|
||||||
|
del fsuae_options['wrapper_quiet']
|
||||||
|
|
||||||
if 'help' in cmd_options:
|
if 'help' in fsuae_options:
|
||||||
usage()
|
usage()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if not config_file:
|
if not config_file:
|
||||||
sys.stderr.write('Error: Configuration file not found\nSee --help'
|
logging.error('Error: Configuration file not found. See --help'
|
||||||
' for usage\n')
|
' for usage')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
configuration = utils.get_config_options(config_file)
|
configuration = utils.get_config_options(config_file)
|
||||||
|
|
||||||
if configuration is None:
|
if configuration is None:
|
||||||
sys.stderr.write('Error: Configuration file have syntax issues\n')
|
logging.error('Error: Configuration file have syntax issues')
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
wrapper_module = cmd_options.get(WRAPPER_KEY)
|
wrapper_module = fsuae_options.get(WRAPPER_KEY)
|
||||||
if not wrapper_module:
|
if not wrapper_module:
|
||||||
wrapper_module = configuration.get(WRAPPER_KEY)
|
wrapper_module = configuration.get(WRAPPER_KEY)
|
||||||
|
|
||||||
@@ -74,11 +106,18 @@ def run():
|
|||||||
wrapper = importlib.import_module('fs_uae_wrapper.' +
|
wrapper = importlib.import_module('fs_uae_wrapper.' +
|
||||||
wrapper_module)
|
wrapper_module)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
sys.stderr.write("Error: provided wrapper module: `%s' doesn't "
|
logging.error("Error: provided wrapper module: `%s' doesn't "
|
||||||
"exists.\n" % wrapper_module)
|
"exists.", wrapper_module)
|
||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
|
|
||||||
if not wrapper.run(config_file, cmd_options, configuration):
|
runner = wrapper.Wrapper(config_file, fsuae_options, configuration)
|
||||||
|
|
||||||
|
try:
|
||||||
|
exit_code = runner.run()
|
||||||
|
finally:
|
||||||
|
runner.clean()
|
||||||
|
|
||||||
|
if not exit_code:
|
||||||
sys.exit(4)
|
sys.exit(4)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
4
setup.py
4
setup.py
@@ -2,12 +2,12 @@
|
|||||||
"""
|
"""
|
||||||
Setup for the fs-uae-wrapper
|
Setup for the fs-uae-wrapper
|
||||||
"""
|
"""
|
||||||
from distutils.core import setup
|
from setuptools import setup
|
||||||
|
|
||||||
|
|
||||||
setup(name='fs-uae-wrapper',
|
setup(name='fs-uae-wrapper',
|
||||||
packages=['fs_uae_wrapper'],
|
packages=['fs_uae_wrapper'],
|
||||||
version='0.6',
|
version='0.8',
|
||||||
description='Automate archives and state for fs-uae',
|
description='Automate archives and state for fs-uae',
|
||||||
author='Roman Dobosz',
|
author='Roman Dobosz',
|
||||||
author_email='gryf73@gmail.com',
|
author_email='gryf73@gmail.com',
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class TestArchive(TestCase):
|
|||||||
def test_validate_options(self, which):
|
def test_validate_options(self, which):
|
||||||
which.return_value = 'unrar'
|
which.return_value = 'unrar'
|
||||||
|
|
||||||
arch = archive.Archive('Config.fs-uae', utils.CmdOption(), {})
|
arch = archive.Wrapper('Config.fs-uae', utils.CmdOption(), {})
|
||||||
self.assertFalse(arch._validate_options())
|
self.assertFalse(arch._validate_options())
|
||||||
arch.all_options = {'wrapper': 'archive'}
|
arch.all_options = {'wrapper': 'archive'}
|
||||||
|
|
||||||
@@ -42,29 +42,26 @@ class TestArchive(TestCase):
|
|||||||
|
|
||||||
@mock.patch('tempfile.mkdtemp')
|
@mock.patch('tempfile.mkdtemp')
|
||||||
@mock.patch('fs_uae_wrapper.path.which')
|
@mock.patch('fs_uae_wrapper.path.which')
|
||||||
@mock.patch('fs_uae_wrapper.archive.Archive._make_archive')
|
@mock.patch('fs_uae_wrapper.archive.Wrapper._make_archive')
|
||||||
@mock.patch('fs_uae_wrapper.base.Base._save_save')
|
@mock.patch('fs_uae_wrapper.base.ArchiveBase._save_save')
|
||||||
@mock.patch('fs_uae_wrapper.base.Base._get_saves_dir')
|
@mock.patch('fs_uae_wrapper.base.ArchiveBase._get_saves_dir')
|
||||||
@mock.patch('fs_uae_wrapper.base.Base._run_emulator')
|
@mock.patch('fs_uae_wrapper.base.ArchiveBase._run_emulator')
|
||||||
@mock.patch('fs_uae_wrapper.base.Base._kickstart_option')
|
@mock.patch('fs_uae_wrapper.base.ArchiveBase._copy_conf')
|
||||||
@mock.patch('fs_uae_wrapper.base.Base._copy_conf')
|
@mock.patch('fs_uae_wrapper.base.ArchiveBase._load_save')
|
||||||
@mock.patch('fs_uae_wrapper.base.Base._load_save')
|
@mock.patch('fs_uae_wrapper.base.ArchiveBase._extract')
|
||||||
@mock.patch('fs_uae_wrapper.base.Base._extract')
|
def test_run(self, extract, load_save, copy_conf, run_emulator,
|
||||||
def test_run(self, extract, load_save, copy_conf, kick_option,
|
get_save_dir, save_state, make_arch, which, mkdtemp):
|
||||||
run_emulator, get_save_dir, save_state, make_arch, which,
|
|
||||||
mkdtemp):
|
|
||||||
|
|
||||||
extract.return_value = False
|
extract.return_value = False
|
||||||
load_save.return_value = False
|
load_save.return_value = False
|
||||||
copy_conf.return_value = False
|
copy_conf.return_value = False
|
||||||
kick_option.return_value = False
|
|
||||||
run_emulator.return_value = False
|
run_emulator.return_value = False
|
||||||
get_save_dir.return_value = False
|
get_save_dir.return_value = False
|
||||||
save_state.return_value = False
|
save_state.return_value = False
|
||||||
make_arch.return_value = False
|
make_arch.return_value = False
|
||||||
which.return_value = 'rar'
|
which.return_value = 'rar'
|
||||||
|
|
||||||
arch = archive.Archive('Config.fs-uae', utils.CmdOption(), {})
|
arch = archive.Wrapper('Config.fs-uae', utils.CmdOption(), {})
|
||||||
self.assertFalse(arch.run())
|
self.assertFalse(arch.run())
|
||||||
|
|
||||||
arch.all_options = {'wrapper': 'archive',
|
arch.all_options = {'wrapper': 'archive',
|
||||||
@@ -82,10 +79,6 @@ class TestArchive(TestCase):
|
|||||||
copy_conf.return_value = True
|
copy_conf.return_value = True
|
||||||
self.assertFalse(arch.run())
|
self.assertFalse(arch.run())
|
||||||
|
|
||||||
kick_option.return_value = {'foo': 'bar'}
|
|
||||||
self.assertFalse(arch.run())
|
|
||||||
self.assertDictEqual(arch.fsuae_options, {'foo': 'bar'})
|
|
||||||
|
|
||||||
run_emulator.return_value = True
|
run_emulator.return_value = True
|
||||||
self.assertFalse(arch.run())
|
self.assertFalse(arch.run())
|
||||||
|
|
||||||
@@ -102,15 +95,15 @@ class TestArchive(TestCase):
|
|||||||
@mock.patch('os.unlink')
|
@mock.patch('os.unlink')
|
||||||
@mock.patch('shutil.rmtree')
|
@mock.patch('shutil.rmtree')
|
||||||
@mock.patch('fs_uae_wrapper.utils.create_archive')
|
@mock.patch('fs_uae_wrapper.utils.create_archive')
|
||||||
@mock.patch('fs_uae_wrapper.base.Base._get_title')
|
@mock.patch('fs_uae_wrapper.base.ArchiveBase._get_title')
|
||||||
@mock.patch('fs_uae_wrapper.base.Base._get_saves_dir')
|
@mock.patch('fs_uae_wrapper.base.ArchiveBase._get_saves_dir')
|
||||||
def test_make_archive(self, sdir, title, carch, rmt, unlink, rename):
|
def test_make_archive(self, sdir, title, carch, rmt, unlink, rename):
|
||||||
|
|
||||||
sdir.return_value = None
|
sdir.return_value = None
|
||||||
title.return_value = ''
|
title.return_value = ''
|
||||||
carch.return_value = False
|
carch.return_value = False
|
||||||
|
|
||||||
arch = archive.Archive('Config.fs-uae', utils.CmdOption(), {})
|
arch = archive.Wrapper('Config.fs-uae', utils.CmdOption(), {})
|
||||||
arch.dir = self.dirname
|
arch.dir = self.dirname
|
||||||
arch.arch_filepath = os.path.join(self.dirname, 'foo.tgz')
|
arch.arch_filepath = os.path.join(self.dirname, 'foo.tgz')
|
||||||
arch.all_options = {}
|
arch.all_options = {}
|
||||||
|
|||||||
@@ -48,27 +48,49 @@ class TestBase(TestCase):
|
|||||||
self.assertFalse(os.path.exists(self.dirname))
|
self.assertFalse(os.path.exists(self.dirname))
|
||||||
|
|
||||||
@mock.patch('fs_uae_wrapper.utils.get_config')
|
@mock.patch('fs_uae_wrapper.utils.get_config')
|
||||||
def test_kickstart_option(self, get_config):
|
def test_normalize_options(self, get_config):
|
||||||
|
|
||||||
bobj = base.Base('Config.fs-uae', utils.CmdOption(), {})
|
bobj = base.Base('Config.fs-uae', utils.CmdOption(), {})
|
||||||
get_config.return_value = {'foo': 'bar'}
|
|
||||||
self.assertDictEqual(bobj._kickstart_option(), {})
|
|
||||||
|
|
||||||
get_config.return_value = {'kickstarts_dir': '/some/path'}
|
get_config.return_value = {'kickstarts_dir': '/some/path'}
|
||||||
self.assertDictEqual(bobj._kickstart_option(),
|
bobj._normalize_options()
|
||||||
{'kickstarts_dir': '/some/path'})
|
self.assertDictEqual(bobj.fsuae_options, {})
|
||||||
|
|
||||||
os.chdir(self.dirname)
|
os.chdir(self.dirname)
|
||||||
get_config.return_value = {'kickstarts_dir': '../some/path'}
|
get_config.return_value = {'fmv_rom': 'bar'}
|
||||||
|
bobj._normalize_options()
|
||||||
|
self.assertDictEqual(bobj.fsuae_options,
|
||||||
|
{'fmv_rom': os.path.join(self.dirname, 'bar')})
|
||||||
|
|
||||||
|
get_config.return_value = {'floppies_dir': '../some/path'}
|
||||||
|
bobj.fsuae_options = utils.CmdOption()
|
||||||
result = os.path.abspath(os.path.join(self.dirname, '../some/path'))
|
result = os.path.abspath(os.path.join(self.dirname, '../some/path'))
|
||||||
self.assertDictEqual(bobj._kickstart_option(),
|
bobj._normalize_options()
|
||||||
{'kickstarts_dir': result})
|
self.assertDictEqual(bobj.fsuae_options, {'floppies_dir': result})
|
||||||
|
|
||||||
bobj.conf_file = os.path.join(self.dirname, 'Config.fs-uae')
|
bobj.conf_file = os.path.join(self.dirname, 'Config.fs-uae')
|
||||||
get_config.return_value = {'kickstarts_dir': '$CONFIG/../path'}
|
get_config.return_value = {'cdroms_dir': '$CONFIG/../path'}
|
||||||
|
bobj.fsuae_options = utils.CmdOption()
|
||||||
result = os.path.abspath(os.path.join(self.dirname, '../path'))
|
result = os.path.abspath(os.path.join(self.dirname, '../path'))
|
||||||
self.assertDictEqual(bobj._kickstart_option(),
|
bobj._normalize_options()
|
||||||
{'kickstarts_dir': result})
|
self.assertDictEqual(bobj.fsuae_options, {'cdroms_dir': result})
|
||||||
|
|
||||||
|
get_config.return_value = {'cdroms_dir': '$HOME/path'}
|
||||||
|
bobj.fsuae_options = utils.CmdOption()
|
||||||
|
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):
|
def test_set_assets_paths(self):
|
||||||
|
|
||||||
@@ -99,49 +121,28 @@ class TestBase(TestCase):
|
|||||||
self.assertTrue(os.path.exists(os.path.join(self.dirname,
|
self.assertTrue(os.path.exists(os.path.join(self.dirname,
|
||||||
'Config.fs-uae')))
|
'Config.fs-uae')))
|
||||||
|
|
||||||
@mock.patch('fs_uae_wrapper.utils.extract_archive')
|
|
||||||
def test_extract(self, utils_extract):
|
|
||||||
|
|
||||||
bobj = base.Base('Config.fs-uae', utils.CmdOption(), {})
|
|
||||||
bobj.arch_filepath = self.fname
|
|
||||||
bobj.dir = self.dirname
|
|
||||||
|
|
||||||
utils_extract.return_value = False
|
|
||||||
|
|
||||||
# message for the gui is taken from title in fs-uae conf or, if there
|
|
||||||
# is no such entry, use archive name, which is mandatory to provide
|
|
||||||
bobj.all_options = {'title': 'foo_game', 'wrapper_gui_msg': '1'}
|
|
||||||
self.assertFalse(bobj._extract())
|
|
||||||
utils_extract.assert_called_once_with(self.fname, 'foo_game')
|
|
||||||
|
|
||||||
utils_extract.reset_mock()
|
|
||||||
bobj.all_options = {'wrapper_archive': 'arch.tar',
|
|
||||||
'wrapper_gui_msg': '1'}
|
|
||||||
self.assertFalse(bobj._extract())
|
|
||||||
utils_extract.assert_called_once_with(self.fname, 'arch.tar')
|
|
||||||
|
|
||||||
# lets pretend, the extracting has failed
|
|
||||||
utils_extract.reset_mock()
|
|
||||||
bobj.all_options = {'wrapper_gui_msg': '0'}
|
|
||||||
utils_extract.return_value = False
|
|
||||||
self.assertFalse(bobj._extract())
|
|
||||||
utils_extract.assert_called_once_with(self.fname, '')
|
|
||||||
|
|
||||||
@mock.patch('fs_uae_wrapper.utils.run_command')
|
@mock.patch('fs_uae_wrapper.utils.run_command')
|
||||||
def test_run_emulator(self, run):
|
def test_run_emulator(self, run):
|
||||||
|
|
||||||
bobj = base.Base('Config.fs-uae', utils.CmdOption(), {})
|
bobj = base.Base('Config.fs-uae', utils.CmdOption(), {})
|
||||||
bobj.dir = self.dirname
|
bobj.dir = self.dirname
|
||||||
|
|
||||||
self.assertTrue(bobj._run_emulator([]))
|
self.assertTrue(bobj._run_emulator())
|
||||||
run.assert_called_once_with(['fs-uae'])
|
run.assert_called_once_with(['fs-uae'])
|
||||||
|
|
||||||
# Errors from emulator are not fatal to wrappers
|
# Errors from emulator are not fatal to wrappers
|
||||||
run.reset_mock()
|
run.reset_mock()
|
||||||
run.return_value = False
|
run.return_value = False
|
||||||
self.assertTrue(bobj._run_emulator([]))
|
self.assertTrue(bobj._run_emulator())
|
||||||
run.assert_called_once_with(['fs-uae'])
|
run.assert_called_once_with(['fs-uae'])
|
||||||
|
|
||||||
|
# pass the options
|
||||||
|
bobj.fsuae_options = utils.CmdOption({'foo': '1'})
|
||||||
|
run.reset_mock()
|
||||||
|
run.return_value = False
|
||||||
|
self.assertTrue(bobj._run_emulator())
|
||||||
|
run.assert_called_once_with(['fs-uae', '--foo'])
|
||||||
|
|
||||||
@mock.patch('fs_uae_wrapper.base.Base._get_saves_dir')
|
@mock.patch('fs_uae_wrapper.base.Base._get_saves_dir')
|
||||||
@mock.patch('fs_uae_wrapper.utils.create_archive')
|
@mock.patch('fs_uae_wrapper.utils.create_archive')
|
||||||
def test_save_save(self, carch, saves_dir):
|
def test_save_save(self, carch, saves_dir):
|
||||||
@@ -212,13 +213,13 @@ class TestBase(TestCase):
|
|||||||
bobj.all_options['save_states_dir'] = '/some/path'
|
bobj.all_options['save_states_dir'] = '/some/path'
|
||||||
self.assertIsNone(bobj._get_saves_dir())
|
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())
|
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())
|
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())
|
self.assertIsNone(bobj._get_saves_dir())
|
||||||
|
|
||||||
path = os.path.join(self.dirname, 'saves')
|
path = os.path.join(self.dirname, 'saves')
|
||||||
@@ -230,7 +231,7 @@ class TestBase(TestCase):
|
|||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
self.assertEqual(bobj._get_saves_dir(), 'saves')
|
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')
|
self.assertEqual(bobj._get_saves_dir(), 'saves')
|
||||||
|
|
||||||
@mock.patch('fs_uae_wrapper.path.which')
|
@mock.patch('fs_uae_wrapper.path.which')
|
||||||
@@ -247,12 +248,15 @@ class TestBase(TestCase):
|
|||||||
self.assertTrue(bobj._validate_options())
|
self.assertTrue(bobj._validate_options())
|
||||||
|
|
||||||
bobj.all_options = {'wrapper': 'dummy',
|
bobj.all_options = {'wrapper': 'dummy',
|
||||||
'wrapper_archiver': 'myarchiver'}
|
'wrapper_save_state': '0'}
|
||||||
self.assertTrue(bobj._validate_options())
|
self.assertTrue(bobj._validate_options())
|
||||||
|
|
||||||
bobj.all_options = {'wrapper': 'dummy',
|
bobj.all_options = {'wrapper': 'dummy',
|
||||||
'wrapper_save_state': '1',
|
'wrapper_archiver': 'rar'}
|
||||||
'wrapper_archiver': 'myarchiver'}
|
self.assertTrue(bobj._validate_options())
|
||||||
|
|
||||||
|
bobj.all_options = {'wrapper': 'dummy',
|
||||||
|
'wrapper_save_state': '1'}
|
||||||
self.assertFalse(bobj._validate_options())
|
self.assertFalse(bobj._validate_options())
|
||||||
|
|
||||||
which.return_value = '7z'
|
which.return_value = '7z'
|
||||||
@@ -265,6 +269,12 @@ class TestBase(TestCase):
|
|||||||
'wrapper_archiver': '7z'}
|
'wrapper_archiver': '7z'}
|
||||||
self.assertTrue(bobj._validate_options())
|
self.assertTrue(bobj._validate_options())
|
||||||
|
|
||||||
|
which.return_value = None
|
||||||
|
bobj.all_options = {'wrapper': 'dummy',
|
||||||
|
'wrapper_save_state': '1',
|
||||||
|
'wrapper_archiver': '7z'}
|
||||||
|
self.assertFalse(bobj._validate_options())
|
||||||
|
|
||||||
@mock.patch('fs_uae_wrapper.path.which')
|
@mock.patch('fs_uae_wrapper.path.which')
|
||||||
def test_run_clean(self, which):
|
def test_run_clean(self, which):
|
||||||
|
|
||||||
@@ -276,9 +286,96 @@ class TestBase(TestCase):
|
|||||||
self.assertFalse(bobj.run())
|
self.assertFalse(bobj.run())
|
||||||
|
|
||||||
bobj.all_options = {'wrapper': 'dummy',
|
bobj.all_options = {'wrapper': 'dummy',
|
||||||
'wrapper_archiver': 'rar'}
|
'wrapper_archiver': 'rar',
|
||||||
|
'wrapper_archive': 'foo.7z'}
|
||||||
try:
|
try:
|
||||||
self.assertTrue(bobj.run())
|
self.assertTrue(bobj.run())
|
||||||
self.assertTrue(os.path.exists(bobj.dir))
|
self.assertTrue(os.path.exists(bobj.dir))
|
||||||
finally:
|
finally:
|
||||||
bobj.clean()
|
bobj.clean()
|
||||||
|
|
||||||
|
|
||||||
|
class TestArchiveBase(TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
fd, self.fname = mkstemp()
|
||||||
|
self.dirname = mkdtemp()
|
||||||
|
self.confdir = mkdtemp()
|
||||||
|
os.close(fd)
|
||||||
|
self._argv = sys.argv[:]
|
||||||
|
sys.argv = ['fs-uae-wrapper']
|
||||||
|
self.curdir = os.path.abspath(os.curdir)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
os.chdir(self.curdir)
|
||||||
|
try:
|
||||||
|
shutil.rmtree(self.dirname)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
shutil.rmtree(self.confdir)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
os.unlink(self.fname)
|
||||||
|
sys.argv = self._argv[:]
|
||||||
|
|
||||||
|
def test_set_assets_paths(self):
|
||||||
|
|
||||||
|
bobj = base.ArchiveBase('Config.fs-uae', utils.CmdOption(), {})
|
||||||
|
os.chdir(self.dirname)
|
||||||
|
bobj.conf_file = 'Config.fs-uae'
|
||||||
|
bobj.all_options = {'wrapper_archive': 'foo.7z',
|
||||||
|
'wrapper_archiver': '7z'}
|
||||||
|
|
||||||
|
bobj._set_assets_paths()
|
||||||
|
full_path = os.path.join(self.dirname, 'Config_save.7z')
|
||||||
|
self.assertEqual(bobj.save_filename, full_path)
|
||||||
|
|
||||||
|
bobj.all_options = {'wrapper_archive': '/home/user/foo.7z',
|
||||||
|
'wrapper_archiver': '7z'}
|
||||||
|
|
||||||
|
bobj._set_assets_paths()
|
||||||
|
full_path = os.path.join(self.dirname, 'Config_save.7z')
|
||||||
|
self.assertEqual(bobj.save_filename, full_path)
|
||||||
|
|
||||||
|
@mock.patch('fs_uae_wrapper.utils.extract_archive')
|
||||||
|
def test_extract(self, utils_extract):
|
||||||
|
|
||||||
|
bobj = base.ArchiveBase('Config.fs-uae', utils.CmdOption(), {})
|
||||||
|
bobj.arch_filepath = self.fname
|
||||||
|
bobj.dir = self.dirname
|
||||||
|
|
||||||
|
utils_extract.return_value = False
|
||||||
|
|
||||||
|
# message for the gui is taken from title in fs-uae conf or, if there
|
||||||
|
# is no such entry, use archive name, which is mandatory to provide
|
||||||
|
bobj.all_options = {'title': 'foo_game', 'wrapper_gui_msg': '1'}
|
||||||
|
self.assertFalse(bobj._extract())
|
||||||
|
utils_extract.assert_called_once_with(self.fname, 'foo_game')
|
||||||
|
|
||||||
|
utils_extract.reset_mock()
|
||||||
|
bobj.all_options = {'wrapper_archive': 'arch.tar',
|
||||||
|
'wrapper_gui_msg': '1'}
|
||||||
|
self.assertFalse(bobj._extract())
|
||||||
|
utils_extract.assert_called_once_with(self.fname, 'arch.tar')
|
||||||
|
|
||||||
|
# lets pretend, the extracting has failed
|
||||||
|
utils_extract.reset_mock()
|
||||||
|
bobj.all_options = {'wrapper_gui_msg': '0'}
|
||||||
|
utils_extract.return_value = False
|
||||||
|
self.assertFalse(bobj._extract())
|
||||||
|
utils_extract.assert_called_once_with(self.fname, '')
|
||||||
|
|
||||||
|
def test_validate_options(self):
|
||||||
|
|
||||||
|
bobj = base.ArchiveBase('Config.fs-uae', utils.CmdOption(), {})
|
||||||
|
bobj.all_options = {}
|
||||||
|
|
||||||
|
self.assertFalse(bobj._validate_options())
|
||||||
|
|
||||||
|
bobj.all_options = {'wrapper': 'dummy'}
|
||||||
|
self.assertFalse(bobj._validate_options())
|
||||||
|
|
||||||
|
bobj.all_options = {'wrapper': 'dummy',
|
||||||
|
'wrapper_archive': 'myarchive.7z'}
|
||||||
|
self.assertTrue(bobj._validate_options())
|
||||||
|
|||||||
@@ -11,42 +11,26 @@ from fs_uae_wrapper import utils
|
|||||||
|
|
||||||
class TestCD32(TestCase):
|
class TestCD32(TestCase):
|
||||||
|
|
||||||
@mock.patch('fs_uae_wrapper.path.which')
|
|
||||||
def test_validate_options(self, which):
|
|
||||||
|
|
||||||
which.return_value = 'rar'
|
|
||||||
|
|
||||||
acd32 = cd32.CD32('Config.fs-uae', utils.CmdOption(), {})
|
|
||||||
self.assertFalse(acd32._validate_options())
|
|
||||||
|
|
||||||
acd32.all_options['wrapper'] = 'cd32'
|
|
||||||
self.assertFalse(acd32._validate_options())
|
|
||||||
|
|
||||||
acd32.all_options['wrapper_archive'] = 'fake.tgz'
|
|
||||||
self.assertTrue(acd32._validate_options())
|
|
||||||
|
|
||||||
@mock.patch('tempfile.mkdtemp')
|
@mock.patch('tempfile.mkdtemp')
|
||||||
@mock.patch('fs_uae_wrapper.path.which')
|
@mock.patch('fs_uae_wrapper.path.which')
|
||||||
@mock.patch('fs_uae_wrapper.base.Base._save_save')
|
@mock.patch('fs_uae_wrapper.base.ArchiveBase._save_save')
|
||||||
@mock.patch('fs_uae_wrapper.base.Base._get_saves_dir')
|
@mock.patch('fs_uae_wrapper.base.ArchiveBase._get_saves_dir')
|
||||||
@mock.patch('fs_uae_wrapper.base.Base._run_emulator')
|
@mock.patch('fs_uae_wrapper.base.ArchiveBase._run_emulator')
|
||||||
@mock.patch('fs_uae_wrapper.base.Base._kickstart_option')
|
@mock.patch('fs_uae_wrapper.base.ArchiveBase._copy_conf')
|
||||||
@mock.patch('fs_uae_wrapper.base.Base._copy_conf')
|
@mock.patch('fs_uae_wrapper.base.ArchiveBase._load_save')
|
||||||
@mock.patch('fs_uae_wrapper.base.Base._load_save')
|
@mock.patch('fs_uae_wrapper.base.ArchiveBase._extract')
|
||||||
@mock.patch('fs_uae_wrapper.base.Base._extract')
|
def test_run(self, extract, load_save, copy_conf, run_emulator,
|
||||||
def test_run(self, extract, load_save, copy_conf, kick_option,
|
get_save_dir, save_state, which, mkdtemp):
|
||||||
run_emulator, get_save_dir, save_state, which, mkdtemp):
|
|
||||||
|
|
||||||
extract.return_value = False
|
extract.return_value = False
|
||||||
copy_conf.return_value = False
|
copy_conf.return_value = False
|
||||||
load_save.return_value = False
|
load_save.return_value = False
|
||||||
kick_option.return_value = {}
|
|
||||||
run_emulator.return_value = False
|
run_emulator.return_value = False
|
||||||
get_save_dir.return_value = False
|
get_save_dir.return_value = False
|
||||||
save_state.return_value = False
|
save_state.return_value = False
|
||||||
which.return_value = 'unrar'
|
which.return_value = 'unrar'
|
||||||
|
|
||||||
acd32 = cd32.CD32('Config.fs-uae', utils.CmdOption(), {})
|
acd32 = cd32.Wrapper('Config.fs-uae', utils.CmdOption(), {})
|
||||||
self.assertFalse(acd32.run())
|
self.assertFalse(acd32.run())
|
||||||
|
|
||||||
acd32.all_options = {'wrapper': 'cd32',
|
acd32.all_options = {'wrapper': 'cd32',
|
||||||
@@ -64,10 +48,6 @@ class TestCD32(TestCase):
|
|||||||
load_save.return_value = True
|
load_save.return_value = True
|
||||||
self.assertFalse(acd32.run())
|
self.assertFalse(acd32.run())
|
||||||
|
|
||||||
kick_option.return_value = {'foo': 'bar'}
|
|
||||||
self.assertFalse(acd32.run())
|
|
||||||
self.assertDictEqual(acd32.fsuae_options, {'foo': 'bar'})
|
|
||||||
|
|
||||||
run_emulator.return_value = True
|
run_emulator.return_value = True
|
||||||
self.assertTrue(acd32.run())
|
self.assertTrue(acd32.run())
|
||||||
|
|
||||||
|
|||||||
@@ -54,9 +54,18 @@ class TestArchive(TestCase):
|
|||||||
call.assert_called_once_with(['false', 'a', 'foo', '.'])
|
call.assert_called_once_with(['false', 'a', 'foo', '.'])
|
||||||
|
|
||||||
call.reset_mock()
|
call.reset_mock()
|
||||||
call.return_value = 1
|
self.assertFalse(arch.extract('foo'))
|
||||||
with open('foo', 'w') as fobj:
|
with open('foo', 'w') as fobj:
|
||||||
fobj.write('\n')
|
fobj.write('\n')
|
||||||
|
self.assertTrue(arch.extract('foo'))
|
||||||
|
|
||||||
|
call.return_value = 1
|
||||||
|
|
||||||
|
call.reset_mock()
|
||||||
|
self.assertFalse(arch.create('foo'))
|
||||||
|
call.assert_called_once_with(['false', 'a', 'foo', '.'])
|
||||||
|
|
||||||
|
call.reset_mock()
|
||||||
self.assertFalse(arch.extract('foo'))
|
self.assertFalse(arch.extract('foo'))
|
||||||
call.assert_called_once_with(['false', 'x', 'foo'])
|
call.assert_called_once_with(['false', 'x', 'foo'])
|
||||||
|
|
||||||
@@ -128,6 +137,12 @@ class TestArchive(TestCase):
|
|||||||
self.assertTrue(arch.create('foo.tgz'))
|
self.assertTrue(arch.create('foo.tgz'))
|
||||||
call.assert_called_once_with(['tar', 'zcf', 'foo.tgz', 'bar', 'foo'])
|
call.assert_called_once_with(['tar', 'zcf', 'foo.tgz', 'bar', 'foo'])
|
||||||
|
|
||||||
|
call.reset_mock()
|
||||||
|
call.return_value = 1
|
||||||
|
arch = file_archive.TarArchive()
|
||||||
|
self.assertFalse(arch.create('foo.tar'))
|
||||||
|
call.assert_called_once_with(['tar', 'cf', 'foo.tar', 'bar', 'foo'])
|
||||||
|
|
||||||
@mock.patch('fs_uae_wrapper.path.which')
|
@mock.patch('fs_uae_wrapper.path.which')
|
||||||
@mock.patch('subprocess.call')
|
@mock.patch('subprocess.call')
|
||||||
def test_lha(self, call, which):
|
def test_lha(self, call, which):
|
||||||
@@ -208,6 +223,11 @@ class TestArchive(TestCase):
|
|||||||
self.assertFalse(arch.extract('foo'))
|
self.assertFalse(arch.extract('foo'))
|
||||||
call.assert_called_once_with(['7z', 'x', 'foo'])
|
call.assert_called_once_with(['7z', 'x', 'foo'])
|
||||||
|
|
||||||
|
which.side_effect = ['zip', 'unzip']
|
||||||
|
arch = file_archive.ZipArchive()
|
||||||
|
self.assertEqual(arch._compress, 'zip')
|
||||||
|
self.assertEqual(arch._decompress, 'unzip')
|
||||||
|
|
||||||
@mock.patch('fs_uae_wrapper.path.which')
|
@mock.patch('fs_uae_wrapper.path.which')
|
||||||
@mock.patch('subprocess.call')
|
@mock.patch('subprocess.call')
|
||||||
def test_rar(self, call, which):
|
def test_rar(self, call, which):
|
||||||
@@ -231,17 +251,23 @@ class TestArchive(TestCase):
|
|||||||
self.assertTrue(arch.create('foo.rar'))
|
self.assertTrue(arch.create('foo.rar'))
|
||||||
call.assert_called_once_with(['rar', 'a', 'foo.rar', 'bar', 'baz',
|
call.assert_called_once_with(['rar', 'a', 'foo.rar', 'bar', 'baz',
|
||||||
'directory', 'foo'])
|
'directory', 'foo'])
|
||||||
|
|
||||||
|
call.return_value = 1
|
||||||
|
call.reset_mock()
|
||||||
|
self.assertFalse(arch.create('foo.rar'))
|
||||||
|
call.assert_called_once_with(['rar', 'a', 'foo.rar', 'bar', 'baz',
|
||||||
|
'directory', 'foo'])
|
||||||
|
|
||||||
with open('foo', 'w') as fobj:
|
with open('foo', 'w') as fobj:
|
||||||
fobj.write('\n')
|
fobj.write('\n')
|
||||||
|
|
||||||
call.reset_mock()
|
call.reset_mock()
|
||||||
call.return_value = 1
|
|
||||||
self.assertFalse(arch.extract('foo'))
|
self.assertFalse(arch.extract('foo'))
|
||||||
call.assert_called_once_with(['rar', 'x', 'foo'])
|
call.assert_called_once_with(['rar', 'x', 'foo'])
|
||||||
|
|
||||||
call.reset_mock()
|
call.reset_mock()
|
||||||
call.return_value = 0
|
call.return_value = 0
|
||||||
arch._compess = arch._decompess = arch.archiver = 'unrar'
|
arch._compress = arch._decompress = arch.archiver = 'unrar'
|
||||||
|
|
||||||
self.assertFalse(arch.create('foo'))
|
self.assertFalse(arch.create('foo'))
|
||||||
call.assert_not_called()
|
call.assert_not_called()
|
||||||
@@ -250,3 +276,42 @@ class TestArchive(TestCase):
|
|||||||
call.return_value = 1
|
call.return_value = 1
|
||||||
self.assertFalse(arch.extract('foo'))
|
self.assertFalse(arch.extract('foo'))
|
||||||
call.assert_called_once_with(['unrar', 'x', 'foo'])
|
call.assert_called_once_with(['unrar', 'x', 'foo'])
|
||||||
|
|
||||||
|
|
||||||
|
class TestArchivers(TestCase):
|
||||||
|
|
||||||
|
def test_get(self):
|
||||||
|
self.assertEqual(file_archive.Archivers.get('tar'),
|
||||||
|
file_archive.TarArchive)
|
||||||
|
self.assertEqual(file_archive.Archivers.get('tar.gz'),
|
||||||
|
file_archive.TarGzipArchive)
|
||||||
|
self.assertEqual(file_archive.Archivers.get('tgz'),
|
||||||
|
file_archive.TarGzipArchive)
|
||||||
|
self.assertEqual(file_archive.Archivers.get('tar.bz2'),
|
||||||
|
file_archive.TarBzip2Archive)
|
||||||
|
self.assertEqual(file_archive.Archivers.get('tar.xz'),
|
||||||
|
file_archive.TarXzArchive)
|
||||||
|
self.assertEqual(file_archive.Archivers.get('rar'),
|
||||||
|
file_archive.RarArchive)
|
||||||
|
self.assertEqual(file_archive.Archivers.get('7z'),
|
||||||
|
file_archive.SevenZArchive)
|
||||||
|
self.assertEqual(file_archive.Archivers.get('lha'),
|
||||||
|
file_archive.LhaArchive)
|
||||||
|
self.assertEqual(file_archive.Archivers.get('lzh'),
|
||||||
|
file_archive.LhaArchive)
|
||||||
|
self.assertEqual(file_archive.Archivers.get('lzx'),
|
||||||
|
file_archive.LzxArchive)
|
||||||
|
self.assertIsNone(file_archive.Archivers.get('ace'))
|
||||||
|
|
||||||
|
def test_get_extension_by_name(self):
|
||||||
|
archivers = file_archive.Archivers
|
||||||
|
self.assertEqual(archivers.get_extension_by_name('tar'), '.tar')
|
||||||
|
self.assertEqual(archivers.get_extension_by_name('tgz'), '.tar.gz')
|
||||||
|
self.assertEqual(archivers.get_extension_by_name('tar.bz2'),
|
||||||
|
'.tar.bz2')
|
||||||
|
self.assertEqual(archivers.get_extension_by_name('tar.xz'), '.tar.xz')
|
||||||
|
self.assertEqual(archivers.get_extension_by_name('rar'), '.rar')
|
||||||
|
self.assertEqual(archivers.get_extension_by_name('7z'), '.7z')
|
||||||
|
self.assertEqual(archivers.get_extension_by_name('lha'), '.lha')
|
||||||
|
self.assertEqual(archivers.get_extension_by_name('lzx'), '.lzx')
|
||||||
|
self.assertIsNone(archivers.get_extension_by_name('ace'))
|
||||||
|
|||||||
@@ -11,8 +11,12 @@ from fs_uae_wrapper import utils
|
|||||||
|
|
||||||
class TestPlainModule(TestCase):
|
class TestPlainModule(TestCase):
|
||||||
|
|
||||||
@mock.patch('subprocess.call')
|
@mock.patch('fs_uae_wrapper.utils.run_command')
|
||||||
def test_show(self, subprocess_call):
|
def test_run(self, run_command):
|
||||||
|
wrapper = plain.Wrapper('some.conf', utils.CmdOption(), {})
|
||||||
|
wrapper.run()
|
||||||
|
run_command.assert_called_once_with(['fs-uae', 'some.conf'])
|
||||||
|
|
||||||
plain.run('some.conf', utils.CmdOption(), None)
|
def test_clean(self):
|
||||||
subprocess_call.assert_called_once()
|
wrapper = plain.Wrapper('some.conf', utils.CmdOption(), {})
|
||||||
|
self.assertIsNone(wrapper.clean())
|
||||||
|
|||||||
79
tests/test_savestate.py
Normal file
79
tests/test_savestate.py
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
from tempfile import mkdtemp
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
try:
|
||||||
|
from unittest import mock
|
||||||
|
except ImportError:
|
||||||
|
import mock
|
||||||
|
|
||||||
|
from fs_uae_wrapper import savestate
|
||||||
|
from fs_uae_wrapper import utils
|
||||||
|
|
||||||
|
|
||||||
|
class TestSaveState(TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.dirname = mkdtemp()
|
||||||
|
self.curdir = os.path.abspath(os.curdir)
|
||||||
|
os.chdir(self.dirname)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
os.chdir(self.curdir)
|
||||||
|
try:
|
||||||
|
shutil.rmtree(self.dirname)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
@mock.patch('tempfile.mkdtemp')
|
||||||
|
@mock.patch('fs_uae_wrapper.path.which')
|
||||||
|
@mock.patch('fs_uae_wrapper.base.Base._save_save')
|
||||||
|
@mock.patch('fs_uae_wrapper.base.Base._get_saves_dir')
|
||||||
|
@mock.patch('fs_uae_wrapper.base.Base._run_emulator')
|
||||||
|
@mock.patch('fs_uae_wrapper.base.Base._copy_conf')
|
||||||
|
@mock.patch('fs_uae_wrapper.base.Base._load_save')
|
||||||
|
def test_run(self, load_save, copy_conf, run_emulator, get_save_dir,
|
||||||
|
save_state, which, mkdtemp):
|
||||||
|
|
||||||
|
copy_conf.return_value = False
|
||||||
|
run_emulator.return_value = False
|
||||||
|
get_save_dir.return_value = False
|
||||||
|
save_state.return_value = False
|
||||||
|
which.return_value = 'rar'
|
||||||
|
|
||||||
|
arch = savestate.Wrapper('Config.fs-uae', utils.CmdOption(), {})
|
||||||
|
self.assertFalse(arch.run())
|
||||||
|
|
||||||
|
arch.all_options = {'wrapper': 'savestate',
|
||||||
|
'wrapper_save_state': '1',
|
||||||
|
'wrapper_archiver': 'rar'}
|
||||||
|
|
||||||
|
self.assertFalse(arch.run())
|
||||||
|
|
||||||
|
self.assertFalse(arch.run())
|
||||||
|
|
||||||
|
copy_conf.return_value = True
|
||||||
|
self.assertFalse(arch.run())
|
||||||
|
|
||||||
|
run_emulator.return_value = True
|
||||||
|
self.assertTrue(arch.run())
|
||||||
|
|
||||||
|
get_save_dir.return_value = True
|
||||||
|
self.assertFalse(arch.run())
|
||||||
|
|
||||||
|
save_state.return_value = True
|
||||||
|
self.assertTrue(arch.run())
|
||||||
|
|
||||||
|
@mock.patch('fs_uae_wrapper.path.which')
|
||||||
|
def test_validate_options(self, which):
|
||||||
|
which.return_value = 'unrar'
|
||||||
|
|
||||||
|
arch = savestate.Wrapper('Config.fs-uae', utils.CmdOption(), {})
|
||||||
|
self.assertFalse(arch._validate_options())
|
||||||
|
|
||||||
|
arch.all_options['wrapper'] = 'savestate'
|
||||||
|
self.assertFalse(arch._validate_options())
|
||||||
|
|
||||||
|
arch.all_options['wrapper_archiver'] = 'rar'
|
||||||
|
self.assertTrue(arch._validate_options())
|
||||||
@@ -83,7 +83,7 @@ class TestUtils(TestCase):
|
|||||||
which.return_value = None
|
which.return_value = None
|
||||||
|
|
||||||
# No config
|
# No config
|
||||||
self.assertFalse(utils.operate_archive('non-existend.7z', 'foo', '',
|
self.assertFalse(utils.operate_archive('non-existent.7z', 'foo', '',
|
||||||
None))
|
None))
|
||||||
|
|
||||||
# Archive type not known
|
# Archive type not known
|
||||||
@@ -114,45 +114,36 @@ class TestUtils(TestCase):
|
|||||||
create.assert_called_once()
|
create.assert_called_once()
|
||||||
show.assert_called_once()
|
show.assert_called_once()
|
||||||
|
|
||||||
def test_extract_archive(self):
|
@mock.patch('fs_uae_wrapper.utils.operate_archive')
|
||||||
|
def test_extract_archive(self, operate):
|
||||||
|
|
||||||
os.chdir(self.dirname)
|
os.chdir(self.dirname)
|
||||||
|
|
||||||
# No config
|
operate.return_value = True
|
||||||
self.assertFalse(utils.extract_archive('non-existend.7z'))
|
self.assertTrue(utils.extract_archive('arch.7z'))
|
||||||
|
operate.assert_called_once_with('arch.7z', 'extract', '', None)
|
||||||
|
|
||||||
# Archive type not known
|
operate.reset_mock()
|
||||||
with open('unsupported-archive.ace', 'w') as fobj:
|
operate.return_value = False
|
||||||
fobj.write("\n")
|
self.assertFalse(utils.extract_archive('arch.7z', 'MyFoo',
|
||||||
self.assertFalse(utils.extract_archive('unsupported-archive.ace'))
|
['foo', 'bar']))
|
||||||
|
operate.assert_called_once_with('arch.7z', 'extract',
|
||||||
|
"Extracting files for `MyFoo'. Please"
|
||||||
|
" be patient", ['foo', 'bar'])
|
||||||
|
|
||||||
# archive is known, but extraction will fail - we have an empty
|
@mock.patch('fs_uae_wrapper.utils.operate_archive')
|
||||||
# archive and there is no guarantee, that 7z exists on system where
|
def test_create_archive(self, operate):
|
||||||
# test will run
|
operate.return_value = True
|
||||||
with open('supported-archive.7z', 'w') as fobj:
|
self.assertTrue(utils.create_archive('arch.7z'))
|
||||||
fobj.write("\n")
|
operate.assert_called_once_with('arch.7z', 'create', '', None)
|
||||||
self.assertFalse(utils.extract_archive('supported-archive.7z'))
|
|
||||||
|
|
||||||
@mock.patch('fs_uae_wrapper.file_archive.Archive.create')
|
operate.reset_mock()
|
||||||
def test_create_archive(self, arch_create):
|
operate.return_value = False
|
||||||
arch_create.return_value = True
|
self.assertFalse(utils.create_archive('arch.7z', 'MyFoo',
|
||||||
|
['foo', 'bar']))
|
||||||
os.chdir(self.dirname)
|
operate.assert_called_once_with('arch.7z', 'create',
|
||||||
|
"Creating archive for `MyFoo'. Please"
|
||||||
# No config
|
" be patient", ['foo', 'bar'])
|
||||||
self.assertFalse(utils.extract_archive('non-existend.7z'))
|
|
||||||
|
|
||||||
# Archive type not known
|
|
||||||
with open('unsupported-archive.ace', 'w') as fobj:
|
|
||||||
fobj.write("\n")
|
|
||||||
self.assertFalse(utils.extract_archive('unsupported-archive.ace'))
|
|
||||||
|
|
||||||
# archive is known, but extraction will fail - we have an empty
|
|
||||||
# archive and there is no guarantee, that 7z exists on system where
|
|
||||||
# test will run
|
|
||||||
with open('supported-archive.7z', 'w') as fobj:
|
|
||||||
fobj.write("\n")
|
|
||||||
self.assertFalse(utils.extract_archive('supported-archive.7z'))
|
|
||||||
|
|
||||||
@mock.patch('fs_uae_wrapper.path.which')
|
@mock.patch('fs_uae_wrapper.path.which')
|
||||||
@mock.patch('fs_uae_wrapper.file_archive.Archive.extract')
|
@mock.patch('fs_uae_wrapper.file_archive.Archive.extract')
|
||||||
@@ -179,6 +170,37 @@ class TestUtils(TestCase):
|
|||||||
self.assertDictEqual(conf, {'foo': '1', 'bar': 'zip'})
|
self.assertDictEqual(conf, {'foo': '1', 'bar': 'zip'})
|
||||||
self.assertDictEqual(other, {'foo': '2', 'baz': '3'})
|
self.assertDictEqual(other, {'foo': '2', 'baz': '3'})
|
||||||
|
|
||||||
|
@mock.patch('subprocess.call')
|
||||||
|
def test_run_command(self, call):
|
||||||
|
call.return_value = 0
|
||||||
|
self.assertTrue(utils.run_command(['ls']))
|
||||||
|
call.assert_called_once_with(['ls'])
|
||||||
|
|
||||||
|
call.reset_mock()
|
||||||
|
self.assertTrue(utils.run_command('ls -l'))
|
||||||
|
call.assert_called_once_with(['ls', '-l'])
|
||||||
|
|
||||||
|
call.return_value = 1
|
||||||
|
call.reset_mock()
|
||||||
|
self.assertFalse(utils.run_command(['ls', '-l']))
|
||||||
|
call.assert_called_once_with(['ls', '-l'])
|
||||||
|
|
||||||
|
call.reset_mock()
|
||||||
|
self.assertFalse(utils.run_command('ls'))
|
||||||
|
call.assert_called_once_with(['ls'])
|
||||||
|
|
||||||
|
@mock.patch('os.path.exists')
|
||||||
|
def test_get_config(self, exists):
|
||||||
|
exists.return_value = False
|
||||||
|
|
||||||
|
os.chdir(self.dirname)
|
||||||
|
self.assertDictEqual(utils.get_config('foo'), {})
|
||||||
|
|
||||||
|
with open('conf.fs-uae', 'w') as fobj:
|
||||||
|
fobj.write("[conf]\nwrapper=foo\n")
|
||||||
|
self.assertDictEqual(utils.get_config('conf.fs-uae'),
|
||||||
|
{'wrapper': 'foo'})
|
||||||
|
|
||||||
|
|
||||||
class TestCmdOptions(TestCase):
|
class TestCmdOptions(TestCase):
|
||||||
|
|
||||||
@@ -219,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')
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class TestWrapper(TestCase):
|
|||||||
os.unlink(self.fname)
|
os.unlink(self.fname)
|
||||||
sys.argv = self._argv[:]
|
sys.argv = self._argv[:]
|
||||||
|
|
||||||
@mock.patch('fs_uae_wrapper.plain.run')
|
@mock.patch('fs_uae_wrapper.plain.Wrapper.run')
|
||||||
def test_run(self, mock_plain_run):
|
def test_run(self, mock_plain_run):
|
||||||
|
|
||||||
sys.argv.append('--help')
|
sys.argv.append('--help')
|
||||||
@@ -67,11 +67,13 @@ class TestWrapper(TestCase):
|
|||||||
def test_parse_args(self):
|
def test_parse_args(self):
|
||||||
|
|
||||||
# Looking for configuration file... first, we have nothing
|
# Looking for configuration file... first, we have nothing
|
||||||
self.assertEqual(wrapper.parse_args(), (None, {}))
|
self.assertEqual(wrapper.parse_args(),
|
||||||
|
(None, {'wrapper_verbose': 0, 'wrapper_quiet': 0}))
|
||||||
|
|
||||||
# still no luck - nonexistent file
|
# still no luck - nonexistent file
|
||||||
sys.argv.append('there-is-no-config.fs-uae')
|
sys.argv.append('there-is-no-config.fs-uae')
|
||||||
self.assertEqual(wrapper.parse_args(), (None, {}))
|
self.assertEqual(wrapper.parse_args(),
|
||||||
|
(None, {'wrapper_verbose': 0, 'wrapper_quiet': 0}))
|
||||||
|
|
||||||
# lets make it
|
# lets make it
|
||||||
os.chdir(self.dirname)
|
os.chdir(self.dirname)
|
||||||
@@ -79,7 +81,8 @@ class TestWrapper(TestCase):
|
|||||||
fobj.write('\n')
|
fobj.write('\n')
|
||||||
|
|
||||||
self.assertEqual(wrapper.parse_args(),
|
self.assertEqual(wrapper.parse_args(),
|
||||||
('there-is-no-config.fs-uae', {}))
|
('there-is-no-config.fs-uae',
|
||||||
|
{'wrapper_verbose': 0, 'wrapper_quiet': 0}))
|
||||||
|
|
||||||
# remove argument, try to find default one
|
# remove argument, try to find default one
|
||||||
sys.argv.pop()
|
sys.argv.pop()
|
||||||
@@ -88,7 +91,9 @@ class TestWrapper(TestCase):
|
|||||||
with open('Config.fs-uae', 'w') as fobj:
|
with open('Config.fs-uae', 'w') as fobj:
|
||||||
fobj.write('\n')
|
fobj.write('\n')
|
||||||
|
|
||||||
self.assertEqual(wrapper.parse_args(), ('Config.fs-uae', {}))
|
self.assertEqual(wrapper.parse_args(),
|
||||||
|
('Config.fs-uae',
|
||||||
|
{'wrapper_verbose': 0, 'wrapper_quiet': 0}))
|
||||||
|
|
||||||
# add --wrapper-foo and --wrapper-bar options
|
# add --wrapper-foo and --wrapper-bar options
|
||||||
sys.argv.extend(['--wrapper=plain', '--wrapper_foo=1',
|
sys.argv.extend(['--wrapper=plain', '--wrapper_foo=1',
|
||||||
@@ -104,7 +109,9 @@ class TestWrapper(TestCase):
|
|||||||
self.assertEqual(conf, 'Config.fs-uae')
|
self.assertEqual(conf, 'Config.fs-uae')
|
||||||
self.assertDictEqual(fsopts, {'wrapper': 'plain',
|
self.assertDictEqual(fsopts, {'wrapper': 'plain',
|
||||||
'wrapper_foo': '1',
|
'wrapper_foo': '1',
|
||||||
'wrapper_bar': 'false'})
|
'wrapper_bar': 'false',
|
||||||
|
'wrapper_verbose': 0,
|
||||||
|
'wrapper_quiet': 0})
|
||||||
|
|
||||||
# mix wrapper* params in commandline and config
|
# mix wrapper* params in commandline and config
|
||||||
sys.argv = ['fs-uae-wrapper',
|
sys.argv = ['fs-uae-wrapper',
|
||||||
@@ -120,4 +127,6 @@ class TestWrapper(TestCase):
|
|||||||
self.assertDictEqual(fsopts, {'wrapper': 'plain',
|
self.assertDictEqual(fsopts, {'wrapper': 'plain',
|
||||||
'wrapper_bar': 'false',
|
'wrapper_bar': 'false',
|
||||||
'fullscreen': '1',
|
'fullscreen': '1',
|
||||||
'fast_memory': '4096'})
|
'fast_memory': '4096',
|
||||||
|
'wrapper_verbose': 0,
|
||||||
|
'wrapper_quiet': 0})
|
||||||
|
|||||||
Reference in New Issue
Block a user