2
0

symlink-install-tree.py 1.2 KB

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