def appGuiFilter(pkg_name): if self.state == remove_state: package = PisiIface.get_installed_package(pkg_name) return "app:gui" in package.isA elif self.state == install_state: package = PisiIface.get_repo_package(pkg_name) return "app:gui" in package.isA
def searchPackage(self): Globals.setWaitCursor() query = unicode(self.searchLine.text()) terms = query.split() if query: if self.state == remove_state: result = PisiIface.search_in_installed(terms) elif self.state == install_state: result = PisiIface.search_in_repos(terms) elif self.state == upgrade_state: result = PisiIface.search_in_upgradables(terms) self.createSearchResults(result) else: self.refreshState(reset=False) Globals.setNormalCursor()
def getProxySettings(self): config = PisiIface.read_config("/etc/pisi/pisi.conf") httpProxy = httpProxyPort = ftpProxy = ftpProxyPort = httpsProxy = httpsProxyPort = None http = config.get("general", "http_proxy") if http and http != "None": httpProxy, httpProxyPort = http[7:].split(":") self.httpProxy.setText(httpProxy) self.httpProxyPort.setValue(int(httpProxyPort)) https = config.get("general", "https_proxy") if https and https != "None": httpsProxy, httpsProxyPort = https[8:].split(":") self.httpsProxy.setText(httpsProxy) self.httpsProxyPort.setValue(int(httpsProxyPort)) ftp = config.get("general", "ftp_proxy") if ftp and ftp != "None": ftpProxy, ftpProxyPort = ftp[6:].split(":") self.ftpProxy.setText(ftpProxy) self.ftpProxyPort.setValue(int(ftpProxyPort)) if httpProxy or ftpProxy or httpsProxy: self.useProxyButton.setChecked(True) if (httpProxy == httpsProxy == ftpProxy) and (httpProxyPort == httpsProxyPort == ftpProxyPort): self.useHttpForAll.setChecked(True)
def humanReadableSize(size, precision=".1"): tpl = PisiIface.humanize(size) if tpl[0] == 0: return "0 B" fmt = "%%%sf %%s" % precision return fmt % (tpl[0], tpl[1])
def setTakeBackPlan(self): willbeinstalled, willberemoved = PisiIface.getPlan(self.selected.getOpNo()) information = "" if self.selected.getType() == 'snapshot': # configuration files in a snapshot configs = self.historydb.get_config_files(self.selected.getOpNo()) if len(configs) != 0: information += "<br>" + i18n("Configuration files in snapshot:") for i in configs.keys(): information += "<br><br><b>" + i + "</b><br>" for j in configs.get(i): information += "/".join(j.split(str(self.selected.getOpNo()),1)[1].split(i,1)[1:]) self.planTextEdit.setText(information) message = i18n("Take Back Plan for %1 operation on %2")\ .arg(self.selected.getTypeTr()).arg(self.selected.getDate()) + "<br><br>" if len(willbeinstalled) != 0: message += "<br>" + i18n("These package(s) will be <b>installed</b> :") + "<br>" for i in range(len(willbeinstalled)): message += willbeinstalled[i] + "<br>" if len(willberemoved) != 0: message += "<br>" + i18n("These package(s) will be <b>removed</b> :") + "<br>" for i in range(len(willberemoved)): message += willberemoved[i] + "<br>" message += "<br>" self.planTextEdit.setText(message + information)
def createSearchResults(self, packages): self.componentsList.clear() item = KListViewItem(self.componentsList) item.setText(0,i18n("Search Results")) item.setPixmap(0, KGlobal.iconLoader().loadIcon("find",KIcon.Desktop,KIcon.SizeMedium)) packagesWithMeta = [PisiIface.get_package(package, self.state != install_state) for package in packages] if self.state == remove_state: self.specialList.createList(packagesWithMeta, selected = self.basket.packages, disabled = unremovable_packages) else: self.specialList.createList(packagesWithMeta, selected = self.basket.packages) self.componentsList.setSelected(self.componentsList.firstChild(),True)
def __take_back(self, operation): willbeinstalled, willberemoved = PisiIface.getPlan(operation) qmessage = i18n("This will restore your system back to : %1 %2\nIf you're unsure, click Cancel and see TakeBack Plan")\ .arg(self.selected.getDate()).arg(self.selected.getTime()) if not self.command.inProgress(): if 0 == QMessageBox.question(self, i18n("Warning"), \ qmessage, i18n("Continue"), i18n("Cancel")): self.enableButtons(False) self.progress.reset() self.progress.setTotalSteps((len(willbeinstalled)+len(willberemoved))*2) self.command.takeBack(operation)
def getBandwidthSetting(self): config = PisiIface.read_config("/etc/pisi/pisi.conf") bandwidth_limit = config.get("general", "bandwidth_limit") if bandwidth_limit: bandwidth_limit = int(bandwidth_limit) else: bandwidth_limit = 0 if bandwidth_limit != 0: self.useBandwidthLimit.setChecked(True) self.bandwidthValue.setValue(bandwidth_limit)
def showPopup(self): from sets import Set as set upgrades = PisiIface.get_upgradable_packages() newUpgrades = set(upgrades) - set(self.lastUpgrades) self.lastUpgrades = upgrades if not len(upgrades) or not newUpgrades: return icon = getIconPath("package-manager") message = i18n("There are <b>%1</b> updates available!").arg(len(upgrades)) header = i18n("Updates Available!") self.notifier.show(icon, header, message, self.getPos())
def update(self): self.packagesSize = 0 self.extraPackagesSize = 0 pkgs = self.packages if not pkgs: self.extraPackages = [] return if self.state == install_state: allPackages = PisiIface.get_install_order(pkgs) elif self.state == remove_state: allPackages = PisiIface.get_remove_order(pkgs) elif self.state == upgrade_state: allPackages = PisiIface.get_upgrade_order(pkgs) self.extraPackages = list(set(allPackages) - set(pkgs)) for package in pkgs: self.packagesSize += self.getPackageSize(self.getPackage(package)) for package in self.extraPackages: self.extraPackagesSize += self.getPackageSize(self.getPackage(package))
def finished(self, command=None): # when pisi db version is upgraded, reload is needed before init packages = self.basket.packages + self.basket.extraPackages print "in finished(): command=%s" % command if command in nop: return #FIXME: Why do we need to reload pisi module every time. Added for not updating mem cached dbs of pisi PisiIface.reloadPisi() self.basket.empty() self.operateAction.setEnabled(False) self.basketAction.setEnabled(False) self.parent.showUpgradeAction.setEnabled(True) self.progressDialog.closeForced() self.progressDialog.reset() if command in ["System.Manager.updateAllRepositories", "System.Manager.updateRepository"]: self.refreshState() if self.parent.isHidden(): self.parent.tray.showPopup() elif command == "System.Manager.setRepositories": self.updateCheck() return elif command in ["System.Manager.updatePackage", "System.Manager.installPackage", "System.Manager.removePackage", "System.Manager.cancelled"]: self.refreshState() self.parent.tray.updateTrayIcon()
def refreshComponentList(self, item): Globals.setWaitCursor() try: # fetch packages including metadata from cache packagesWithMeta = [PisiIface.get_package(package, self.state == remove_state) for package in self.componentDict[item].packages] if self.state == remove_state: self.specialList.createList(packagesWithMeta, selected = self.basket.packages, disabled = unremovable_packages) else: self.specialList.createList(packagesWithMeta, selected = self.basket.packages) self.lastSelectedComponent = self.componentDict[item].name # initialization and search state listview items are not components except KeyError: pass finally: Globals.setNormalCursor()
def getCacheSettings(self): config = PisiIface.read_config("/etc/pisi/pisi.conf") cache = config.get("general", "package_cache") cache_limit = config.get("general", "package_cache_limit") if cache_limit: cache_limit = int(cache_limit) else: cache_limit = 0 # If pisi.conf does not have it yet, default is use package cache if not cache or cache == "True": enableCache = True else: enableCache = False self.cacheEnabled = enableCache self.cacheSize = cache_limit self.useCacheCheck.setChecked(enableCache) self.useCacheSize.setValue(cache_limit)
def updateTrayIcon(self): nofUpgrades = len(PisiIface.get_upgradable_packages()) if not nofUpgrades: self.setPixmap(self.icon) return oldW = self.pixmap().size().width() oldH = self.pixmap().size().height() uStr = QString.number(nofUpgrades); f = KGlobalSettings.generalFont() f.setBold(True); pointSize = f.pointSizeFloat() fm = QFontMetrics(f) w = fm.width(uStr) if w > oldW: pointSize *= float(oldW) / float(w) f.setPointSizeFloat(pointSize) pix = QPixmap(oldW, oldH) pix.fill(Qt.white) p = QPainter(pix) p.setFont(f) p.setPen(Qt.blue) p.drawText(pix.rect(), Qt.AlignCenter, uStr) pix.setMask(pix.createHeuristicMask()) img = QImage(pix.convertToImage()) overlayImg = QImage(self.overlayIcon.copy()) KIconEffect.overlay(overlayImg, img) icon = QPixmap() icon.convertFromImage(overlayImg) self.setPixmap(icon) # for cannot destroy paint device error p = None
def upgradeState(self): Globals.setWaitCursor() try: # TODO: # If package-manager is opened while tray is updating-repo; progress dialog is # shown. And when it ends, pm switches to upgradeState but without checking # operation buttons. If pm is not opened while this is done, no change state happens # in pm, and when it is opened it will be seen in which state it was left. # # Later this background update may be done with a widget like kmail's small progress # and any operation button will be disabled when tray is caught while updating. For # now we show progress dialog and change pm state and button states manually. self.parent.showUpgradeAction.setChecked(True) self.parent.showNewAction.setChecked(False) self.parent.showInstalledAction.setChecked(False) ## try: upgradables = PisiIface.get_upgradable_packages() except PisiIface.RepoError: Globals.setNormalCursor() self.repoNotReady() return self.createComponentList(upgradables, True) self.operateAction.setText(i18n("Upgrade Package(s)")) self.operateAction.setIconSet(loadIconSet("reload")) self.lastSelectedComponent = i18n("All") self.setLastSelected() self.basket.setState(self.state) self.updateStatusBar() finally: Globals.setNormalCursor()
def componentsReady(self): if not PisiIface.get_components(): # Repo metadata empty return False return True
def createComponentList(self, packages, allComponent=False): # filter for selecting only apps with gui def appGuiFilter(pkg_name): if self.state == remove_state: package = PisiIface.get_installed_package(pkg_name) return "app:gui" in package.isA elif self.state == install_state: package = PisiIface.get_repo_package(pkg_name) return "app:gui" in package.isA self.componentsList.clear() self.componentDict.clear() # eliminate components that are not visible to users. This is achieved by a tag in component.xmls componentNames = [cname for cname in PisiIface.get_components() if PisiIface.is_component_visible(cname)] showOnlyGuiApp = self.settings.getBoolValue(Settings.general, "ShowOnlyGuiApp") # this list is required to find 'Others' group, that is group of packages not belong to any component componentPackages = [] for componentName in componentNames: # just check the component existance try: component = PisiIface.get_union_component(componentName) except Exception: continue # get all packages of the component compPkgs = PisiIface.get_union_component_packages(componentName, walk=True) # find which packages belong to this component component_packages = list(set(packages).intersection(compPkgs)) componentPackages += component_packages if self.state != upgrade_state and showOnlyGuiApp: component_packages = filter(appGuiFilter, component_packages) if len(component_packages): # create ListView item for component item = KListViewItem(self.componentsList) if component.localName: name = component.localName else: name = component.name if component.icon: icon = component.icon else: icon = "package" item.setText(0,u"%s (%s)" % (name, len(component_packages))) item.setPixmap(0, KGlobal.iconLoader().loadIcon(icon, KIcon.Desktop,KIcon.SizeMedium)) # create component object that has a list of its own packages and a summary self.componentDict[item] = Component(name, component_packages, component.summary) # Rest of the packages rest_packages = list(set(packages) - set(componentPackages)) if self.state != upgrade_state and showOnlyGuiApp: rest_packages = filter(appGuiFilter, rest_packages) if rest_packages: item = KListViewItem(self.componentsList) name = i18n("Others") item.setText(0, u"%s (%s)" % (name, len(rest_packages))) item.setPixmap(0, KGlobal.iconLoader().loadIcon("package_applications",KIcon.Desktop,KIcon.SizeMedium)) self.componentDict[item] = Component(name, rest_packages, name) # All of the component's packages if allComponent: item = KListViewItem(self.componentsList) name = i18n("All") item.setText(0, u"%s (%s)" % (name, len(packages))) item.setPixmap(0, KGlobal.iconLoader().loadIcon("package_network",KIcon.Desktop,KIcon.SizeMedium)) self.componentDict[item] = Component(name, packages, name)
def getPackage(self, package): if self.state == remove_state: return PisiIface.get_installed_package(package) else: return PisiIface.get_repo_package(package)
def updateDownloadingInfo(self, operation, file): self.packageName = PisiIface.parse_package_name(file)[0] self.setOperationDescription(i18n('%1 %2').arg(self.packageName).arg(operation)) self.updateCompletedInfo() self.showOperationDescription()