-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathRemoveItemFromManifests.py
42 lines (29 loc) · 1.48 KB
/
RemoveItemFromManifests.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
#!/usr/bin/python
import os
import plistlib
# Change this to match your actual Munki repo path
manifest_path='/Library/WebServer/Documents/munki_repo/manifests'
# Change this to the name of the item you want to remove (case and spaces matter)
item_to_remove='Name of Offending Item'
removal_type='managed_installs'
# Loop through the manifests directory
for root, dirs, files in os.walk(manifest_path):
for file in files:
# Get the full path to the file
file_path=os.path.join(root,file)
# Omit files that start with a period
if os.path.exists(file_path) and file[0]!=".":
# Even then, it's possible some files in the directory (and subdirectories) may not be actual manifests, so let's just TRY to read the plist
try:
# Read the contents of the manifest
file_contents=plistlib.readPlist(file_path)
except:
# If the contents can't be read with plistlib, say so
print "%s is not a valid .plist" % file
# If the offending item is in the removal type...
if removal_type in file_contents and item_to_remove in file_contents[removal_type]:
print 'Removing %s from %s' % (file_contents[removal_type], file)
# Remove the offending item
file_contents[removal_type].remove(item_to_remove)
# Write the changes back to the manifest
plistlib.writePlist(file_contents,file_path)