def init_with_sucatalog(sucatalog, pkg_re = "^.*/XProtectPlistConfigData.*\.pkg$"): meta = None data = None pkg_url = None u = NSURL.URLWithString_(sucatalog) d = NSDictionary.dictionaryWithContentsOfURL_(u) if not d: raise Exception("Invalid CatalogURL.", sucatalog) for k, v in d["Products"].items(): for package in v["Packages"]: r = re.compile(pkg_re) if r.findall(package["URL"]) != []: pkg_url = package["URL"] if not pkg_url: raise Exception("Package not found.", sucatalog, pkg_name) tmp_t = "%f" % time.time() tmp_pkg = "/tmp/xplist_%s.pkg" % tmp_t tmp_dir = "/tmp/xplist_%s" % tmp_t tmp_tar = "/tmp/xplist_%s/Payload" % tmp_t cmds = [ "/usr/bin/curl -s -o '%s' '%s'" %(tmp_pkg, pkg_url), "/usr/sbin/pkgutil --expand '%s' '%s'" %(tmp_pkg, tmp_dir), "/usr/bin/tar xf '%s' -C '%s' -s '|.*/||' --include '*.plist'" %(tmp_tar, tmp_dir) ] for cmd in cmds: retcode = os.system(cmd) if retcode != 0: raise Exception("Error processing package.", pkg_url, retcode, cmd) fmeta = "%s/XProtect.meta.plist" % tmp_dir fdata = "%s/XProtect.plist" % tmp_dir if os.path.exists(fmeta) and os.path.exists(fdata): meta, data = init_with_files(fmeta, fdata) return meta, data, pkg_url