PNG  IHDR* pHYs+ IDATx]n#; cdLb Ǚ[at¤_:uP}>!Usă cag޿ ֵNu`ݼTâabO7uL&y^wFٝA"l[|ŲHLN밪4*sG3|Dv}?+y߉{OuOAt4Jj.u]Gz*҉sP'VQKbA1u\`& Af;HWj hsO;ogTu uj7S3/QzUr&wS`M$X_L7r2;aE+ώ%vikDA:dR+%KzƉo>eOth$z%: :{WwaQ:wz%4foɹE[9<]#ERINƻv溂E%P1i01 |Jvҗ&{b?9g=^wζXn/lK::90KwrюO\!ջ3uzuGv^;騢wq<Iatv09:tt~hEG`v;3@MNZD.1]L:{ծI3`L(÷ba")Y.iljCɄae#I"1 `3*Bdz>j<fU40⨬%O$3cGt]j%Fߠ_twJ;ABU8vP3uEԑwQ V:h%))LfraqX-ۿX]v-\9I gl8tzX ]ecm)-cgʒ#Uw=Wlێn(0hPP/ӨtQ“&J35 $=]r1{tLuǮ*i0_;NƝ8;-vݏr8+U-kruȕYr0RnC]*ެ(M:]gE;{]tg(#ZJ9y>utRDRMdr9㪩̞zֹb<ģ&wzJM"iI( .ꮅX)Qw:9,i좜\Ԛi7&N0:asϓc];=ΗOӣ APqz93 y $)A*kVHZwBƺnWNaby>XMN*45~ղM6Nvm;A=jֲ.~1}(9`KJ/V F9[=`~[;sRuk]rєT!)iQO)Y$V ی ۤmzWz5IM Zb )ˆC`6 rRa}qNmUfDsWuˤV{ Pݝ'=Kֳbg,UҘVz2ﴻnjNgBb{? ߮tcsͻQuxVCIY۠:(V뺕 ٥2;t`@Fo{Z9`;]wMzU~%UA蛚dI vGq\r82iu +St`cR.6U/M9IENDB`#!/usr/libexec/platform-python # SPDX-License-Identifier: LGPL-2.1+ """A simple fwupd frontend""" import sys import os import gi from gi.repository import GLib gi.require_version("Fwupd", "2.0") from gi.repository import Fwupd # pylint: disable=wrong-import-position class Progress: """Class to track the signal changes of progress events""" def __init__(self): self.device = None self.status = None self.percent = 0 self.erase = 0 def device_changed(self, new_device): """Indicate new device string to track""" if self.device != new_device: self.device = new_device print("\nUpdating %s" % self.device) def status_changed(self, percent, status): """Indicate new status string or % complete to track""" if self.status != status or self.percent != percent: for i in range(0, self.erase): sys.stdout.write("\b \b") self.status = status self.percent = percent status_str = "[" for i in range(0, 50): if i < percent / 2: status_str += "*" else: status_str += " " status_str += "] %d%% %s" % (percent, status) self.erase = len(status_str) sys.stdout.write(status_str) sys.stdout.flush() if "idle" in status: sys.stdout.write("\n") def parse_args(): """Parse arguments for this client""" import argparse parser = argparse.ArgumentParser(description="Interact with fwupd daemon") parser.add_argument( "--allow-older", action="store_true", help="Install older payloads(default False)", ) parser.add_argument( "--allow-reinstall", action="store_true", help="Reinstall payloads(default False)", ) parser.add_argument( "command", choices=["get-devices", "get-details", "install", "refresh"], help="What to do", ) parser.add_argument("cab", nargs="?", help="CAB file") parser.add_argument("deviceid", nargs="?", help="DeviceID to operate on(optional)") args = parser.parse_args() return args def refresh(client): """Uses fwupd client to refresh metadata""" remotes = client.get_remotes() client.set_user_agent_for_package("simple_client", "1.7.8") for remote in remotes: if not remote.get_enabled(): continue if remote.get_kind() != Fwupd.RemoteKind.DOWNLOAD: continue client.refresh_remote(remote) def get_devices(client): """Use fwupd client to fetch devices""" devices = client.get_devices() for item in devices: print(item.to_string()) def get_details(client, cab): """Use fwupd client to fetch details for a CAB file""" devices = client.get_details(cab, None) for device in devices: print(device.to_string()) def status_changed(client, spec, progress): # pylint: disable=unused-argument """Signal emitted by fwupd daemon indicating status changed""" progress.status_changed( client.get_percentage(), Fwupd.status_to_string(client.get_status()) ) def device_changed(client, device, progress): # pylint: disable=unused-argument """Signal emitted by fwupd daemon indicating active device changed""" progress.device_changed(device.get_name()) def install(client, cab, target, older, reinstall): """Use fwupd client to install CAB file to applicable devices""" # FWUPD_DEVICE_ID_ANY if not target: target = "*" flags = Fwupd.InstallFlags.NONE if older: flags |= Fwupd.InstallFlags.ALLOW_OLDER if reinstall: flags |= Fwupd.InstallFlags.ALLOW_REINSTALL progress = Progress() parent = super(client.__class__, client) parent.connect("device-changed", device_changed, progress) parent.connect("notify::percentage", status_changed, progress) parent.connect("notify::status", status_changed, progress) try: client.install(target, cab, flags, None) except GLib.Error as glib_err: # pylint: disable=catching-non-exception progress.status_changed(0, "idle") print("%s" % glib_err) sys.exit(1) print("\n") def check_exists(cab): """Check that CAB file exists""" if not cab: print("Need to specify payload") sys.exit(1) if not os.path.isfile(cab): print("%s doesn't exist or isn't a file" % cab) sys.exit(1) if __name__ == "__main__": ARGS = parse_args() CLIENT = Fwupd.Client() if ARGS.command == "get-devices": get_devices(CLIENT) elif ARGS.command == "get-details": check_exists(ARGS.cab) get_details(CLIENT, ARGS.cab) elif ARGS.command == "refresh": refresh(CLIENT) elif ARGS.command == "install": check_exists(ARGS.cab) install(CLIENT, ARGS.cab, ARGS.deviceid, ARGS.allow_older, ARGS.allow_reinstall)