def get_pending_updates(path): data = [] changes = Update.PendingUpdatesChanges(path) if changes: if changes.get("Reboot", True) is False: for svc in changes.get("Restart", []): data.append({ 'operation': svc, 'name': Update.GetServiceDescription(svc), }) for new, op, old in changes['Packages']: if op == 'upgrade': name = '%s-%s -> %s-%s' % ( old.Name(), old.Version(), new.Name(), new.Version(), ) elif op == 'install': name = '%s-%s' % (new.Name(), new.Version()) else: name = '%s-%s' % (old.Name(), old.Version()) data.append({ 'operation': op, 'name': name, }) return data
def PrintDifferences(diffs): for type in diffs: if type == "Packages": pkg_diffs = diffs[type] for (pkg, op, old) in pkg_diffs: if op == "delete": print("Delete package {0}".format(pkg.Name()), file=sys.stderr) elif op == "install": print("Install package {0}-{1}".format(pkg.Name(), pkg.Version()), file=sys.stderr) elif op == "upgrade": print("Upgrade package {0} {1}->{2}".format(pkg.Name(), old.Version(), pkg.Version()), file=sys.stderr) else: print("Unknown package operation {0} for packge {1}-{2}".format(op, pkg.Name(), pkg.Version()), file=sys.stderr) elif type == "Restart": for svc in diffs[type]: desc = Update.GetServiceDescription(svc) if desc: print(str(desc), file=sys.stderr) else: print("Unknown service restart {0}?!".format(svc), file=sys.stderr) elif type in ("Train", "Sequence"): # Train and Sequence are a single tuple, (old, new) old, new = diffs[type] print("{0} {1} -> {2}".format(type, old, new), file=sys.stderr) elif type == "Reboot": rr = diffs[type] print("Reboot is (conditionally) {0}required".format("" if rr else "not "), file=sys.stderr) else: print("*** Unknown key {0} (value {1})".format(type, str(diffs[type])), file=sys.stderrr)
def get_pending(self, path=None): if path is None: path = self.middleware.call('notifier.get_update_location') data = [] changes = Update.PendingUpdatesChanges(path) if changes: if changes.get("Reboot", True) is False: for svc in changes.get("Restart", []): data.append({ 'operation': svc, 'name': Update.GetServiceDescription(svc), }) for new, op, old in changes['Packages']: if op == 'upgrade': name = '%s-%s -> %s-%s' % ( old.Name(), old.Version(), new.Name(), new.Version(), ) elif op == 'install': name = '%s-%s' % (new.Name(), new.Version()) else: # Its unclear why "delete" would feel out new # instead of old, sounds like a pkgtools bug? if old: name = '%s-%s' % (old.Name(), old.Version()) else: name = '%s-%s' % (new.Name(), new.Version()) data.append({ 'operation': op, 'name': name, }) return data
async def get_pending(self, path=None): """ Gets a list of packages already downloaded and ready to be applied. Each entry of the lists consists of type of operation and name of it, e.g. { "operation": "upgrade", "name": "baseos-11.0 -> baseos-11.1" } """ if path is None: path = await self.middleware.call('notifier.get_update_location') data = [] try: changes = await self.middleware.run_in_thread( Update.PendingUpdatesChanges, path) except ( UpdateIncompleteCacheException, UpdateInvalidCacheException, UpdateBusyCacheException, ): changes = [] if changes: if changes.get("Reboot", True) is False: for svc in changes.get("Restart", []): data.append({ 'operation': svc, 'name': Update.GetServiceDescription(svc), }) for new, op, old in changes['Packages']: if op == 'upgrade': name = '%s-%s -> %s-%s' % ( old.Name(), old.Version(), new.Name(), new.Version(), ) elif op == 'install': name = '%s-%s' % (new.Name(), new.Version()) else: # Its unclear why "delete" would feel out new # instead of old, sounds like a pkgtools bug? if old: name = '%s-%s' % (old.Name(), old.Version()) else: name = '%s-%s' % (new.Name(), new.Version()) data.append({ 'operation': op, 'name': name, }) return data
def get_pending_in_path(self, path): data = [] try: changes = Update.PendingUpdatesChanges(path) except ( UpdateIncompleteCacheException, UpdateInvalidCacheException, UpdateBusyCacheException, ): changes = [] if changes: if changes.get("Reboot", True) is False: for svc in changes.get("Restart", []): data.append({ 'operation': svc, 'name': Update.GetServiceDescription(svc), }) for new, op, old in changes['Packages']: if op == 'upgrade': name = '%s-%s -> %s-%s' % ( old.Name(), old.Version(), new.Name(), new.Version(), ) elif op == 'install': name = '%s-%s' % (new.Name(), new.Version()) else: # Its unclear why "delete" would feel out new # instead of old, sounds like a pkgtools bug? if old: name = '%s-%s' % (old.Name(), old.Version()) else: name = '%s-%s' % (new.Name(), new.Version()) data.append({ 'operation': op, 'name': name, }) return data
def PrintDifferences(diffs): for type in diffs: if type == "Packages": pkg_diffs = diffs[type] for (pkg, op, old) in pkg_diffs: if op == "delete": print("Delete package %s" % pkg.Name(), file=sys.stderr) elif op == "install": print("Install package %s-%s" % (pkg.Name(), pkg.Version()), file=sys.stderr) elif op == "upgrade": print("Upgrade package %s %s->%s" % (pkg.Name(), old.Version(), pkg.Version()), file=sys.stderr) else: print("Unknown package operation %s for packge %s-%s" % (op, pkg.Name(), pkg.Version()), file=sys.stderr) elif type == "Restart": for svc in diffs[type]: desc = Update.GetServiceDescription(svc) if desc: print("%s" % desc) else: print("Unknown service restart %s?!" % svc) elif type in ("Train", "Sequence"): # Train and Sequence are a single tuple, (old, new) old, new = diffs[type] print("%s %s -> %s" % (type, old, new), file=sys.stderr) elif type == "Reboot": rr = diffs[type] print("Reboot is (conditionally) %srequired" % ("" if rr else "not "), file=sys.stderr) else: print("*** Unknown key %s (value %s)" % (type, str(diffs[type])), file=sys.stderrr)