Last active
February 19, 2020 22:06
-
-
Save wjt/5fff5946a9cc451abb26dc3590f9275d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import json | |
| import glob | |
| GTH = "eos-folder-games-to-hack.directory" | |
| LTC = "eos-folder-learn-to-code.directory" | |
| LTC_APPS = [ | |
| "edu.mit.Scratch.desktop", | |
| "org.laptop.TurtleArtActivity.desktop", | |
| ] | |
| YE_OLDE_LIBREOFFICE = [ | |
| "org.libreoffice.LibreOffice-writer.desktop", | |
| "org.libreoffice.LibreOffice-calc.desktop", | |
| "org.libreoffice.LibreOffice-impress.desktop", | |
| ] | |
| MEDIA = "eos-folder-media.directory" | |
| TOOLS = "eos-folder-tools.directory" | |
| MEDIA_APPS = [ | |
| "org.pitivi.Pitivi.desktop", | |
| "org.blender.Blender.desktop", | |
| ] | |
| MEDIA_AFTER = "org.inkscape.Inkscape.desktop" | |
| def wrangle(grid): | |
| def add_to(group_id, apps, after): | |
| try: | |
| group = grid[group_id] | |
| except KeyError: | |
| group = grid[group_id] = [] | |
| for app in reversed(apps): | |
| i = group.index(after) if after else 0 | |
| if app not in group: | |
| group.insert(i + 1, app) | |
| add_to("desktop", [LTC], GTH) | |
| add_to(LTC, LTC_APPS, None) | |
| add_to(MEDIA if MEDIA in grid else TOOLS, MEDIA_APPS, MEDIA_AFTER) | |
| grid["eos-folder-games-to-hack.directory"].sort(key=str.lower) | |
| for vs in grid.values(): | |
| for desktop_id in YE_OLDE_LIBREOFFICE: | |
| if desktop_id in vs: | |
| i = vs.index(desktop_id) | |
| vs[i:i+1] = [desktop_id.replace("-", ".")] | |
| def mangle(filename): | |
| with open(filename, "r") as f: | |
| grid = json.load(f) | |
| try: | |
| wrangle(grid) | |
| except: | |
| print(filename) | |
| raise | |
| with open(filename, "w") as f: | |
| json.dump(grid, f, indent=2) | |
| f.write("\n") | |
| if __name__ == "__main__": | |
| for x in glob.glob("data/settings/*.in"): | |
| mangle(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment