Skip to content
This repository was archived by the owner on Dec 1, 2022. It is now read-only.

Commit 813d859

Browse files
authored
Merge pull request #5 from stashfiler/dev
Add support for translating any Windows path(s) passed on the command-line
2 parents 1eb5d5b + 418bff0 commit 813d859

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

docker-compose-wsl.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,24 @@ def wsl_drive_map(string_to_map):
5353

5454
# Replace Windows path with WSL supported path
5555
for idx, cli_arg in enumerate(cli_args):
56+
windows_file_path = cli_arg
5657

5758
if idx != 0 and cli_args[idx - 1] == '-f':
5859
compose_file = cli_arg
5960
compose_file_name = os.path.basename(compose_file)
60-
tmp_compose_file = os.path.join(compose_file_tmp_dir, compose_file_name)
61+
windows_file_path = os.path.join(compose_file_tmp_dir, compose_file_name)
6162

6263
if os.path.isfile(compose_file):
6364
compose_file_content = pathlib.Path(compose_file).read_text()
6465
new_compose_file_content = wsl_drive_map(compose_file_content)
65-
pathlib.Path(tmp_compose_file).write_text(new_compose_file_content)
66+
pathlib.Path(windows_file_path).write_text(new_compose_file_content)
6667
else:
6768
sys.stderr.write('The PyCharm docker-compose file "{0}" does not exists, exiting...'.format(
6869
compose_file))
6970
raise SystemExit(1)
7071

71-
compose_file_mapped = wsl_drive_map(tmp_compose_file)
72-
docker_compose_cli_args += '{0} '.format(compose_file_mapped)
73-
72+
if os.path.exists(windows_file_path):
73+
docker_compose_cli_args += '{0} '.format(wsl_drive_map(windows_file_path))
7474
else:
7575
docker_compose_cli_args += '{0} '.format(cli_arg)
7676

@@ -85,4 +85,9 @@ def wsl_drive_map(string_to_map):
8585
print('The docker-compose command was: {0}'.format(' '.join(docker_compose_cmd)))
8686

8787
# Run the docker-compose binary in bash on WSL with the appropriate argument(s)
88-
subprocess.run(docker_compose_cmd, shell=True)
88+
docker_compose_process = subprocess.Popen(docker_compose_cmd, shell=True)
89+
90+
try:
91+
docker_compose_process.wait()
92+
except KeyboardInterrupt:
93+
docker_compose_process.terminate()

0 commit comments

Comments
 (0)