-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathMunkiPkginfoReceiptsEditor.py
61 lines (48 loc) · 1.9 KB
/
MunkiPkginfoReceiptsEditor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/local/autopkg/python
from __future__ import absolute_import
from autopkglib import Processor, ProcessorError
from plistlib import readPlist, writePlist
__all__ = ["MunkiPkginfoReceiptsEditor"]
class MunkiPkginfoReceiptsEditor(Processor):
'''Modifies the receipts key in a Munki pkginfo.'''
input_variables = {
'pkginfo_repo_path': {
'required': True,
'description': 'The repo path where the pkginfo was written.',
},
'pkg_ids_set_optional_true': {
'required': True,
'description': 'Array of package IDs to turn optional for Munki',
},
}
output_variables = {
}
description = __doc__
def main(self):
if len(self.env['pkginfo_repo_path']) < 1:
self.output('empty pkginfo path')
return
pkginfo = readPlist(self.env['pkginfo_repo_path'])
receipts_modified = []
if 'receipts' in pkginfo.keys():
for i, receipt in enumerate(pkginfo['receipts']):
# made optional any pkginfos
if receipt['packageid'] in self.env[
'pkg_ids_set_optional_true']:
pkginfo['receipts'][i]['optional'] = True
self.output(
'Setting package ID %s as optional' %
receipt['packageid'])
receipts_modified.append(receipt['packageid'])
else:
raise ProcessorError('pkginfo does not contain receipts key')
if len(receipts_modified) > 0:
self.output(
'Writing pkginfo to %s' %
self.env['pkginfo_repo_path'])
writePlist(pkginfo, self.env['pkginfo_repo_path'])
else:
self.output('No receipts modified, not writing pkginfo')
if __name__ == '__main__':
processor = MunkiPkginfoReceiptsEditor()
processor.execute_shell()