Update to Update to My Flatpak CLI Shortcut Proof of Concept

Well, it’s a bit silly, but I got nerd-sniped by how it was taking a little over six seconds to regenerate my Flatpak CLI wrappers with the shell script version I just announced yesterday, so I rewrote it in Python.

(Still the same GitHub Gist URL)

The new version completes basically instantly after the split-second pause to start the Python interpreter, thanks to using PyGObject to go straight to libflatpak so it doesn’t have to launch a whole new copy of flatpak info to query each package.

Other enhancements the rewrite brought are:

  1. Flatpak info parsing is now done using Glib.KeyFile, which is a proper parser for the format
  2. Command lines are now extracted from the .desktop files using Gio.DesktopAppInfo, but with a forced fallback to the old flatpak run generator if the upstream devs omitted --file-forwarding to ensure that things like ScummVM don’t regress in their ability to invoke them with command-line arguments.
  3. EXTRA_CMDS now takes a list of commands, so you can expose more than one secondary command from each package.
  4. CMD_REMAPPINGS Now maps from flatpak package IDs rather than internal command names so that there’s no risk of collisions if the undesired name is undesired because it’s something generic like launcher.
  5. The template for wrapper scripts is now using a proper multi-line string for easy auditing and editing.
  6. The script checks if BIN_DIR is in your path and, if not, warns you that you’ll need to add it, which has the side benefit of telling you what BIN_DIR is set to without needing to read the source.
  7. There’s now basic collision resolution where the first Flatpak package to claim a name wins and a message is printed asking you to add an entry to CMD_REMAPPINGS to resolve the problem.
  8. There’s now collision detection where, whether or not this script is responsible for both of them, a warning will be printed indicating which command from which package is colliding and whether your PATH will favour the Flatpak version or the external version.

Yeah, aside from the lack of manpages (which I can’t solve if they’re just not in the package), the sledgehammer-y approach of just expecting that it’s allowed full freedom to blow away all files inside the BIN_DIR it creates and manages, and the fact that you have to edit constants in the source code rather than an external config file, this is now about as perfect as I can think to make it… maybe I’ll rewrite it in Rust next time the mood hits me.

UPDATE: I’ll also need to add autodetection for when a Flatpak is exporting secondary launchers so EXTRA_CMDS is only necessary for things like audtool and mednafen that are present but not exported.

CC BY-SA 4.0 Update to Update to My Flatpak CLI Shortcut Proof of Concept by Stephan Sokolow is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

This entry was posted in Geek Stuff. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution under the same terms as the associated post.

All comments are moderated. If your comment is generic enough to apply to any post, it will be assumed to be spam. Borderline comments will have their URL field erased before being approved.