transform-dep: Use $WINEPREFIX/dosdevices

Former-commit-id: 61bdef3fd2
This commit is contained in:
Luke Street 2022-04-13 00:30:20 -04:00
parent 6673e65599
commit b2752ec346
1 changed files with 10 additions and 11 deletions

View File

@ -1,6 +1,11 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import argparse import argparse
import subprocess import os
wineprefix = os.path.join(os.environ['HOME'], '.wine')
if 'WINEPREFIX' in os.environ:
wineprefix = os.environ['WINEPREFIX']
winedevices = os.path.join(wineprefix, 'dosdevices')
def import_d_file(in_file) -> str: def import_d_file(in_file) -> str:
out_text = '' out_text = ''
@ -19,16 +24,10 @@ def import_d_file(in_file) -> str:
path = line.lstrip()[:-3] path = line.lstrip()[:-3]
else: else:
path = line.strip() path = line.strip()
if path.startswith('Z:'): # lowercase drive letter
# direct mapping to unix path path = path[0].lower() + path[1:]
path = path[2:].replace('\\', '/') # use $WINEPREFIX/dosdevices to resolve path
else: path = os.path.realpath(os.path.join(winedevices, path.replace('\\', '/')))
# use winepath (very slow!)
cmd = subprocess.run(['winepath', '-u', path], capture_output=True, env={'WINEDEBUG': '-all'})
if cmd.returncode != 0:
print("winepath failed with exit code %d:" % cmd.returncode, cmd.stderr)
exit(1)
path = cmd.stdout.decode('utf-8').rstrip()
out_text += "\t" + path + suffix + "\n" out_text += "\t" + path + suffix + "\n"
return out_text return out_text