#!/usr/bin/env python3 import json import os import subprocess import pathlib updir = "CustomUploaders" control_format = """Package: dev.somnium.{0}-uploadconfig Name: {1} Config Depends: dev.somnium.notatio Version: 1.0.0 Architecture: iphoneos-arm Description: {2} upload config for the Notatio upload tweak. Maintainer: Somnium Tweaks Author: Somnium Tweaks Section: Notatio Uploaders """ files = [f for f in os.listdir(updir) if os.path.isfile("{0}/{1}".format(updir, f))] files2 = [f for f in files if f.endswith(".sxcu")] for fname in files2: dns = fname[:-5] print("Forward DNS: " + dns) revdns1 = dns.split('.') revdns1.reverse() revdns = '.'.join(revdns1) print("Reverse DNS: " + revdns) with open("{0}/{1}".format(updir, fname), "r", encoding="utf-8-sig") as f: rawjson = f.read() conv = json.loads(rawjson) print("Loaded json") if "FileFormName" in conv.keys(): try: conv.pop("Version") except KeyError: pass try: conv.pop("Name") except KeyError: pass try: conv.pop("DestinationType") except KeyError: pass pathlib.Path("pkgs/{0}-uploadconfig/DEBIAN".format(revdns)).mkdir(parents=True, exist_ok=True) pathlib.Path("pkgs/{0}-uploadconfig/Library/Application Support/Notatio".format(revdns)).mkdir(parents=True, exist_ok=True) with open("pkgs/{0}-uploadconfig/DEBIAN/control".format(revdns), "w+") as f: f.write(control_format.format(revdns, dns, dns)) print("Created DEBIAN/control") with open("/tmp/{0}".format(revdns), "w+") as f: f.write(json.dumps(conv)) print("Dumped json to /tmp/{0}".format(revdns)) subprocess.check_call(['json2plist', '-i', '/tmp/{0}'.format(revdns), '-o', 'pkgs/{0}-uploadconfig/Library/Application Support/Notatio/{1}.plist'.format(revdns, dns)]) print("Called json2plist") subprocess.check_call(['dpkg-deb', '-b', 'pkgs/{0}-uploadconfig']) print("Called dpkg-deb") else: print("Skipped {0}".format(fname))