Skip to content

Instantly share code, notes, and snippets.

@dbnicholson
Last active May 11, 2020 19:22
Show Gist options
  • Save dbnicholson/fdc2745fa29d05097b7d76e3de310133 to your computer and use it in GitHub Desktop.
Save dbnicholson/fdc2745fa29d05097b7d76e3de310133 to your computer and use it in GitHub Desktop.
Dump metadata for all flatpaks from all remotes
#!/usr/bin/env python3
from argparse import ArgumentParser
import gi
import os
gi.require_version('Flatpak', '1.0')
from gi.repository import Flatpak # noqa: E402
def dump_remote_metadata(installation, remote, directory):
print('Fetching metadata for remote', remote)
for ref in installation.list_remote_refs_sync(remote):
metadata_bytes = ref.get_metadata()
metadata_dir = os.path.join(directory, remote, ref.format_ref())
metadata_path = os.path.join(metadata_dir, 'metadata')
os.makedirs(metadata_dir, exist_ok=True)
print('Writing', metadata_path)
with open(metadata_path, 'wb') as f:
f.write(metadata_bytes.get_data())
aparser = ArgumentParser('Dump metadata for all flatpaks')
aparser.add_argument('-d', '--directory', default='',
help='output directory')
aparser.set_defaults(system=True)
aparser.add_argument('--user', dest='system', action='store_false',
help='work on user installation')
aparser.add_argument('--system', action='store_true',
help='work on system installation')
args = aparser.parse_args()
if args.system:
installation = Flatpak.Installation.new_system()
else:
installation = Flatpak.Installation.new_user()
for remote in installation.list_remotes():
if remote.get_disabled():
continue
dump_remote_metadata(installation, remote.get_name(), args.directory)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment