Skip to content

Commit 8fc7d8b

Browse files
Merge pull request #101 from salopensource/pending_from_prefs
Read pending updates from the cache preference if present
2 parents 266b64b + 91f8af7 commit 8fc7d8b

File tree

5 files changed

+53
-7
lines changed

5 files changed

+53
-7
lines changed

luggage/luggage.make

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,17 +340,22 @@ ${PACKAGE_PLIST}: ${PLIST_PATH}
340340

341341
define PYTHON_PLISTER
342342
import plistlib
343-
component = plistlib.readPlist('${SCRATCH_D}/luggage.pkg.component.plist')
343+
file_name = '${SCRATCH_D}/luggage.pkg.component.plist'
344+
with open(file_name, 'rb') as infile:
345+
component = plistlib.load(infile)
346+
344347
for payload in component:
345348
if payload.get('BundleIsRelocatable'):
346349
payload['BundleIsRelocatable'] = False
347-
plistlib.writePlist(component, '${SCRATCH_D}/luggage.pkg.component.plist')
350+
351+
with open(file_name, 'wb') as outfile:
352+
plistlib.dump(component, outfile)
348353
endef
349354

350355
export PYTHON_PLISTER
351356

352357
kill_relocate:
353-
@-sudo /usr/bin/python -c "$${PYTHON_PLISTER}"
358+
@-sudo python3 -c "$${PYTHON_PLISTER}"
354359

355360
# Target directory rules
356361

payload/usr/local/sal/checkin_modules/apple_sus_checkin.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
import datetime
5+
import os
56
import pathlib
67
import platform
78
import plistlib
@@ -12,7 +13,7 @@
1213
import sal
1314

1415

15-
__version__ = "1.1.0"
16+
__version__ = "1.2.0"
1617

1718

1819
def main():
@@ -105,6 +106,11 @@ def _get_log_time(line):
105106

106107

107108
def get_pending():
109+
if os.path.exists("/Library/Preferences/com.apple.SoftwareUpdate.plist"):
110+
pending_items = get_pending_updates_from_preferences()
111+
if pending_items != None:
112+
return pending_items
113+
108114
pending_items = {}
109115
cmd = ["softwareupdate", "-l", "--no-scan"]
110116
try:
@@ -174,12 +180,45 @@ def get_pending():
174180
if "recommended" in m.group("recommended")
175181
else "FALSE",
176182
"action": _bracket_cleanup(m, "action"),
183+
"type": "Apple SUS Install",
177184
},
178185
}
179186
for m in rexp.finditer(output)
180187
}
181188

182189

190+
def get_pending_updates_from_preferences():
191+
pending = {}
192+
try:
193+
pref = plistlib.loads(
194+
pathlib.Path(
195+
"/Library/Preferences/com.apple.SoftwareUpdate.plist"
196+
).read_bytes()
197+
)
198+
except (IOError, plistlib.InvalidFileException):
199+
return None
200+
201+
recommended_updates = pref.get("RecommendedUpdates", None)
202+
if not recommended_updates:
203+
return pending
204+
205+
# Convert local time to UTC time represented as a ISO 8601 str.
206+
now = datetime.datetime.now().astimezone(datetime.timezone.utc).isoformat()
207+
for update in recommended_updates:
208+
name = update.get("Display Name")
209+
version = update.get("Display Version")
210+
item = {}
211+
item["date_managed"] = now
212+
item["status"] = "PENDING"
213+
item["data"] = {
214+
"version": version,
215+
"recommended": "TRUE",
216+
"type": "Apple SUS Install",
217+
}
218+
pending[name] = item
219+
return pending
220+
221+
183222
def _bracket_cleanup(match, key):
184223
"""Strip out [ and ] and uppercase SUS output"""
185224
return re.sub(r"[\[\]]", "", match.group(key) or "").upper()

payload/usr/local/sal/checkin_modules/machine_checkin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ def get_friendly_model(serial, udid):
127127
data[0]
128128
.get("product-name")
129129
.decode("ascii", "ignore")
130-
.strip().strip('\x00').strip()
130+
.strip()
131+
.strip("\x00")
132+
.strip()
131133
)
132134
except:
133135
pass

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
sal_python_pkg/
2-
pyobjc==7.2
2+
pyobjc==8.5
33
#urllib3==1.26.5
44
requests==2.26.0
55
MacSesh==0.3.0

sal_python_pkg/sal/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "4.2.1"
1+
__version__ = "4.3.0"

0 commit comments

Comments
 (0)