mirror of
https://github.com/gryf/fs-uae-wrapper.git
synced 2026-02-15 05:25:50 +01:00
Make archive name and archiver for savestate optional.
This commit is contained in:
@@ -237,9 +237,9 @@ class Base(object):
|
||||
return True
|
||||
|
||||
if 'wrapper_archiver' not in self.all_options:
|
||||
logging.error("Configuration lacks of required "
|
||||
"`wrapper_archiver' option.")
|
||||
return False
|
||||
logging.warning("Configuration lacks of optional "
|
||||
"`wrapper_archiver' option, fall back to 7z")
|
||||
self.all_options['wrapper_archiver'] = "7z"
|
||||
|
||||
if not path.which(self.all_options['wrapper_archiver']):
|
||||
logging.error("Cannot find archiver `%s'.",
|
||||
@@ -295,8 +295,30 @@ class ArchiveBase(Base):
|
||||
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
|
||||
logging.warning("Configuration lacks of optional `wrapper_archive'"
|
||||
" option.\n")
|
||||
wrapper_archive = self._get_wrapper_archive_name()
|
||||
if wrapper_archive is None:
|
||||
logging.error("Configuration lacks of optional "
|
||||
"`wrapper_archive', cannot deduct the name by "
|
||||
"configuration file name.\n")
|
||||
validation_result = False
|
||||
self.all_options['wrapper_archive'] = wrapper_archive
|
||||
|
||||
return validation_result
|
||||
|
||||
def _get_wrapper_archive_name(self):
|
||||
"""
|
||||
Return full path to the archive name using configuration file
|
||||
basename and appending one of the expected archive extensions.
|
||||
"""
|
||||
basename = os.path.splitext(self.conf_file)[0]
|
||||
file_list = os.listdir('.')
|
||||
for fname in file_list:
|
||||
for ext in ('.7z', '.lha', '.lzx', '.zip', '.rar', '.tar', '.tgz',
|
||||
'.tar.gz', '.tar.bz2', '.tar.xz'):
|
||||
if ((basename + ext).lower() == fname.lower() and
|
||||
basename == os.path.splitext(fname)[0]):
|
||||
return fname
|
||||
return None
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ Misc utilities
|
||||
import configparser
|
||||
import logging
|
||||
import os
|
||||
import pathlib
|
||||
import shutil
|
||||
import subprocess
|
||||
|
||||
@@ -19,8 +20,8 @@ class CmdOption(dict):
|
||||
def add(self, option):
|
||||
"""parse and add option to the dictionary"""
|
||||
if not option.startswith('--'):
|
||||
raise AttributeError("Cannot add option `%s' to the dictionary" %
|
||||
option)
|
||||
raise AttributeError(f"Cannot add option {option} to the "
|
||||
f"dictionary")
|
||||
if '=' in option:
|
||||
key, val = option.split('=', 1)
|
||||
key = key[2:].strip()
|
||||
@@ -35,9 +36,9 @@ class CmdOption(dict):
|
||||
ret_list = []
|
||||
for key, val in self.items():
|
||||
if val != '1':
|
||||
ret_list.append('--%(k)s=%(v)s' % {'k': key, 'v': val})
|
||||
ret_list.append(f'--{key}={val}')
|
||||
else:
|
||||
ret_list.append('--%(k)s' % {'k': key})
|
||||
ret_list.append(f'--{key}')
|
||||
return ret_list
|
||||
|
||||
|
||||
@@ -87,7 +88,7 @@ def create_archive(arch_name, title='', params=None):
|
||||
"""
|
||||
msg = ''
|
||||
if title:
|
||||
msg = "Creating archive for `%s'. Please be patient" % title
|
||||
msg = f"Creating archive for `{title}'. Please be patient"
|
||||
return operate_archive(arch_name, 'create', msg, params)
|
||||
|
||||
|
||||
@@ -97,7 +98,7 @@ def extract_archive(arch_name, title='', params=None):
|
||||
"""
|
||||
msg = ''
|
||||
if title:
|
||||
msg = "Extracting files for `%s'. Please be patient" % title
|
||||
msg = f"Extracting files for `{title}'. Please be patient"
|
||||
return operate_archive(arch_name, 'extract', msg, params)
|
||||
|
||||
|
||||
@@ -143,8 +144,9 @@ def interpolate_variables(string, config_path, base=None):
|
||||
|
||||
_string = string
|
||||
if '$CONFIG' in string:
|
||||
conf_path = os.path.dirname(os.path.abspath(config_path))
|
||||
string = os.path.abspath(string.replace('$CONFIG', conf_path))
|
||||
conf_path = pathlib.Path(config_path).resolve().parent
|
||||
string = str(pathlib.Path(string.replace('$CONFIG', str(conf_path)))
|
||||
.resolve())
|
||||
|
||||
if '$HOME' in string:
|
||||
string = string.replace('$HOME', os.path.expandvars('$HOME'))
|
||||
|
||||
Reference in New Issue
Block a user