def preparingUpdate(self, troveNum, troveCount, add=0): log.info("callback ....... preparing Update trove %s/%s" % (troveNum, troveCount) ) #self.progress.step() if not self.currentJob or len(self.currentJob) == 0 or troveNum > troveCount: return log.info("currentJob %s" % troveNum) log.info("job %s" % self.currentJob) if len(self.currentJob) > troveNum: job = self.currentJob[troveNum] else: return name = job[0] oldVersion, oldFlavor = job[1] newVersion, newFlavor = job[2] #log.info("JOB>>>>>>>> %s " % str(job) ) if oldVersion and newVersion: log.info("Callback ........ STATUS_UPDATE preparing Update ") self.backend.status(STATUS_UPDATE) package_id = self.backend.get_package_id(name, newVersion, newFlavor) self.backend.package(package_id, INFO_UPDATING, '') elif oldVersion and not newVersion: log.info("Callback ........ STATUS_REMOVE preparing Update ") self.backend.status(STATUS_REMOVE) package_id = self.backend.get_package_id(name, oldVersion, oldFlavor) self.backend.package(package_id, INFO_REMOVING, '')
def creatingRollback(self): #self.backend.status('Creating Rollback') log.info("Callback ........ STATUS_ROLLBACK ") self.backend.status(STATUS_ROLLBACK) self.progress.step() #self.backend.percentage(self.progress.percent) log.info(self.progress.percent)
def removeFiles(self, filenum, total): log.info("Callback ........ STATUS_REMOVE %s percent %s/%s files" %(filenum*100/float(total), filenum, total) ) self.progress.set_subpercent( filenum*100/float(total) ) self.backend.percentage(self.progress.percent) log.info(self.progress.percent) self.backend.status(STATUS_REMOVE) self.preparingUpdate(filenum, total, add=total)
def _resolve_list(self, filters, pkgsList ): log.info("======= _resolve_list =====") specList = [] cli = ConaryPk() for pkg in pkgsList: name = pkg["name"] repo = pkg["label"] version = pkg["version"] trove = name, None , cli.flavor specList.append( trove ) trovesList = cli.repos.findTroves(cli.default_label, specList ) pkgFilter = ConaryFilter(filters) troves = trovesList.values() for trovelst in troves: t = trovelst[0] installed = pkgFilter._pkg_is_installed( t[0] ) if installed: pkgFilter.add_installed( trovelst ) else: pkgFilter.add_available( trovelst ) package_list = pkgFilter.post_process() self._show_package_list(package_list)
def _show_package_list(self, lst): """ HOW its showed on packageKit @lst(list(tuple) = [ ( troveTuple, status ) ] """ for troveTuple, status in lst: # take the basic info name = troveTuple[0] version = troveTuple[1] flavor = troveTuple[2] # get the string id from packagekit package_id = self.get_package_id(name, version, flavor) # split the list for get Determine info summary = package_id.split(";") repo = summary[3].split("#")[0] metadata = eval(summary[3].split("#")[1]) log.info("====== show the package ") log.info(metadata) if metadata.has_key("shortDesc"): meta = metadata["shortDesc"] else: meta = " " self.package(package_id, status, meta )
def set_subpercent(self, pct): ''' Set subpercentage and update percentage ''' self.subpercent = pct self._update_percent() log.info("[Progress] Update SubPercent: Percent -> %d, SubPercent -> %d" % (self.percent, self.subpercent))
def downloadingChangeSet(self, got, need): self.backend.status(STATUS_DOWNLOAD) log.info("[STATUS_DOWNLOAD] Downloading ChangeSet (%.2f%% %.2f out of %.2f MiB)" \ % ( got*100/float(need), got/MEGA,need/MEGA) ) self.progress.set_subpercent( got*100 / float(need) ) self.backend.percentage( self.progress.percent ) if got >= need: self.dostep = True
def resolvingDependencies(self): #self.backend.status('Resolving Dependencies') log.info("Callback ........ STATUS_DEP_RESOLVE ") self.backend.percentage(self.progress.percent) self.backend.status(STATUS_DEP_RESOLVE) self.progress.step() self.backend.percentage(self.progress.percent) log.info(self.progress.percent)
def downloadingChangeSet(self, got, need): self.backend.status(STATUS_DOWNLOAD) log.info("[STATUS_DOWNLOAD] Downloading ChangeSet (%.2f%% %.2f out of %.2f MiB)" \ % ( got*100/float(need), got/MEGA,need/MEGA) ) self.progress.set_subpercent(got * 100 / float(need)) self.backend.percentage(self.progress.percent) if got >= need: self.dostep = True
def committingTransaction(self): #self.backend.status('Committing Transaction') log.info("Callback ........ STATUS_COMMIT transactions ") self.backend.status(STATUS_COMMIT) self.progress.step() self.backend.percentage(self.progress.percent) log.info(self.progress.percent)
def __init__(self, backend, cfg=None): callbacks.UpdateCallback.__init__(self) log.info("==== callback ==== ") if cfg: self.setTrustThreshold(cfg.trustThreshold) self.backend = backend self.currentJob = None self.smallUpdate = False
def set_subpercent(self, pct): ''' Set subpercentage and update percentage ''' self.subpercent = pct self._update_percent() log.info( "[Progress] Update SubPercent: Percent -> %d, SubPercent -> %d" % (self.percent, self.subpercent))
def set_steps(self, steps): ''' Set the steps for the whole transaction @param steps: list of int representing the percentage of each step in the transaction ''' self.reset() self.steps = steps self.current_step = 0 log.info("[Progress] Setting the following steps: %s" % (str(self.steps),))
def setChangesetHunk(self, hunk, hunkCount): """ Called when creating changesets, such as when downloading changesets. @param hunk: the number of the changeset being created (starts at 1) @type hunk: integer @param hunkCount: total number of changesets to be created. @type hunkCount: integer @return: None """ log.info("Callback getUpdates:setChangesetHunk %s percent of %.2f/%.2f bytes" % ( int( hunk*100/float(hunkCount)), hunk/MEGA,hunkCount/MEGA) )
def search_name(self, options, searchlist): ''' Implement the {backend}-search-name functionality ''' log.info("============= search_name ========") self.allow_cancel(True) self.percentage(None) self.status(STATUS_QUERY) log.info("options: %s searchlist:%s "%(options, searchlist)) self._do_search(options, searchlist, 'name')
def search_details(self, options, search): ''' Implement the {backend}-search-details functionality ''' log.info("============= search_details ========") self.allow_cancel(True) #self.percentage(None) self.status(STATUS_QUERY) log.info("options: %s searchlist:%s "%(options, search)) self._do_search(options, search, 'details' )
def setUpdateHunk(self, hunk, hunkCount): log.info("callback. .......... set update HUnk %s/%s" % ( hunk, hunkCount)) if hunk < hunkCount: p = hunk / float(hunkCount) * 100.0 self.progress.set_subpercent(p) else: self.smallUpdate = True self.backend.percentage(self.progress.percent) log.info(self.progress.percent)
def set_steps(self, steps): ''' Set the steps for the whole transaction @param steps: list of int representing the percentage of each step in the transaction ''' self.reset() self.steps = steps self.current_step = 0 log.info("[Progress] Setting the following steps: %s" % (str(self.steps), ))
def search_path(self,path_file ): labels = self.get_labels_from_config() where = self._get_repos() from conary.deps.deps import compatibleFlavors for label in self.default_label: trove = where.getTroveLeavesByPath([path_file], label) log.info(trove) if trove.get(path_file): for ( name,version,flavor) in trove[path_file]: return name
def setChangesetHunk(self, num, total): log.info("Changeset Hunk %d out of %d" % (num, total)) if total > 0: p = num * 100 / float(total) else: p = 0 self.progress.set_subpercent(p) self.disablepercent = True self.backend.percentage(self.progress.percent) if num == total: self.dostep = True
def search(self, search, where ): if where == "name": return self._searchNamePackage(search) elif where == "details": return self._searchDetailsPackage(search) elif where == "group": return self._searchGroupPackage(search) elif where == "all": log.info("searching all .............") return self._getAllPackages() return []
def search(self, search, where): if where == "name": return self._searchNamePackage(search) elif where == "details": return self._searchDetailsPackage(search) elif where == "group": return self._searchGroupPackage(search) elif where == "all": log.info("searching all .............") return self._getAllPackages() return []
def setChangesetHunk(self, num, total): log.info("Changeset Hunk %d out of %d" % (num, total) ) if total > 0: p = num*100/float(total) else: p = 0 self.progress.set_subpercent(p) self.disablepercent = True self.backend.percentage(self.progress.percent) if num == total: self.dostep = True
def get_package_from_id(self, package_id): """ package_id(string) = "dpaster;0.1-3-1;x86;/foresight.rpath.org@fl:2-qa/0.1-3-1#{'version': '0.1-3-1', 'category': [], 'name': 'dpaster', 'label': 'foresight.rpath.org@fl:2-qa'}" """ log.info("=========== get package from package_id ======================") name, verString, archString, data = pkpackage.get_package_from_id(package_id) summary = data.split("#") repo = summary[0] metadata = eval(summary[1]) cli = ConaryPk() return cli.request_query(name)
def step(self): ''' Step to the next step in the transaction ''' if self.current_step < len(self.steps)-1: self.current_step += 1 self.percent = self.steps[self.current_step] self.subpercent = 0 else: self.percent = 100 self.subpercent = 0 log.info("[Progress] Step -> %d, Percent -> %d " % (self.current_step, self.percent))
def setUpdateHunk(self, num, total): log.info("Update Hunk %d out of %d" % (num, total ) ) if self.dostep: self.disablepercent = True self.dostep = False if num < total: p = num*100/float(total) self.progress.set_subpercent(p) else: self.smallUpdate = True self.backend.percentage(self.progress.percent)
def setUpdateHunk(self, num, total): log.info("Update Hunk %d out of %d" % (num, total)) if self.dostep: self.disablepercent = True self.dostep = False if num < total: p = num * 100 / float(total) self.progress.set_subpercent(p) else: self.smallUpdate = True self.backend.percentage(self.progress.percent)
def __init__(self, backend, cfg=None): callbacks.UpdateCallback.__init__(self) log.info("==== callback ==== ") if cfg: self.setTrustThreshold(cfg.trustThreshold) self.backend = backend self.currentJob = None self.smallUpdate = False self.error = [] self.progress = PackagekitProgress() self.progress.set_steps([ 2,5,7,8,90,100 ] )
def _fetchXML(self): log.info("Updating XMLCache for label %s" % self.label) if self.label in self.pregenerated_XML_labels: wwwfile = "%s/%s.xml" % (self.server, self.label) try: wget = url.urlopen(wwwfile) openfile = open(self.xml_file, 'w') openfile.write(wget.read()) openfile.close() except: self.pk.error(ERROR_NO_NETWORK,"Failed to fetch %s." % wwwfile) else: generateXML.init(self.label, self.xml_file)
def step(self): ''' Step to the next step in the transaction ''' if self.current_step < len(self.steps) - 1: self.current_step += 1 self.percent = self.steps[self.current_step] self.subpercent = 0 else: self.percent = 100 self.subpercent = 0 log.info("[Progress] Step -> %d, Percent -> %d " % (self.current_step, self.percent))
def __init__(self, backend, cfg=None): callbacks.UpdateCallback.__init__(self) log.info("==== callback ==== ") if cfg: self.setTrustThreshold(cfg.trustThreshold) self.backend = backend self.currentJob = None self.smallUpdate = False self.error = [] self.progress = PackagekitProgress() self.disablepercent = False self.dostep = True
def resolve(self, filters, package ): """ @filters (list) list of filters @package (list ) list with packages name for resolve """ log.info("======== resolve =========") log.info("filters: %s package:%s " % (filters, package)) cache = Cache() pkg_dict = cache.resolve( package[0] ) if pkg_dict is None: self.error(ERROR_INTERNAL_ERROR, "Package Not found on repository") filter = ConaryFilter(filters) installed = filter._pkg_is_installed( pkg_dict["name"] ) conary_cli = ConaryPk() troveTuple = conary_cli.request_query( package[0] ) log.info(">>> %s" % troveTuple) if installed: filter.add_installed( troveTuple ) else: filter.add_available( troveTuple ) package_list = filter.post_process() log.info("package_list %s" % package_list) self._show_package_list(package_list)
def preparingUpdate(self, troveNum, troveCount, add=0): if not self.currentJob or len(self.currentJob) == 0 or troveNum > troveCount: return if troveNum > 0 and troveCount > 0: sub_percent = (add + troveNum) / (2 * float(troveCount)) * 100 self.backend.sub_percentage(sub_percent) if self.smallUpdate: self.backend.percentage(sub_percent) if troveNum != 0: troveNum -= 1 job = self.currentJob[troveNum] name = job[0] oldVersion, oldFlavor = job[1] newVersion, newFlavor = job[2] log.info((oldVersion, newVersion)) if oldVersion and newVersion: log.info("Callback ........ STATUS_UPDATE ") self.backend.status(STATUS_UPDATE) package_id = self.backend.get_package_id(name, newVersion, newFlavor) self.backend.package(package_id, INFO_UPDATING, '') elif oldVersion and not newVersion: log.info("Callback ........ STATUS_REMOVE ") self.backend.status(STATUS_REMOVE) package_id = self.backend.get_package_id(name, oldVersion, oldFlavor) self.backend.package(package_id, INFO_REMOVING, '') elif not oldVersion and newVersion: log.info("Callback ........ STATUS_INSTALL ") self.backend.status(STATUS_INSTALL) package_id = self.backend.get_package_id(name, newVersion, newFlavor) self.backend.package(package_id, INFO_INSTALLING, '')
def _fetchXML(self): log.info("Updating XMLCache for label %s" % self.label) if self.label in self.pregenerated_XML_labels: wwwfile = "%s/%s.xml" % (self.server, self.label) try: wget = url.urlopen(wwwfile) openfile = open(self.xml_file, 'w') openfile.write(wget.read()) openfile.close() except: self.pk.error(ERROR_NO_NETWORK, "Failed to fetch %s." % wwwfile) else: generateXML.init(self.label, self.xml_file)
def search(self, search, where = "name" ): """ @where (string) values = name | details | group | all """ repositories_result = [] log.info("%s " % search) if search is not list: search = [search] for repo in self.repos: for s in search: results = repo.search(s , where ) for i in results: repositories_result.append(i) return self.list_set( repositories_result)
def init(label, fileoutput): conarypk = ConaryPk() cli = conarypk.cli cfg = conarypk.cfg log.info("Attempting to retrieve repository data for %s" % label) try: pkgs = getPackagesFromLabel(cfg,cli,label) troves = conarypk.repos.getTroves(pkgs,withFiles=False) nodes = generate_xml(troves,label) cElementTree.ElementTree(nodes).write(fileoutput) log.info("Successfully wrote XML data for label %s into file %s" % (label, fileoutput)) except: log.error("Failed to gather data from the repository")
def _fetchXML(self, label): log.info("Updating XMLCache for label %s" % label) filename = label + '.xml' filepath = self.xml_path + filename if label in self.pregenerated_XML_labels: wwwfile = self.server + filename try: wget = url.urlopen( wwwfile ) openfile = open(filepath,'w') openfile.writelines(wget.readlines()) openfile.close() except: self.pk.error(ERROR_NO_NETWORK,"%s can not open" % wwwfile) else: generateXML.init(label,filepath,self.conarypk)
def _fetchXML(self, label): log.info("Updating XMLCache for label %s" % label) filename = label + '.xml' filepath = self.xml_path + filename if label in self.pregenerated_XML_labels: wwwfile = self.server + filename try: wget = url.urlopen(wwwfile) openfile = open(filepath, 'w') openfile.writelines(wget.readlines()) openfile.close() except: self.pk.error(ERROR_NO_NETWORK, "%s can not open" % wwwfile) else: generateXML.init(label, filepath, self.conarypk)
def init(label, fileoutput): conarypk = ConaryPk() cli = conarypk.cli cfg = conarypk.cfg log.info("Attempting to retrieve repository data for %s" % label) try: pkgs = getPackagesFromLabel(cfg, cli, label) troves = conarypk.repos.getTroves(pkgs, withFiles=False) nodes = generate_xml(troves, label) cElementTree.ElementTree(nodes).write(fileoutput) log.info("Successfully wrote XML data for label %s into file %s" % (label, fileoutput)) except: log.error("Failed to gather data from the repository")
def _findPackage(self, package_id): ''' find a package based on a package id (name;version;arch;repoid) ''' log.info("========== _findPackage ==========") log.info(package_id) troveTuples = self.get_package_from_id(package_id) for troveTuple in troveTuples: log.info("======== trove ") log.info(troveTuple) installed = self.check_installed(troveTuple) log.info(installed) name, version, flavor = troveTuple return name, version, flavor, installed else: self.error(ERROR_INTERNAL_ERROR, "package_id Not Correct ")
def preparingUpdate(self, troveNum, troveCount): def _get_package_id(name, v, f): version = str(v.trailingRevision()) label = str(v.trailingLabel()) arch = conarypk.get_arch(f) package_id = get_package_id(name, version, arch, label) return package_id if not self.currentJob or len( self.currentJob) == 0 or troveNum > troveCount: return self.backend.percentage(self.progress.percent) job = self.currentJob[troveNum - 1] name, (oldVersion, oldFlavor), (newVersion, newFlavor) = job[:3] if oldVersion and newVersion: package_id = _get_package_id(name, newVersion, newFlavor) log.info("Preparing Update %d out of %d: %s" % (troveNum, troveCount, package_id)) self.backend.status(STATUS_UPDATE) self.backend.package(package_id, INFO_UPDATING, '') elif oldVersion and not newVersion: package_id = _get_package_id(name, oldVersion, oldFlavor) log.info("Preparing Remove %d out of %d: %s" % (troveNum, troveCount, package_id)) self.backend.status(STATUS_REMOVE) self.backend.package(package_id, INFO_REMOVING, '') elif not oldVersion and newVersion: package_id = _get_package_id(name, newVersion, newFlavor) log.info("Preparing Install %d out of %d: %s" % (troveNum, troveCount, package_id)) self.backend.status(STATUS_INSTALL) self.backend.package(package_id, INFO_INSTALLING, '')
def preparingUpdate(self, troveNum, troveCount, add=0): if not self.currentJob or len( self.currentJob) == 0 or troveNum > troveCount: return self.backend.percentage(self.progress.percent) job = self.currentJob[troveNum - 1] name = job[0] oldVersion, oldFlavor = job[1] newVersion, newFlavor = job[2] if oldVersion and newVersion: package_id = self.backend.get_package_id(name, newVersion, newFlavor) log.info("Preparing Update %d out of %d: %s" % (troveNum, troveCount, package_id)) self.backend.status(STATUS_UPDATE) self.backend.package(package_id, INFO_UPDATING, '') elif oldVersion and not newVersion: package_id = self.backend.get_package_id(name, oldVersion, oldFlavor) log.info("Preparing Remove %d out of %d: %s" % (troveNum, troveCount, package_id)) self.backend.status(STATUS_REMOVE) self.backend.package(package_id, INFO_REMOVING, '') elif not oldVersion and newVersion: package_id = self.backend.get_package_id(name, newVersion, newFlavor) log.info("Preparing Install %d out of %d: %s" % (troveNum, troveCount, package_id)) self.backend.status(STATUS_INSTALL) self.backend.package(package_id, INFO_INSTALLING, '')
def updateDone(self): log.info("Update Done") self.backend.percentage(self.progress.percent) self.currentJob = None log.info(self.progress.percent)
def reset(self): self.percent = 0 self.steps = [] self.current_step = 0 self.subpercent = 0 log.info("[Progress] Reset")
def done(self): log.info("Done.")
def requestingChangeSet(self): self.backend.status(STATUS_REQUEST) log.info("[STATUS_REQUEST] Requesting ChangeSet")
def committingTransaction(self): log.info('[STATUS_COMMIT] Committing Transaction') self.backend.status(STATUS_COMMIT) self.backend.percentage(self.progress.percent)
def creatingDatabaseTransaction(self, troveNum, troveCount): log.info("Creating Database Transaction %d out of %d" % (troveNum, troveCount)) self.backend.percentage(self.progress.percent) log.info(self.progress.percent)
def troveScriptOutput(self, typ, msg): log.info("Trove Script Output [%s] %s" % (typ, msg))
def removeFiles(self, filenum, total): log.info("[STATUS_REMOVE] %s out of %s file(s)" % (filenum, total)) self.backend.status(STATUS_REMOVE)
def resolvingDependencies(self): self.backend.status(STATUS_DEP_RESOLVE) log.info("[STATUS_DEP_RESOLVE] Resolving Dependencies") self.backend.percentage(self.progress.percent)
def downloadingFileContents(self, got, need): log.info("[STATUS_DOWNLOAD] Downloading File Contents (%.2f%% %.2f out of %.2f MiB)" \ % ( got*100/float(need), got/MEGA,need/MEGA) ) self.backend.status(STATUS_DOWNLOAD)
def cacheUpdateJob(self, applyList, updJob): jobPath = self._getJobCachePath(applyList) log.info("jobPath %s" % jobPath) if os.path.exists(jobPath): log.info("deleting the JobPath %s " % jobPath) util.rmtree(jobPath) log.info("end deleting the JobPath %s " % jobPath) log.info("making the logPath ") os.mkdir(jobPath) log.info("freeze JobPath") updJob.freeze(jobPath) log.info("end freeze JobPath")
def checkCachedUpdateJob(self, applyList): jobPath = self._getJobCachePath(applyList) log.info("CheckjobPath %s" % jobPath) if os.path.exists(jobPath): return jobPath
def setUpdateJob(self, job): self.currentJob = job self.backend.percentage(self.progress.percent) log.info("callback UpdateSystem. setUpdateJob") log.info(self.progress.percent)
def requestingFileContents(self): log.info("[STATUS_REQUEST] Requesting File Contents") self.backend.status(STATUS_REQUEST)
def tagHandlerOutput(self, tag, msg, stderr=False): log.info("Tag Handler Output: [%s] %s" % (tag, msg))