def main(): print("Silica Compiler {0}".format(version)) ########### # Step 0: Clean up "repo" and "temp" folder ########### root = os.path.dirname(os.path.abspath(__file__)) + "/" try: shutil.rmtree(root + "repo/") except Exception: pass try: shutil.rmtree(root + "temp/") except Exception: pass ########### # Step 1: Generate folders, files, and variables needed (including temp) ########### PackageLister.CreateFolder("repo") PackageLister.CreateFolder("repo/web") PackageLister.CreateFolder("repo/depiction") PackageLister.CreateFolder("repo/depiction/web") PackageLister.CreateFolder("repo/depiction/native") PackageLister.CreateFolder("repo/depiction/native/help") PackageLister.CreateFolder("repo/pkg") PackageLister.CreateFolder("repo/assets") PackageLister.CreateFolder("repo/api") # Make sure all index.json files are generated (if using DEBs) DebianPackager.CheckForSilicaData() tweak_release = PackageLister.GetTweakRelease() repo_settings = PackageLister.GetRepoSettings() # Create folder for each tweak for tweak in tweak_release: PackageLister.CreateFolder("repo/assets/" + tweak['bundle_id']) ########### # Step 2: Copy all images ########### for package_name in PackageLister.ListDirNames(): package_bundle_id = PackageLister.DirNameToBundleID(package_name) try: shutil.copy( root + "Packages/" + package_name + "/silica_data/icon.png", root + "repo/assets/" + package_bundle_id + "/icon.png") except Exception: category = PackageLister.ResolveCategory(tweak_release, package_bundle_id) category = re.sub(r'\([^)]*\)', '', category).strip() try: shutil.copy( root + "Styles/Generic/Icon/" + category + ".png", root + "repo/assets/" + package_bundle_id + "/icon.png") except Exception: try: shutil.copy( root + "Styles/Generic/Icon/Generic.png", root + "repo/assets/" + package_bundle_id + "/icon.png") except Exception: PackageLister.ErrorReporter( "Configuration Error!", "You are missing a file at " + root + "Styles/Generic/Icon/Generic.png. Please place an icon here to be the repo's default." ) try: shutil.copy( root + "Packages/" + package_name + "/silica_data/banner.png", root + "repo/assets/" + package_bundle_id + "/banner.png") except Exception: category = PackageLister.ResolveCategory(tweak_release, package_bundle_id) category = re.sub(r'\([^)]*\)', '', category).strip() try: shutil.copy( root + "Styles/Generic/Banner/" + category + ".png", root + "repo/assets/" + package_bundle_id + "/banner.png") except Exception: try: shutil.copy( root + "Styles/Generic/Banner/Generic.png", root + "repo/assets/" + package_bundle_id + "/banner.png") except Exception: PackageLister.ErrorReporter( "Configuration Error!", "You are missing a file at " + root + "Styles/Generic/Banner/Generic.png. Please place a banner here to be the repo's default." ) try: shutil.copy( root + "Packages/" + package_name + "/silica_data/description.md", root + "repo/assets/" + package_bundle_id + "/description.md") except Exception: pass try: shutil.copytree( root + "Packages/" + package_name + "/silica_data/screenshots", root + "repo/assets/" + package_bundle_id + "/screenshot") except Exception: pass try: shutil.copy(root + "Styles/icon.png", root + "repo/CydiaIcon.png") except Exception: PackageLister.ErrorReporter( "Configuration Error!", "You are missing a file at " + root + "Styles/icon.png. " "Please add a PNG here to act as the repo's icon.") ########### # Step 3: Generate HTML depictions and copy stylesheet ########### # Copy CSS and JS over shutil.copy(root + "Styles/index.css", root + "repo/web/index.css") shutil.copy(root + "Styles/index.js", root + "repo/web/index.js") # Generate index.html index_html = DepictionGenerator.RenderIndexHTML() PackageLister.CreateFile("repo/index.html", index_html) PackageLister.CreateFile("repo/404.html", index_html) # Generate per-tweak depictions for tweak_data in tweak_release: tweak_html = DepictionGenerator.RenderPackageHTML(tweak_data) PackageLister.CreateFile( "repo/depiction/web/" + tweak_data['bundle_id'] + ".html", tweak_html) PackageLister.CreateFile("repo/CNAME", repo_settings['cname']) ########### # Step 4: Generate Sileo depictions and featured JSON ########### # Generate sileo-featured.json carousel_obj = DepictionGenerator.NativeFeaturedCarousel(tweak_release) PackageLister.CreateFile("repo/sileo-featured.json", carousel_obj) # Generate per-tweak depictions for tweak_data in tweak_release: tweak_json = DepictionGenerator.RenderPackageNative(tweak_data) PackageLister.CreateFile( "repo/depiction/native/" + tweak_data['bundle_id'] + ".json", tweak_json) help_depiction = DepictionGenerator.RenderNativeHelp(tweak_data) PackageLister.CreateFile( "repo/depiction/native/help/" + tweak_data['bundle_id'] + ".json", help_depiction) ########### # Step 5: Generate Release file from settings.json. ########### release_file = DebianPackager.CompileRelease(repo_settings) PackageLister.CreateFile("repo/Release", release_file) ########### # Step 6: Copy packages to temp ########### # You should remove .DS_Store files AFTER copying to temp. PackageLister.CreateFolder("temp") for package_name in PackageLister.ListDirNames(): bundle_id = PackageLister.DirNameToBundleID(package_name) try: shutil.copytree(root + "Packages/" + package_name, root + "temp/" + bundle_id) shutil.rmtree(root + "temp/" + bundle_id + "/silica_data") except Exception: try: shutil.rmtree(root + "temp/" + bundle_id + "/silica_data") except Exception: pass script_check = Path(root + "Packages/" + package_name + "/silica_data/scripts/") if script_check.is_dir(): shutil.copytree( root + "Packages/" + package_name + "/silica_data/scripts", root + "temp/" + bundle_id + "/DEBIAN") else: PackageLister.CreateFolder("temp/" + bundle_id + "/DEBIAN") ########### # Step 7: Generate CONTROL and DEB files and move them to repo/ ########### for tweak_data in tweak_release: control_file = DebianPackager.CompileControl(tweak_data, repo_settings) #input(); PackageLister.CreateFile( "temp/" + tweak_data['bundle_id'] + "/DEBIAN/control", control_file) DebianPackager.CreateDEB(tweak_data['bundle_id'], tweak_data['version']) shutil.copy(root + "temp/" + tweak_data['bundle_id'] + ".deb", root + "repo/pkg/" + tweak_data['bundle_id'] + ".deb") ########### # Step 8: Generate Package file and hash/sign the Release file. ########### DebianPackager.CompilePackages() DebianPackager.SignRelease() ########### # Step 9: Make API endpoints ########### PackageLister.CreateFile("repo/api/tweak_release.json", json.dumps(tweak_release)) PackageLister.CreateFile("repo/api/repo_settings.json", json.dumps(repo_settings)) PackageLister.CreateFile("repo/api/about.json", json.dumps(DepictionGenerator.SilicaAbout())) ########### # Step 10: Push to GitHub ########### shutil.rmtree(root + "temp/") # Clean-up the now-unneeded temp folder. try: if repo_settings['automatic_git'].lower() == "true": DebianPackager.PushToGit( ) # Push the repo to GitHub automatically. except Exception: pass
def CheckForSilicaData(self): """ Ensures that a silica_data file exists and if it doesn't, try to create one with as much data as we have. If there is a DEB file, it will take data from its CONTROL file. It will also auto-update the version number. If there is no DEB file, it will use the name of the folder, version 1.0.0, try to guess some dependencies, and add some placeholder data. :return: """ for folder in os.listdir(self.root + "Packages"): if folder.lower() != ".ds_store": if not os.path.isdir(self.root + "Packages/" + folder + "/silica_data"): print("It seems like the package \"" + folder + "\" is not configured. Let's set it up!") is_deb = False deb_path = "" try: for file_name in os.listdir(self.root + "Packages/" + folder): if file_name.endswith(".deb"): is_deb = True deb_path = self.root + "Packages/" + folder + "/" + file_name except Exception: PackageLister.ErrorReporter(self, "Configuration Error!", "Please put your .deb file inside of " "its own folder. The \"Packages\" directory should be made of multiple folders that each " "contain data for a single package.\n Please fix this issue and try again.") # This will be the default scaffolding for our package. Eventually I'll neuter it to only be the # essential elements; it's also kinda a reference to me. output = { "bundle_id": "co.shuga.silica.unknown", "name": "Unknown Package", "version": "1.0.0", "tagline": "An unknown package.", "homepage": "https://shuga.co/", "developer": { "name": "Unknown", "email": "*****@*****.**" }, "maintainer": { "name": "Unknown", "email": "*****@*****.**" }, "section": "Themes", "works_min": "8.0", "works_max": "13.0", "featured": "false" } if is_deb: print("Extracting data from DEB...") deb = Dpkg(deb_path) output['name'] = deb.headers['Name'] output['bundle_id'] = deb.headers['Package'] try: output['tagline'] = deb.headers['Description'] except Exception: output['tagline'] = input("What is a brief description of the package? ") try: output['homepage'] = deb.headers['Homepage'] except Exception: pass try: remove_email_regex = re.compile('<.*?>') output['developer']['name'] = remove_email_regex.sub("", deb.headers['Author']) except Exception: output['developer']['name'] = input("Who originally made this package? This may be" " your name. ") output['developer']['email'] = input("What is the original author's email address? ") try: remove_email_regex = re.compile('<.*?>') output['maintainer']['name'] = remove_email_regex.sub("", deb.headers['Maintainer']) except Exception: output['maintainer']['name'] = input("Who maintains this package now?" " This is likely your name. ") output['maintainer']['email'] = input("What is the maintainer's email address? ") try: output['sponsor']['name'] = remove_email_regex.sub("", deb.headers['Sponsor']) except Exception: pass try: output['dependencies'] = deb.headers['Depends'] except Exception: pass try: output['section'] = deb.headers['Section'] except Exception: pass try: output['version'] = deb.headers['Version'] except Exception: output['version'] = "1.0.0" try: output['conflicts'] = deb.headers['Conflicts'] except Exception: pass try: output['replaces'] = deb.headers['Replaces'] except Exception: pass try: output['provides'] = deb.headers['Provides'] except Exception: pass try: output['build_depends'] = deb.headers['Build-Depends'] except Exception: pass try: output['recommends'] = deb.headers['Recommends'] except Exception: pass try: output['suggests'] = deb.headers['Suggests'] except Exception: pass try: output['enhances'] = deb.headers['Enhances'] except Exception: pass try: output['breaks'] = deb.headers['Breaks'] except Exception: pass try: output['tags'] = deb.headers['Tag'] except Exception: pass try: output['suggests'] = deb.headers['Suggests'] except Exception: pass # These still need data. output['works_min'] = input("What is the lowest iOS version the package works on? ") output['works_max'] = input("What is the highest iOS version the package works on? ") output['featured'] = input("Should this package be featured on your repo? (true/false) ") set_tint = input("What would you like this package's tint color to be? To keep it at" " the default, leave this blank: ") if set_tint != "": output['tint'] = set_tint print("All done! Please look over the generated \"index.json\" file and consider populating the" " \"silica_data\" folder with a description, screenshots, and an icon.") # Extract Control file and scripts from DEB DpkgPy.control_extract(self, deb_path, self.root + "Packages/" + folder + "/silica_data/scripts/") # Remove the Control; it's not needed. os.remove(self.root + "Packages/" + folder + "/silica_data/scripts/Control") if not os.listdir(self.root + "Packages/" + folder + "/silica_data/scripts/"): os.rmdir(self.root + "Packages/" + folder + "/silica_data/scripts/") else: print("Estimating dependencies...") # Use the filesystem to see if Zeppelin, Anemone, LockGlyph, XenHTML, and similar. # If one of these are found, set it as a dependency. # If multiple of these are found, use a hierarchy system, with Anemone as the highest priority, # for determining the category. output['dependencies'] = "" output['section'] = "Themes" if os.path.isdir(self.root + "Packages/" + folder + "/Library/Zeppelin"): output['section'] = "Themes (Zeppelin)" output['dependencies'] += "com.alexzielenski.zeppelin, " if os.path.isdir(self.root + "Packages/" + folder + "/Library/Application Support/LockGlyph"): output['section'] = "Themes (LockGlyph)" output['dependencies'] += "com.evilgoldfish.lockglypgh, " if os.path.isdir(self.root + "Packages/" + folder + "/var/mobile/Library/iWidgets"): output['section'] = "Widgets" output['dependencies'] += "com.matchstic.xenhtml, " if os.path.isdir(self.root + "Packages/" + folder + "/Library/Wallpaper"): output['section'] = "Wallpapers" if os.path.isdir(self.root + "Packages/" + folder + "/Library/Themes"): output['section'] = "Themes" output['dependencies'] += "com.anemonetheming.anemone, " if output['dependencies'] != "": output['dependencies'] = output['dependencies'][:-2] repo_settings = PackageLister.GetRepoSettings(self) # Ask for name output['name'] = input("What should we name this package? ") # Automatically generate a bundle ID from the package name. domain_breakup = repo_settings['cname'].split(".")[::-1] only_alpha_regex = re.compile('[^a-zA-Z]') machine_safe_name = only_alpha_regex.sub("", output['name']).lower() output['bundle_id'] = ".".join(str(x) for x in domain_breakup) + "." + machine_safe_name output['tagline'] = input("What is a brief description of the package? ") output['homepage'] = "https://" + repo_settings['cname'] # I could potentially default this to what is in settings.json but attribution may be an issue. output['developer']['name'] = input("Who made this package? This is likely your name. ") output['developer']['email'] = input("What is the author's email address? ") output['works_min'] = input("What is the lowest iOS version the package works on? ") output['works_max'] = input("What is the highest iOS version the package works on? ") output['featured'] = input("Should this package be featured on your repo? (true/false) ") PackageLister.CreateFolder(self, "Packages/" + folder + "/silica_data/") PackageLister.CreateFile(self, "Packages/" + folder + "/silica_data/index.json", json.dumps(output))