master
py 36 lines 1.17 KB
Raw
1 #!/usr/bin/env python3
2
3 from pathlib import PurePath
4 import errno
5 import json
6 import os
7 import shlex
8 import subprocess
9 import sys
10
11 def destdir_join(d1: str, d2: str) -> str:
12 if not d1:
13 return d2
14 # c:\destdir + c:\prefix must produce c:\destdir\prefix
15 return str(PurePath(d1, *PurePath(d2).parts[1:]))
16
17 introspect = os.environ.get('MESONINTROSPECT')
18 out = subprocess.run([*shlex.split(introspect), '--installed'],
19 stdout=subprocess.PIPE, check=True).stdout
20 for source, dest in json.loads(out).items():
21 bundle_dest = destdir_join('qemu-bundle', dest)
22 path = os.path.dirname(bundle_dest)
23 try:
24 os.makedirs(path, exist_ok=True)
25 except BaseException as e:
26 print(f'error making directory {path}', file=sys.stderr)
27 raise e
28 try:
29 os.symlink(source, bundle_dest)
30 except BaseException as e:
31 if not isinstance(e, OSError) or e.errno != errno.EEXIST:
32 if os.name == 'nt':
33 print('Please enable Developer Mode to support soft link '
34 'without Administrator permission')
35 print(f'error making symbolic link {dest}', file=sys.stderr)
36 raise e