def run(self): """run the dialog, and if reload was pressed run cache update""" res = self.dialog.run() self.dialog.hide() if res == Gtk.ResponseType.APPLY: self._pktask = packagekit.Task() self._pdia = ProgressDialog(self.parent) self._loop = GObject.MainLoop() self._pdia.show_all() self.parent.set_sensitive(False) try: self._pktask.refresh_cache_async( False, # force None, # GCancellable self.on_pktask_progress, (None, ), # user data self.on_pktask_finish, (None, )) except Exception as e: print("Error while requesting cache refresh: {}".format(e)) self._loop.run() self._pdia.hide() self.parent.set_sensitive(True) return res
def update_cache(self): self.stack.set_visible_child_name("refresh_page") self.spinner.start() task = packagekit.Task() task.refresh_cache_async(True, Gio.Cancellable(), self.on_cache_update_progress, (None, ), self.on_cache_update_finished, (None, ))
def _get_package_details(self, pkgs): pkgsId = [] for pkg in pkgs: if (not (pkg.get_id() in pkgsId)): pkgsId.append(pkg.get_id()) try: task = packagekit.Task() result = task.get_details_sync(pkgsId, None, self._progress_pcb, None) except GObject.GError: e = sys.exc_info()[1] return None pkgsDetails = result.get_details_array() if not pkgsDetails: return None resultDetails = [] currVal = 0 for pkg in pkgs: for details in pkgsDetails: if (pkg.get_id() == details.get_property("package-id")): resultDetails.append((pkg, details)) break if (len(resultDetails) == currVal): resultDetails.append((pkg, None)) currVal = currVal + 1 return resultDetails
def install_multiple(self, apps, iconnames, addons_install=[], addons_remove=[], metadatas=None): pkgnames = [app.pkgname for app in apps] appnames = [app.appname for app in apps] # keep track of pkg, app and icon for setting them as meta self.new_pkgname = pkgnames[0] self.new_appname = appnames[0] self.new_iconname = iconnames[0] # temporary hack pkgnames = self._fix_pkgnames(pkgnames) LOG.debug("Installing multiple packages: " + str(pkgnames)) task = packagekit.Task() task.install_packages_async( pkgnames, None, # cancellable self._on_progress_changed, None, # progress data self._on_install_ready, # GAsyncReadyCallback task # ready data ) self.emit("transaction-started", pkgnames[0], appnames[0], 0, TransactionTypes.INSTALL)
def remove_multiple(self, apps, iconnames, addons_install=[], addons_remove=[], metadatas=None): pkgnames = [app.pkgname for app in apps] appnames = [app.appname for app in apps] # keep track of pkg, app and icon for setting them as meta self.new_pkgname = pkgnames[0] self.new_appname = appnames[0] self.new_iconname = iconnames[0] # temporary hack pkgnames = self._fix_pkgnames(pkgnames) task = packagekit.Task() task.remove_packages_async( pkgnames, False, # allow deps True, # autoremove None, # cancellable self._on_progress_changed, None, # progress data self._on_remove_ready, # callback ready task # callback data ) self.emit("transaction-started", pkgnames[0], appnames[0], 0, TransactionTypes.REMOVE)
def on_driver_changes_apply(self, button): self.pk_task = packagekit.Task() installs = [] removals = [] for pkg in self.driver_changes: if pkg.is_installed: removals.append(self.get_package_id(pkg.installed)) # The main NVIDIA package is only a metapackage. # We need to collect its dependencies, so that # we can uninstall the driver properly. if 'nvidia' in pkg.shortname: for dep in self.get_dependencies(self.apt_cache, pkg.shortname, 'nvidia'): dep_pkg = self.apt_cache[dep] if dep_pkg.is_installed: removals.append( self.get_package_id(dep_pkg.installed)) else: installs.append(self.get_package_id(pkg.candidate)) self.cancellable = Gio.Cancellable() try: if removals: installs_pending = False if installs: installs_pending = True self.pk_task.remove_packages_async( removals, False, # allow deps True, # autoremove self.cancellable, # cancellable self.on_driver_changes_progress, (None, ), # progress data self.on_driver_changes_finish, # callback ready installs_pending # callback data ) if installs: self.pk_task.install_packages_async( installs, self.cancellable, # cancellable self.on_driver_changes_progress, (None, ), # progress data self.on_driver_changes_finish, # GAsyncReadyCallback False # ready data ) self.button_driver_revert.set_sensitive(False) self.button_driver_apply.set_sensitive(False) self.scrolled_window_drivers.set_sensitive(False) except Exception as e: print("Warning: install not completed successfully: {}".format(e))
def _get_package_details(self, packageid, cache=USE_CACHE): LOG.debug("package_details %s", packageid) #, self._cache.keys() if cache and (packageid in self._cache_details.keys()): return self._cache_details[packageid] task = packagekit.Task() try: result = task.get_details_sync((packageid,), None, self._on_progress_changed, None) except GObject.GError as e: return None pkgs = result.get_details_array() if not pkgs: LOG.debug("no details found for %s", packageid) return None packageid = pkgs[0].get_property('package-id') self._cache_details[packageid] = pkgs[0] LOG.debug("returning package details for %s", packageid) return pkgs[0]
def _get_info(self, app_info, app): app_info['version'] = app.get_version() app_info['arch'] = app.get_id().split(';')[2] pkTask = packagekit.Task() results = [] self._set_status(0) #Only get size and depends if we don't have the data if not app_info['size']: app_info_pool = pool() threads = [] th = threading.Thread(target=self._th_get_details, args=(pkTask, app_info_pool, app)) threads.append(th) th.start() #Get depends disabled per time-costing #th=threading.Thread(target=self._th_get_depends, args = (pkTask,app_info_pool,app)) #threads.append(th) #th.start() for thread in threads: try: thread.join() except: pass while app_info_pool.qsize(): data = app_info_pool.get() app_info.update(data) #Get status try: info = app.get_info() state = info.to_string(info) if state != app_info['state'] and state != 'available' and app_info[ 'state'] == 'installed': app_info['updatable'] = 1 else: app_info['state'] = state self._debug("State: %s" % state) except Exception as e: self._debug("State: not available (%s)" % e) pass #self._debug("INFO: %s"%app_info) return (app_info)