Skip to content

Commit

Permalink
Simplify 'get_runner_args' for WINE
Browse files Browse the repository at this point in the history
  • Loading branch information
BurnySc2 committed Jul 24, 2020
1 parent 4765d3f commit ea56fa6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions examples/competitive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sc2
from sc2 import Race, Difficulty
from sc2.player import Bot, Computer
from sc2.protocol import ConnectionAlreadyClosed

from sc2.sc2process import SC2Process
from sc2.client import Client
Expand Down
17 changes: 10 additions & 7 deletions sc2/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ def get_env():

def get_runner_args(cwd):
if "WINE" in os.environ:
runner_dir = os.path.dirname(os.environ.get("WINE"))
# translate cwd from Unix to Windows path
win_cwd = subprocess.run(
[os.path.join(runner_dir, "winepath"), "-w", cwd], capture_output=True, text=True
).stdout.rstrip()
return [os.environ.get("WINE"), "start", "/d", win_cwd, "/unix"]

runner_file = Path(os.environ.get("WINE"))
runner_file = runner_file if runner_file.is_file() else runner_file / "wine"
"""
TODO Is converting linux path really necessary?
That would convert
'/home/burny/Games/battlenet/drive_c/Program Files (x86)/StarCraft II/Support64'
to
'Z:\\home\\burny\\Games\\battlenet\\drive_c\\Program Files (x86)\\StarCraft II\\Support64'
"""
return [runner_file, "start", "/d", cwd, "/unix"]
return []


Expand Down
3 changes: 2 additions & 1 deletion sc2/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async def proxy_handler(self, request):
return bot_ws

async def play_with_proxy(self, startport):
logger.info(f"Proxy({self.port}): starting app")
logger.info(f"Proxy({self.port}): Starting app")
app = web.Application()
app.router.add_route("GET", "/sc2api", self.proxy_handler)
apprunner = web.AppRunner(app, access_log=None)
Expand All @@ -167,6 +167,7 @@ async def play_with_proxy(self, startport):
subproc_args["creationflags"] = subprocess.CREATE_NEW_PROCESS_GROUP

player_command_line = self.player.cmd_line(self.port, startport, self.controller._process._host)
logger.info(f"Starting bot with command: {' '.join(player_command_line)}")
if self.player.stdout is None:
bot_process = subprocess.Popen(player_command_line, stdout=subprocess.DEVNULL, **subproc_args)
else:
Expand Down

0 comments on commit ea56fa6

Please sign in to comment.