Skip to content

Commit e3d26f7

Browse files
committed
osenum: Add more logging
Signed-off-by: Hector Martin <[email protected]>
1 parent 34135ad commit e3d26f7

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

src/diskutil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ def __init__(self):
2121
self.verbose = "-v" in sys.argv
2222

2323
def action(self, *args, verbose=False):
24-
logging.info(f"run: diskutil {args!r}")
24+
logging.debug(f"run: diskutil {args!r}")
2525
subprocess.run(["diskutil"] + list(args), check=True, capture_output=(not self.verbose))
2626

2727
def get(self, *args):
28-
logging.info(f"get: diskutil {args!r}")
28+
logging.debug(f"get: diskutil {args!r}")
2929
result = subprocess.run(["diskutil"] + list(args),
3030
stdout=subprocess.PIPE, check=True)
3131
return plistlib.loads(result.stdout)

src/osenum.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: MIT
2-
import os, os.path, plistlib, subprocess
2+
import os, os.path, plistlib, subprocess, logging
33
from dataclasses import dataclass
44

55
UUID_SROS = "3D3287DE-280D-4619-AAAB-D97469CA9C71"
@@ -49,6 +49,7 @@ def __init__(self, sysinfo, dutil, sysdsk):
4949
self.sysdsk = sysdsk
5050

5151
def collect(self, parts):
52+
logging.info("OSEnum.collect()")
5253
for p in parts:
5354
p.os = []
5455
if p.type == "Apple_APFS_Recovery":
@@ -57,6 +58,7 @@ def collect(self, parts):
5758
self.collect_part(p)
5859

5960
def collect_recovery(self, part):
61+
logging.info(f"OSEnum.collect_recovery(part={part.name})")
6062
recs = []
6163

6264
for volume in part.container["Volumes"]:
@@ -66,14 +68,19 @@ def collect_recovery(self, part):
6668
if len(recs) != 1:
6769
return
6870

69-
part.os.append(OSInfo(partition=part, vgid=UUID_SROS,
70-
rec_vgid=recs[0]["APFSVolumeUUID"],
71-
version=self.sysinfo.sfr_ver))
71+
os = OSInfo(partition=part, vgid=UUID_SROS,
72+
rec_vgid=recs[0]["APFSVolumeUUID"],
73+
version=self.sysinfo.sfr_ver)
74+
logging.info(f" Found SROS: {os}")
75+
part.os.append(os)
7276
if self.sysinfo.fsfr_ver:
73-
part.os.append(OSInfo(partition=part, vgid=UUID_FROS,
74-
version=self.sysinfo.fsfr_ver))
77+
os = OSInfo(partition=part, vgid=UUID_FROS,
78+
version=self.sysinfo.fsfr_ver)
79+
logging.info(f" Found FROS: {os}")
80+
part.os.append(os)
7581

7682
def collect_part(self, part):
83+
logging.info(f"OSEnum.collect_part(part={part.name})")
7784
if part.container is None:
7885
return
7986

@@ -92,25 +99,31 @@ def collect_part(self, part):
9299
for role in ("Preboot", "Recovery"):
93100
vols = by_role.get((role,), None)
94101
if not vols:
102+
logging.info(f" No {role} volume")
95103
return
96104
elif len(vols) > 1:
105+
logging.info(f" Multiple {role} volumes ({vols})")
97106
return
98107
volumes[role] = vols[0]
99108

100109
for vg in ct["VolumeGroups"]:
101110
data = [i for i in vg["Volumes"] if i["Role"] == "Data"]
102111
system = [i for i in vg["Volumes"] if i["Role"] == "System"]
103112
if len(data) != 1 or len(system) != 1:
113+
logging.info(f" Weird VG: {vg['Volumes']}")
104114
continue
105115

106116
volumes["Data"] = by_device[data[0]["DeviceIdentifier"]]
107117
volumes["System"] = by_device[system[0]["DeviceIdentifier"]]
108118
vgid = vg["APFSVolumeGroupUUID"]
109-
part.os.append(self.collect_os(part, volumes, vgid))
119+
os = self.collect_os(part, volumes, vgid)
120+
logging.info(f" Found {os}")
121+
part.os.append(os)
110122

111123
return part.os
112124

113125
def collect_os(self, part, volumes, vgid):
126+
logging.info(f"OSEnum.collect_os(part={part.name}, vgid={vgid})")
114127
mounts = {}
115128

116129
for role in ("Preboot", "Recovery", "System"):
@@ -148,6 +161,7 @@ def collect_os(self, part, volumes, vgid):
148161
try:
149162
bps = self.bputil("-d", "-v", vgid)
150163
except subprocess.CalledProcessError:
164+
logging.info(f" bputil failed")
151165
return osi
152166

153167
osi.bp = {}
@@ -158,6 +172,7 @@ def collect_os(self, part, volumes, vgid):
158172
if val == "absent":
159173
val = None
160174
osi.bp[k] = val
175+
logging.info(f" BootPolicy[{k}] = {val}")
161176

162177
if coih := osi.bp.get("coih", None):
163178
fuos_path = os.path.join(mounts["Preboot"], vgid, "boot",
@@ -167,6 +182,7 @@ def collect_os(self, part, volumes, vgid):
167182
fuos = open(fuos_path, "rb").read()
168183
if b"##m1n1_ver##" in fuos:
169184
osi.m1n1_ver = fuos.split(b"##m1n1_ver##")[1].split(b"\0")[0].decode("ascii")
185+
logging.info(f" m1n1 version found: {osi.m1n1_ver}")
170186

171187
return osi
172188

0 commit comments

Comments
 (0)