mirror of
https://github.com/UniXNU/UniXNU.git
synced 2026-11-18 10:01:39 +03:00
39 lines
1.4 KiB
Python
39 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Print runtime Metal-library paths from one read-only mounted OS image."""
|
|
import os
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) != 3:
|
|
raise SystemExit('usage: list-metal-libraries.py MOUNT RUNTIME_PREFIX')
|
|
mount, prefix = Path(sys.argv[1]).resolve(), sys.argv[2].rstrip('/')
|
|
paths = set()
|
|
|
|
def failed(error):
|
|
raise error
|
|
|
|
for directory, dirs, files in os.walk(mount, followlinks=False, onerror=failed):
|
|
relative_dir = Path(directory).relative_to(mount).as_posix()
|
|
# Account databases and initial user homes are Data state. Shipped
|
|
# application and framework libraries remain in the image scan.
|
|
if relative_dir == 'System/Library/Templates/Data':
|
|
dirs[:] = [name for name in dirs if name not in ('private', 'Users')]
|
|
if Path(directory) == mount:
|
|
dirs[:] = [name for name in dirs if name not in ('.Trashes', '.Spotlight-V100', '.fseventsd')]
|
|
for name in files:
|
|
if not name.endswith('.metallib'):
|
|
continue
|
|
relative = (Path(directory) / name).relative_to(mount).as_posix()
|
|
template = 'System/Library/Templates/Data/'
|
|
if not prefix and relative.startswith(template):
|
|
relative = relative[len(template):]
|
|
paths.add(prefix + '/' + relative)
|
|
for path in sorted(paths):
|
|
print(path)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|