1
0
mirror of https://github.com/gryf/fs-uae-wrapper.git synced 2026-02-02 06:05:45 +01:00

Implementation for saving changes in archive wrapper module

This commit is contained in:
2017-01-02 13:47:07 +01:00
parent 251fab377b
commit 38a9604916
2 changed files with 96 additions and 11 deletions

View File

@@ -4,9 +4,12 @@ Run fs-uae with archived filesystem/adf files
It will use compressed directories, and optionally replace source archive with
the temporary one.
"""
import os
import shutil
import sys
from fs_uae_wrapper import base
from fs_uae_wrapper import utils
class Archive(base.Base):
@@ -41,6 +44,8 @@ class Archive(base.Base):
if not self._extract():
return False
self._load_save()
if not self._copy_conf():
return False
@@ -48,10 +53,10 @@ class Archive(base.Base):
if kick_opts:
self.fsuae_options.update(kick_opts)
if self._run_emulator(self.fsuae_options.list()):
return self._make_archive()
if not self._run_emulator(self.fsuae_options.list()):
return False
return True
return self._make_archive()
def _validate_options(self):
@@ -71,6 +76,29 @@ class Archive(base.Base):
"""
Produce archive and save it back. Than remove old one.
"""
if self.all_options.get('wrapper_persist_data', '0') != '1':
return True
saves = self._get_saves_dir()
if saves:
if not self._save_save():
return False
curdir = os.path.abspath('.')
os.chdir(self.dir)
if saves:
shutil.rmtree(saves)
os.unlink('Config.fs-uae')
title = self._get_title()
arch = os.path.basename(self.arch_filepath)
if not utils.create_archive(arch, title):
return False
os.rename(arch, self.arch_filepath)
os.chdir(curdir)
return True

View File

@@ -1,3 +1,6 @@
import os
import shutil
from tempfile import mkdtemp
from unittest import TestCase
try:
@@ -11,6 +14,18 @@ from fs_uae_wrapper import utils
class TestArchive(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
def test_validate_options(self):
arch = archive.Archive('Config.fs-uae', utils.CmdOption(), {})
@@ -23,16 +38,20 @@ class TestArchive(TestCase):
self.assertTrue(arch._validate_options())
@mock.patch('tempfile.mkdtemp')
@mock.patch('fs_uae_wrapper.archive.Archive._make_archive')
@mock.patch('fs_uae_wrapper.base.Base._run_emulator')
@mock.patch('fs_uae_wrapper.base.Base._kickstart_option')
@mock.patch('fs_uae_wrapper.base.Base._copy_conf')
@mock.patch('fs_uae_wrapper.base.Base._load_save')
@mock.patch('fs_uae_wrapper.base.Base._extract')
def test_run(self, extr, cconf, kick, runemul, mkdtemp):
def test_run(self, extr, load, copy, kick, run, march, mkdtemp):
extr.return_value = False
cconf.return_value = False
kick.return_value = {}
runemul.return_value = False
load.return_value = False
copy.return_value = False
kick.return_value = False
run.return_value = False
march.return_value = False
arch = archive.Archive('Config.fs-uae', utils.CmdOption(), {})
self.assertFalse(arch.run())
@@ -45,12 +64,50 @@ class TestArchive(TestCase):
extr.return_value = True
self.assertFalse(arch.run())
cconf.return_value = True
self.assertTrue(arch.run())
load.return_value = True
self.assertFalse(arch.run())
copy.return_value = True
self.assertFalse(arch.run())
kick.return_value = {'foo': 'bar'}
self.assertTrue(arch.run())
self.assertFalse(arch.run())
self.assertDictEqual(arch.fsuae_options, {'foo': 'bar'})
runemul.return_value = True
run.return_value = True
self.assertFalse(arch.run())
march.return_value = True
self.assertTrue(arch.run())
@mock.patch('os.rename')
@mock.patch('os.unlink')
@mock.patch('shutil.rmtree')
@mock.patch('fs_uae_wrapper.utils.create_archive')
@mock.patch('fs_uae_wrapper.base.Base._get_title')
@mock.patch('fs_uae_wrapper.base.Base._save_save')
@mock.patch('fs_uae_wrapper.base.Base._get_saves_dir')
def test_make_archive(self, sdir, save, title, carch, rmt, unlink, rename):
sdir.return_value = None
save.return_value = False
title.return_value = ''
carch.return_value = False
arch = archive.Archive('Config.fs-uae', utils.CmdOption(), {})
arch.dir = self.dirname
arch.arch_filepath = os.path.join(self.dirname, 'foo.tgz')
arch.all_options = {}
self.assertTrue(arch._make_archive())
arch.all_options['wrapper_persist_data'] = '1'
self.assertFalse(arch._make_archive())
carch.return_value = True
self.assertTrue(arch._make_archive())
sdir.return_value = '/some/path'
self.assertFalse(arch._make_archive())
save.return_value = True
self.assertTrue(arch._make_archive())