mirror of
https://github.com/gryf/fs-uae-wrapper.git
synced 2025-12-19 12:28:12 +01:00
Extracted some methods to utils module
This commit is contained in:
@@ -11,17 +11,19 @@ import sys
|
|||||||
class Plain(object):
|
class Plain(object):
|
||||||
"""Class for run fs-uae"""
|
"""Class for run fs-uae"""
|
||||||
|
|
||||||
def run(self, conf, fs_uae_options):
|
def run(self, conf_file, fs_uae_options):
|
||||||
"""
|
"""
|
||||||
Run the emulation.
|
Run the emulation.
|
||||||
conf is a path to the configuration,
|
conf_file is a path to the configuration,
|
||||||
fs_uae_options is a list contains tokenized options to be passed to
|
fs_uae_options is a list contains tokenized options to be passed to
|
||||||
fs-uae
|
fs-uae
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
subprocess.call(['fs-uae'] + [conf] + fs_uae_options)
|
subprocess.call(['fs-uae'] + [conf_file] + fs_uae_options)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
sys.stderr.write('Warning: fs-uae returned non 0 exit code\n')
|
sys.stderr.write('Warning: fs-uae returned non 0 exit code\n')
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
"""In this class, do nothing on exit"""
|
"""In this class, do nothing on exit"""
|
||||||
@@ -33,6 +35,6 @@ def run(config_file, fs_uae_options, _, unused):
|
|||||||
|
|
||||||
runner = Plain()
|
runner = Plain()
|
||||||
try:
|
try:
|
||||||
runner.run(config_file, fs_uae_options)
|
return runner.run(config_file, fs_uae_options)
|
||||||
finally:
|
finally:
|
||||||
runner.clean()
|
runner.clean()
|
||||||
|
|||||||
61
fs_uae_wrapper/utils.py
Normal file
61
fs_uae_wrapper/utils.py
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
"""
|
||||||
|
Misc utilities
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from fs_uae_wrapper.wrapper import WRAPPER_KEY
|
||||||
|
|
||||||
|
|
||||||
|
ARCHIVERS = {'.tar': ['tar', 'xf'],
|
||||||
|
'.tgz': ['tar', 'xf'],
|
||||||
|
'.tar.gz': ['tar', 'xf'],
|
||||||
|
'.tar.bz2': ['tar', 'xf'],
|
||||||
|
'.tar.xz': ['tar', 'xf'],
|
||||||
|
'.rar': ['unrar', 'x'],
|
||||||
|
'.7z': ['7z', 'x'],
|
||||||
|
'.zip': ['7z', 'x'],
|
||||||
|
'.lha': ['lha', 'x'],
|
||||||
|
'.lzx': ['unlzx']}
|
||||||
|
|
||||||
|
|
||||||
|
def extract_archive(arch_name):
|
||||||
|
"""
|
||||||
|
Extract provided archive to current directory
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not os.path.exists(arch_name):
|
||||||
|
sys.stderr.write("Archive `%s' doesn't exists.\n" % arch_name)
|
||||||
|
return False
|
||||||
|
|
||||||
|
_, ext = os.path.splitext(arch_name)
|
||||||
|
|
||||||
|
cmd = ARCHIVERS.get(ext)
|
||||||
|
|
||||||
|
if cmd is None:
|
||||||
|
sys.stderr.write("Unable find archive type for `%s'.\n" % arch_name)
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
subprocess.check_call(cmd + [arch_name])
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
sys.stderr.write("Error during extracting archive `%s'.\n" % arch_name)
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def merge_options(configuration, wrapper_options):
|
||||||
|
"""
|
||||||
|
Merge dictionaries with wrapper options into one. Commandline options
|
||||||
|
have precedence.
|
||||||
|
"""
|
||||||
|
options = {}
|
||||||
|
for key, val in configuration:
|
||||||
|
if WRAPPER_KEY in key:
|
||||||
|
options[key] = val
|
||||||
|
|
||||||
|
options.update(wrapper_options)
|
||||||
|
|
||||||
|
return options
|
||||||
@@ -122,7 +122,9 @@ def run():
|
|||||||
"exists.\n" % wrapper_module)
|
"exists.\n" % wrapper_module)
|
||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
|
|
||||||
wrapper.run(config_file, fs_uae_options, wrapper_options, configuration)
|
if not wrapper.run(config_file, fs_uae_options, wrapper_options,
|
||||||
|
configuration):
|
||||||
|
sys.exit(4)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user