def test_large_binary_plist(self): plist_file = os.path.join(cur_dir, "large.plist") p = PlistInfo.from_file(plist_file) self.assertEqual(p.ref_size, 2) buf = p.to_binary() p2 = PlistInfo(buf) self.assertEqual(p2.ref_size, 2) self.assertEqual(dict(p), dict(p2))
def test_xml_plist(self): plist_file = os.path.join(cur_dir, "Info.xml") p = PlistInfo.from_file(plist_file) self.check_plist(p) xml_file = "temp.xml" p.to_xml_file(xml_file) self.assertTrue(os.path.isfile(xml_file)) self.addCleanup(os.remove, xml_file) new_p = PlistInfo.from_file(xml_file) self.assertEqual(new_p, p)
def test_binary_file(self): plist_file = os.path.join(cur_dir, "Info.plist") p = PlistInfo.from_file(plist_file) self.assertEqual(p.ref_size, 1) self.check_plist(p) temp_file = "temp.plist" p.to_binary_file(temp_file) self.assertTrue(os.path.isfile(temp_file)) self.addCleanup(os.remove, temp_file) new_p = PlistInfo.from_file(temp_file) self.assertEqual(new_p.ref_size, 1) self.assertEqual(new_p, p)
def test_plist(self): file_path = os.path.join(cur_dir, "Info.plist") cmdline = "%s -m gplist %s" % (py_exe, file_path) with os.popen(cmdline) as fd: content = fd.read() p = json.loads(content) p2 = PlistInfo.from_file(file_path) self.assertEqual(p, p2)
def test_with_biplist(self): plist_file = os.path.join(cur_dir, "large.plist") p = PlistInfo.from_file(plist_file) p2 = biplist.readPlist(plist_file) self.assertEqual(p, p2) p3 = biplist.readPlistFromString(p.to_binary()) self.assertEqual(p, p3)
def test_dict_plist(self): data = {"foo": {"a": 1}} p = PlistInfo(data) xml_file = "dict_plist.xml" p.to_xml_file(xml_file) self.assertTrue(os.path.isfile(xml_file)) self.addCleanup(os.remove, xml_file) new_p = PlistInfo.from_file(xml_file) self.assertEqual(new_p, data) bin_file = "dict.plist" p.to_binary_file(bin_file) self.addCleanup(os.remove, bin_file) p2 = PlistInfo.from_file(bin_file) self.assertEqual(p, p2)
def test_manipulate_property(self): plist_file = os.path.join(cur_dir, "Info.xml") p = PlistInfo.from_file(plist_file) p.add_property({"a": 1}, "foo") self.assertRaises(ValueError, p.add_property, 1, "foo") self.assertEqual(p["foo"], {"a": 1}) p.update_property(2, "foo", "a") self.assertEqual(p["foo"]["a"], 2) p.remove_property("foo", "a") self.assertEqual(p["foo"], {}) self.assertRaises(ValueError, p.remove_property, "xx") self.assertRaises(ValueError, p.update_property, "xx") with self.assertRaises(ValueError) as ctx: p.add_property(1, "foo", "b", "c") e = ctx.exception self.assertIn("b/c", e.args[0])
def main(): parser = argparse.ArgumentParser() parser.add_argument("file", help="plist or mobile provision file path") parser.add_argument("--cert", action="store_true", help="output certificate information of mobile provision file") parser.add_argument("--has-udid", dest="udid", help="check whether provision contains the target udid") args = parser.parse_args(sys.argv[1:]) file_path = os.path.abspath(args.file) if not os.path.isfile(file_path): print("file=%s is not a valid file" % file_path) sys.exit(1) try: p = PlistInfo.from_file(file_path) except ValueError: m = MobileProvision.from_file(file_path) if args.cert: cert_info = [] for cert in m.certs: cert_info.append({ "serial": cert.serial, "name": cert.common_name, "sha1": cert.sha1}) json.dump(cert_info, sys.stdout, indent=2, cls=PlistEncoder) elif args.udid: if m.has_udid(args.udid): print("yes") else: print("no") sys.exit(1) else: json.dump(m, sys.stdout, indent=2, cls=PlistEncoder) else: if any([args.cert, args.udid]): print("file=%s is not recognized as mobile provision file" % file_path) sys.exit(1) json.dump(p, sys.stdout, indent=2, cls=PlistEncoder)
def test_ipa(self): app_path = os.path.join(cur_dir, "FooApp.ipa") p = PlistInfo.from_app(app_path) self.check_plist(p)