1import os 2import subprocess 3 4from fsbc import settings 5from fsgs.option import Option 6from .fsuae import FSUAE 7 8try: 9 getcwd = os.getcwdu 10except AttributeError: 11 getcwd = os.getcwd 12 13 14class FSUAEDeviceHelper(object): 15 @classmethod 16 def start_with_args(cls, args, **kwargs): 17 print("FSUAE.start_with_args:", args) 18 exe = cls.find_executable() 19 print("current dir (cwd): ", getcwd()) 20 print("using fs-uae executable:", exe) 21 args = [exe] + args 22 print(args) 23 env = os.environ.copy() 24 if settings.get(Option.FAKE_JOYSTICKS): 25 try: 26 fake_joysticks = int(settings.get(Option.FAKE_JOYSTICKS)) 27 except ValueError: 28 print( 29 "WARNING: fake_joysticks contains invalid value", 30 repr(settings.get(Option.FAKE_JOYSTICKS)), 31 ) 32 else: 33 env["FSGS_FAKE_JOYSTICKS"] = str(fake_joysticks) 34 FSUAE.add_environment_from_settings(env) 35 process = subprocess.Popen( 36 args, 37 env=env, 38 stdin=subprocess.PIPE, 39 stderr=subprocess.PIPE, 40 **kwargs 41 ) 42 return process 43 44 @classmethod 45 def find_executable(cls): 46 return FSUAE.find_executable("fs-uae-device-helper") 47