Skip to content

Instantly share code, notes, and snippets.

@Honestpuck
Created June 6, 2020 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Honestpuck/f481d1e9fc2f4d34436df9453cf00c14 to your computer and use it in GitHub Desktop.
Save Honestpuck/f481d1e9fc2f4d34436df9453cf00c14 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
from os import path
import plistlib
import requests
import xml.etree.ElementTree as ET
plist = path.expanduser('~/Library/Preferences/JPCImporter.plist')
fp = open(plist, 'rb')
prefs = plistlib.load(fp)
base = prefs['url'] + '/JSSResource/'
auth = (prefs['user'], prefs['password'])
hdrs = {'Accept': 'application/json'}
for line in sys.stdin:
print('Doing %s' % line)
parts = line.rstrip().split('\t')
url = base + 'packages/id/' + parts[0]
# sanity check
ret = requests.get(url, auth=auth, headers=hdrs)
if ret.status_code != 200:
print("Failed to get %s" % line)
continue
if ret.json()['package']['name'] != parts[1]:
print("Sanity 1 fail %s %s %s" %
(line, ret.json()['package']['name'], parts[1]))
continue
ret = requests.delete(url, auth=auth)
if ret.status_code != 200:
print("Failed to delete %s" % line)
continue
root = ET.fromstring(ret.text)
if root.findtext('id') == parts[1]:
print("Failed delete sanity %s" % line)
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment