3 # Copyright (c) 2010, 2011 Intel, Inc.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation; version 2 of the License
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc., 59
16 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 if not hasattr(zypp, 'PoolQuery') or \
25 not hasattr(zypp.RepoManager, 'loadSolvFile'):
26 raise ImportError("python-zypp in host system cannot support PoolQuery or "
27 "loadSolvFile interface, please update it to enhanced "
28 "version which can be found in download.tizen.org/tools")
31 from mic.kickstart import ksparser
32 from mic.utils import misc, rpmmisc, runner, fs_related
33 from mic.utils.grabber import myurlgrab, TextProgress
34 from mic.utils.proxy import get_proxy_for
35 from mic.utils.errors import CreatorError, RepoError, RpmError
36 from mic.imager.baseimager import BaseImageCreator
42 self.mirrorlist = None
44 self.proxy_username = None
45 self.proxy_password = None
49 self.autorefresh = True
50 self.keeppackages = True
53 from mic.pluginbase import BackendPlugin
54 class Zypp(BackendPlugin):
57 def __init__(self, target_arch, instroot, cachedir, strict_mode = False):
58 self.cachedir = cachedir
59 self.instroot = instroot
60 self.target_arch = target_arch
61 self.strict_mode = strict_mode
63 self.__pkgs_license = {}
64 self.__pkgs_content = {}
65 self.__pkgs_vcsinfo = {}
69 self.repo_manager = None
70 self.repo_manager_options = None
78 self.probFilterFlags = [ rpm.RPMPROB_FILTER_OLDPACKAGE,
79 rpm.RPMPROB_FILTER_REPLACEPKG ]
81 self.has_prov_query = True
82 self.install_debuginfo = False
83 # this can't be changed, it is used by zypp
84 self.tmp_file_path = '/var/tmp'
86 def doFileLogSetup(self, uid, logfile):
87 # don't do the file log for the livecd as it can lead to open fds
88 # being left and an inability to clean up after ourself
100 self.ts_pre.closeDB()
108 def _cleanupRpmdbLocks(self, installroot):
109 # cleans up temporary files left by bdb so that differing
110 # versions of rpm don't cause problems
112 for f in glob.glob(installroot + "/var/lib/rpm/__db*"):
115 def _cleanupZyppJunk(self, installroot):
117 shutil.rmtree(os.path.join(installroot, '.zypp'))
122 self._cleanupRpmdbLocks(self.instroot)
123 # '/var/tmp' is used by zypp to build cache, so make sure
125 if not os.path.exists(self.tmp_file_path ):
126 os.makedirs(self.tmp_file_path)
128 def whatObsolete(self, pkg):
129 query = zypp.PoolQuery()
130 query.addKind(zypp.ResKind.package)
131 query.addDependency(zypp.SolvAttr.obsoletes, pkg.name(), pkg.edition())
132 query.setMatchExact()
133 for pi in query.queryResults(self.Z.pool()):
137 def _zyppQueryPackage(self, pkg):
138 query = zypp.PoolQuery()
139 query.addKind(zypp.ResKind.package)
140 query.addAttribute(zypp.SolvAttr.name, pkg)
141 query.setMatchExact()
142 for pi in query.queryResults(self.Z.pool()):
146 def _splitPkgString(self, pkg):
147 sp = pkg.rsplit(".", 1)
152 sysarch = zypp.Arch(self.target_arch)
153 if not zypp.Arch(arch).compatible_with (sysarch):
158 def selectPackage(self, pkg):
159 """Select a given package or package pattern, can be specified
160 with name.arch or name* or *name
164 self.__initialize_zypp()
166 def markPoolItem(obs, pi):
168 pi.status().setToBeInstalled (zypp.ResStatus.USER)
170 obs.status().setToBeInstalled (zypp.ResStatus.USER)
173 # compare criterion: arch compatibility first, then repo
174 # priority, and version last
177 if str(a1) != str(a2):
178 if a1.compatible_with(a2):
182 # Priority of a repository is an integer value between 0 (the
183 # highest priority) and 99 (the lowest priority)
184 pr1 = int(p1.repoInfo().priority())
185 pr2 = int(p2.repoInfo().priority())
193 (e1, v1, r1) = map(str, [ed1.epoch(), ed1.version(), ed1.release()])
194 (e2, v2, r2) = map(str, [ed2.epoch(), ed2.version(), ed2.release()])
195 return rpm.labelCompare((e1, v1, r1), (e2, v2, r2))
198 startx = pkg.startswith("*")
199 endx = pkg.endswith("*")
200 ispattern = startx or endx
201 name, arch = self._splitPkgString(pkg)
204 q.addKind(zypp.ResKind.package)
207 if startx and not endx:
208 pattern = '%s$' % (pkg[1:])
209 if endx and not startx:
210 pattern = '^%s' % (pkg[0:-1])
212 pattern = '%s' % (pkg[1:-1])
214 q.addAttribute(zypp.SolvAttr.name, pattern)
218 q.addAttribute(zypp.SolvAttr.name, name)
222 q.addAttribute(zypp.SolvAttr.name, pkg)
225 q.queryResults(self.Z.pool()),
226 cmp=lambda x,y: cmpEVR(zypp.asKindPackage(x), zypp.asKindPackage(y)),
228 item = zypp.asKindPackage(pitem)
229 if item.name() in self.excpkgs.keys() and \
230 self.excpkgs[item.name()] == item.repoInfo().name():
232 if item.name() in self.incpkgs.keys() and \
233 self.incpkgs[item.name()] != item.repoInfo().name():
237 obspkg = self.whatObsolete(item)
239 if arch == str(item.arch()):
240 pitem.status().setToBeInstalled (zypp.ResStatus.USER)
242 markPoolItem(obspkg, pitem)
246 # Can't match using package name, then search from packge
247 # provides infomation
248 if found == False and not ispattern:
249 q.addAttribute(zypp.SolvAttr.provides, pkg)
250 q.addAttribute(zypp.SolvAttr.name,'')
253 q.queryResults(self.Z.pool()),
254 cmp=lambda x,y: cmpEVR(zypp.asKindPackage(x), zypp.asKindPackage(y)),
256 item = zypp.asKindPackage(pitem)
257 if item.name() in self.excpkgs.keys() and \
258 self.excpkgs[item.name()] == item.repoInfo().name():
260 if item.name() in self.incpkgs.keys() and \
261 self.incpkgs[item.name()] != item.repoInfo().name():
265 obspkg = self.whatObsolete(item)
266 markPoolItem(obspkg, pitem)
272 raise CreatorError("Unable to find package: %s" % (pkg,))
274 def inDeselectPackages(self, pitem):
275 """check if specified pacakges are in the list of inDeselectPackages
277 item = zypp.asKindPackage(pitem)
279 for pkg in self.to_deselect:
280 startx = pkg.startswith("*")
281 endx = pkg.endswith("*")
282 ispattern = startx or endx
283 pkgname, pkgarch = self._splitPkgString(pkg)
286 if name == pkgname and str(item.arch()) == pkgarch:
292 if startx and name.endswith(pkg[1:]):
294 if endx and name.startswith(pkg[:-1]):
299 def deselectPackage(self, pkg):
300 """collect packages should not be installed"""
301 self.to_deselect.append(pkg)
303 def selectGroup(self, grp, include = ksparser.GROUP_DEFAULT):
305 self.__initialize_zypp()
308 q.addKind(zypp.ResKind.pattern)
309 for pitem in q.queryResults(self.Z.pool()):
310 item = zypp.asKindPattern(pitem)
311 summary = "%s" % item.summary()
312 name = "%s" % item.name()
313 if name == grp or summary == grp:
315 pitem.status().setToBeInstalled (zypp.ResStatus.USER)
319 if include == ksparser.GROUP_REQUIRED:
321 lambda p: self.deselectPackage(p),
322 grp.default_packages.keys())
326 raise CreatorError("Unable to find pattern: %s" % (grp,))
328 def addRepository(self, name,
332 proxy_username = None,
333 proxy_password = None,
340 # TODO: Handle cost attribute for repos
342 if not self.repo_manager:
343 self.__initialize_repo_manager()
345 if not proxy and url:
346 proxy = get_proxy_for(url)
348 repo = RepositoryStub()
352 repo.proxy_username = proxy_username
353 repo.proxy_password = proxy_password
354 repo.ssl_verify = ssl_verify
355 repo.nocache = nocache
356 repo.baseurl.append(url)
359 self.incpkgs[pkg] = name
362 self.excpkgs[pkg] = name
365 repo.mirrorlist = mirrorlist
367 # Enable gpg check for verifying corrupt packages
369 if priority is not None:
370 # priority 0 has issue in RepoInfo.setPriority
371 repo.priority = priority + 1
374 repo_info = zypp.RepoInfo()
375 repo_info.setAlias(repo.name)
376 repo_info.setName(repo.name)
377 repo_info.setEnabled(repo.enabled)
378 repo_info.setAutorefresh(repo.autorefresh)
379 repo_info.setKeepPackages(repo.keeppackages)
380 baseurl = zypp.Url(repo.baseurl[0].full)
382 baseurl.setQueryParam("ssl_verify", "no")
384 host = urlparse.urlparse(proxy)[1]
385 # scheme, host, path, parm, query, frag = urlparse.urlparse(proxy)
387 proxyinfo = host.rsplit(":", 1)
391 if len(proxyinfo) > 1:
394 if proxy.startswith("socks") and len(proxy.rsplit(':', 1)) == 2:
395 host = proxy.rsplit(':', 1)[0]
396 port = proxy.rsplit(':', 1)[1]
398 # parse user/pass from proxy host
399 proxyinfo = host.rsplit("@", 1)
400 if len(proxyinfo) == 2:
402 # Known Issue: If password contains ":", which should be
403 # quoted, for example, use '123%3Aabc' instead of 123:abc
404 userpassinfo = proxyinfo[0].rsplit(":", 1)
405 if len(userpassinfo) == 2:
406 proxy_username = userpassinfo[0]
407 proxy_password = userpassinfo[1]
408 elif len(userpassinfo) == 1:
409 proxy_username = userpassinfo[0]
411 baseurl.setQueryParam ("proxy", host)
412 baseurl.setQueryParam ("proxyport", port)
414 baseurl.setQueryParam ("proxyuser", proxy_username)
416 baseurl.setQueryParam ("proxypass", proxy_password)
418 baseurl.setQueryParam ("proxy", "_none_")
420 self.repos.append(repo)
422 repo_info.addBaseUrl(baseurl)
424 if repo.priority is not None:
425 repo_info.setPriority(repo.priority)
427 # this hack is used to change zypp credential file location
428 # the default one is $HOME/.zypp, which cause conflicts when
429 # installing some basic packages, and the location doesn't
430 # have any interface actually, so use a tricky way anyway
432 if 'HOME' in os.environ:
433 homedir = os.environ['HOME']
434 os.environ['HOME'] = '/'
436 os.environ['HOME'] = '/'
438 self.repo_manager.addRepository(repo_info)
440 # save back the $HOME env
442 os.environ['HOME'] = homedir
444 del os.environ['HOME']
446 self.__build_repo_cache(name)
448 except RuntimeError, e:
449 raise CreatorError(str(e))
451 msger.verbose('repo: %s was added' % name)
454 def installHasFile(self, file):
457 def preInstall(self, pkg):
458 self.pre_pkgs.append(pkg)
460 def checkPackage(self, pkg):
461 self.check_pkgs.append(pkg)
463 def runInstall(self, checksize = 0):
464 os.environ["HOME"] = "/"
465 os.environ["LD_PRELOAD"] = ""
466 self.buildTransaction()
468 todo = zypp.GetResolvablesToInsDel(self.Z.pool())
469 installed_pkgs = todo._toInstall
472 for pitem in installed_pkgs:
473 if not zypp.isKindPattern(pitem) and \
474 not self.inDeselectPackages(pitem):
475 item = zypp.asKindPackage(pitem)
478 if item.name() in self.check_pkgs:
479 self.check_pkgs.remove(item.name())
481 if not self.install_debuginfo or str(item.arch()) == "noarch":
484 dipkg = self._zyppQueryPackage("%s-debuginfo" % item.name())
486 ditem = zypp.asKindPackage(dipkg)
489 msger.warning("No debuginfo rpm found for: %s" \
493 raise CreatorError('Packages absent in image: %s' % ','.join(self.check_pkgs))
495 # record all pkg and the content
496 localpkgs = self.localpkgs.keys()
499 if pkg.name() in localpkgs:
500 hdr = rpmmisc.readRpmHeader(self.ts, self.localpkgs[pkg.name()])
501 pkg_long_name = misc.RPM_FMT % {
504 'version': hdr['version'],
505 'release': hdr['release']
507 license = hdr['license']
510 pkg_long_name = misc.RPM_FMT % {
513 'version': pkg.edition().version(),
514 'release': pkg.edition().release()
517 license = pkg.license()
519 if license in self.__pkgs_license.keys():
520 self.__pkgs_license[license].append(pkg_long_name)
522 self.__pkgs_license[license] = [pkg_long_name]
524 total_count = len(dlpkgs)
526 download_total_size = sum(map(lambda x: int(x.downloadSize()), dlpkgs))
527 localpkgs = self.localpkgs.keys()
529 msger.info("Checking packages cached ...")
531 # Check if it is cached locally
532 if po.name() in localpkgs:
535 local = self.getLocalPkgPath(po)
536 name = str(po.repoInfo().name())
538 repo = filter(lambda r: r.name == name, self.repos)[0]
541 nocache = repo.nocache if repo else False
543 if os.path.exists(local):
544 if nocache or self.checkPkg(local) !=0:
547 download_total_size -= int(po.downloadSize())
549 cache_avail_size = misc.get_filesystem_avail(self.cachedir)
550 if cache_avail_size < download_total_size:
551 raise CreatorError("No enough space used for downloading.")
553 # record the total size of installed pkgs
554 install_total_size = sum(map(lambda x: int(x.installSize()), dlpkgs))
555 # check needed size before actually download and install
557 # FIXME: for multiple partitions for loop type, check fails
558 # skip the check temporarily
559 #if checksize and install_total_size > checksize:
560 # raise CreatorError("No enough space used for installing, "
561 # "please resize partition size in ks file")
563 download_count = total_count - cached_count
564 msger.info("Packages: %d Total, %d Cached, %d Missed" \
565 % (total_count, cached_count, download_count))
568 if download_count > 0:
569 msger.info("Downloading packages ...")
570 self.downloadPkgs(dlpkgs, download_count)
571 except CreatorError, e:
572 raise CreatorError("Package download failed: %s" %(e,))
575 self.installPkgs(dlpkgs)
576 except (RepoError, RpmError):
579 raise CreatorError("Package installation failed: %s" % (e,))
581 def getVcsInfo(self):
582 if self.__pkgs_vcsinfo:
586 self.__initialize_transaction()
588 mi = self.ts.dbMatch()
590 lname = misc.RPM_FMT % {
593 'version': hdr['version'],
594 'release': hdr['release']
597 self.__pkgs_vcsinfo[lname] = hdr['VCS']
599 # if rpm not support VCS, set to None
600 self.__pkgs_vcsinfo[lname] = None
602 return self.__pkgs_vcsinfo
604 def getAllContent(self):
605 if self.__pkgs_content:
606 return self.__pkgs_content
609 self.__initialize_transaction()
611 mi = self.ts.dbMatch()
613 lname = misc.RPM_FMT % {
616 'version': hdr['version'],
617 'release': hdr['release']
619 self.__pkgs_content[lname] = hdr['FILENAMES']
621 return self.__pkgs_content
623 def getPkgsLicense(self):
624 return self.__pkgs_license
626 def getFilelist(self, pkgname):
631 self.__initialize_transaction()
633 mi = self.ts.dbMatch('name', pkgname)
635 return header['FILENAMES']
637 def __initialize_repo_manager(self):
638 if self.repo_manager:
641 # Clean up repo metadata
642 shutil.rmtree(self.cachedir + "/etc", ignore_errors = True)
643 shutil.rmtree(self.cachedir + "/solv", ignore_errors = True)
644 shutil.rmtree(self.cachedir + "/raw", ignore_errors = True)
646 zypp.KeyRing.setDefaultAccept( zypp.KeyRing.ACCEPT_UNSIGNED_FILE
647 | zypp.KeyRing.ACCEPT_VERIFICATION_FAILED
648 | zypp.KeyRing.ACCEPT_UNKNOWNKEY
649 | zypp.KeyRing.TRUST_KEY_TEMPORARILY
652 self.repo_manager_options = \
653 zypp.RepoManagerOptions(zypp.Pathname(self.instroot))
655 self.repo_manager_options.knownReposPath = \
656 zypp.Pathname(self.cachedir + "/etc/zypp/repos.d")
658 self.repo_manager_options.repoCachePath = \
659 zypp.Pathname(self.cachedir)
661 self.repo_manager_options.repoRawCachePath = \
662 zypp.Pathname(self.cachedir + "/raw")
664 self.repo_manager_options.repoSolvCachePath = \
665 zypp.Pathname(self.cachedir + "/solv")
667 self.repo_manager_options.repoPackagesCachePath = \
668 zypp.Pathname(self.cachedir + "/packages")
670 self.repo_manager = zypp.RepoManager(self.repo_manager_options)
672 def __build_repo_cache(self, name):
673 repo = self.repo_manager.getRepositoryInfo(name)
674 if self.repo_manager.isCached(repo) or not repo.enabled():
677 msger.info('Refreshing repository: %s ...' % name)
678 self.repo_manager.buildCache(repo, zypp.RepoManager.BuildIfNeeded)
680 def __initialize_zypp(self):
684 zconfig = zypp.ZConfig_instance()
686 # Set system architecture
688 zconfig.setSystemArchitecture(zypp.Arch(self.target_arch))
690 msger.info("zypp architecture is <%s>" % zconfig.systemArchitecture())
692 # repoPackagesCachePath is corrected by this
693 self.repo_manager = zypp.RepoManager(self.repo_manager_options)
694 repos = self.repo_manager.knownRepositories()
696 if not repo.enabled():
698 self.repo_manager.loadFromCache(repo)
700 self.Z = zypp.ZYppFactory_instance().getZYpp()
701 self.Z.initializeTarget(zypp.Pathname(self.instroot))
702 self.Z.target().load()
704 def buildTransaction(self):
705 if not self.Z.resolver().resolvePool():
706 probs = self.Z.resolver().problems()
708 for problem in probs:
709 msger.warning("repo problem: %s, %s" \
710 % (problem.description().decode("utf-8"),
711 problem.details().decode("utf-8")))
713 raise RepoError("found %d resolver problem, abort!" \
716 def getLocalPkgPath(self, po):
717 repoinfo = po.repoInfo()
718 cacheroot = repoinfo.packagesPath()
719 location = po.location()
720 rpmpath = str(location.filename())
721 pkgpath = "%s/%s" % (cacheroot, os.path.basename(rpmpath))
724 def installLocal(self, pkg, po=None, updateonly=False):
726 self.__initialize_transaction()
728 solvfile = "%s/.solv" % (self.cachedir)
730 rc, out = runner.runtool([fs_related.find_binary_path("rpms2solv"),
733 f = open(solvfile, "w+")
737 warnmsg = self.repo_manager.loadSolvFile(solvfile,
738 os.path.basename(pkg))
740 msger.warning(warnmsg)
744 msger.warning('Can not get %s solv data.' % pkg)
746 hdr = rpmmisc.readRpmHeader(self.ts, pkg)
747 arch = zypp.Arch(hdr['arch'])
748 sysarch = zypp.Arch(self.target_arch)
750 if arch.compatible_with (sysarch):
751 pkgname = hdr['name']
752 self.localpkgs[pkgname] = pkg
753 self.selectPackage(pkgname)
754 msger.info("Marking %s to be installed" % (pkg))
757 msger.warning("Cannot add package %s to transaction. "
758 "Not a compatible architecture: %s" \
759 % (pkg, hdr['arch']))
761 def downloadPkgs(self, package_objects, count):
762 localpkgs = self.localpkgs.keys()
763 progress_obj = TextProgress(count)
765 for po in package_objects:
766 if po.name() in localpkgs:
769 filename = self.getLocalPkgPath(po)
770 if os.path.exists(filename):
771 if self.checkPkg(filename) == 0:
774 dirn = os.path.dirname(filename)
775 if not os.path.exists(dirn):
778 url = self.get_url(po)
779 proxies = self.get_proxies(po)
782 filename = myurlgrab(url.full, filename, proxies, progress_obj)
787 def preinstallPkgs(self):
789 self.__initialize_transaction()
792 cb = rpmmisc.RPMInstallCallback(self.ts_pre)
793 cb.headmsg = "Preinstall"
794 installlogfile = "%s/__catched_stderr.buf" % (self.instroot)
796 # start to catch stderr output from librpm
797 msger.enable_logstderr(installlogfile)
799 errors = self.ts_pre.run(cb.callback, '')
801 msger.disable_logstderr()
802 self.ts_pre.closeDB()
805 if errors is not None:
807 msger.warning('scriptlet or other non-fatal errors occurred '
808 'during transaction.')
813 raise RepoError('Could not run transaction.')
815 def installPkgs(self, package_objects):
817 self.__initialize_transaction()
820 self._cleanupRpmdbLocks(self.instroot)
821 self._cleanupZyppJunk(self.instroot)
824 for flag in self.probFilterFlags:
826 self.ts.setProbFilter(probfilter)
827 self.ts_pre.setProbFilter(probfilter)
829 localpkgs = self.localpkgs.keys()
831 for po in package_objects:
833 if pkgname in localpkgs:
834 rpmpath = self.localpkgs[pkgname]
836 rpmpath = self.getLocalPkgPath(po)
838 if not os.path.exists(rpmpath):
839 # Maybe it is a local repo
840 rpmuri = self.get_url(po)
841 if rpmuri.startswith("file:/"):
844 if not os.path.exists(rpmpath):
845 raise RpmError("Error: %s doesn't exist" % rpmpath)
847 h = rpmmisc.readRpmHeader(self.ts, rpmpath)
849 if pkgname in self.pre_pkgs:
850 msger.verbose("pre-install package added: %s" % pkgname)
851 self.ts_pre.addInstall(h, rpmpath, 'u')
853 self.ts.addInstall(h, rpmpath, 'u')
855 unresolved_dependencies = self.ts.check()
856 if not unresolved_dependencies:
858 self.preinstallPkgs()
861 cb = rpmmisc.RPMInstallCallback(self.ts)
862 installlogfile = "%s/__catched_stderr.buf" % (self.instroot)
864 # start to catch stderr output from librpm
865 msger.enable_logstderr(installlogfile)
867 errors = self.ts.run(cb.callback, '')
869 msger.disable_logstderr()
873 if errors is not None:
875 msger.warning('scriptlet or other non-fatal errors occurred '
876 'during transaction.')
878 raise CreatorError("mic failes to install some packages")
882 raise RepoError('Could not run transaction.')
885 for pkg, need, needflags, sense, key in unresolved_dependencies:
886 package = '-'.join(pkg)
888 if needflags == rpm.RPMSENSE_LESS:
889 deppkg = ' < '.join(need)
890 elif needflags == rpm.RPMSENSE_EQUAL:
891 deppkg = ' = '.join(need)
892 elif needflags == rpm.RPMSENSE_GREATER:
893 deppkg = ' > '.join(need)
895 deppkg = '-'.join(need)
897 if sense == rpm.RPMDEP_SENSE_REQUIRES:
898 msger.warning("[%s] Requires [%s], which is not provided" \
901 elif sense == rpm.RPMDEP_SENSE_CONFLICTS:
902 msger.warning("[%s] Conflicts with [%s]" % (package, deppkg))
904 raise RepoError("Unresolved dependencies, transaction failed.")
906 def __initialize_transaction(self):
908 self.ts = rpm.TransactionSet(self.instroot)
909 # Set to not verify DSA signatures.
910 self.ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS)
913 self.ts_pre = rpm.TransactionSet(self.instroot)
914 # Just unpack the files, don't run scripts
915 self.ts_pre.setFlags(rpm.RPMTRANS_FLAG_ALLFILES | rpm.RPMTRANS_FLAG_NOSCRIPTS)
916 # Set to not verify DSA signatures.
917 self.ts_pre.setVSFlags(rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS)
919 def checkPkg(self, pkg):
921 if not os.path.exists(pkg):
923 ret = rpmmisc.checkRpmIntegrity('rpm', pkg)
925 msger.warning("package %s is damaged: %s" \
926 % (os.path.basename(pkg), pkg))
930 def _add_prob_flags(self, *flags):
932 if flag not in self.probFilterFlags:
933 self.probFilterFlags.append(flag)
935 def get_proxies(self, pobj):
941 repoinfo = pobj.repoInfo()
942 reponame = "%s" % repoinfo.name()
943 repos = filter(lambda r: r.name == reponame, self.repos)
944 repourl = str(repoinfo.baseUrls()[0])
947 proxy = repos[0].proxy
949 proxy = get_proxy_for(repourl)
951 proxies = {str(repourl.split(':')[0]): str(proxy)}
955 def get_url(self, pobj):
959 name = str(pobj.repoInfo().name())
961 repo = filter(lambda r: r.name == name, self.repos)[0]
965 location = pobj.location()
966 location = str(location.filename())
967 if location.startswith("./"):
968 location = location[2:]
970 return repo.baseurl[0].join(location)
972 def package_url(self, pkgname):
977 (e1, v1, r1) = map(str, [ed1.epoch(), ed1.version(), ed1.release()])
978 (e2, v2, r2) = map(str, [ed2.epoch(), ed2.version(), ed2.release()])
979 return rpm.labelCompare((e1, v1, r1), (e2, v2, r2))
982 self.__initialize_zypp()
985 q.addKind(zypp.ResKind.package)
987 q.addAttribute(zypp.SolvAttr.name, pkgname)
988 items = sorted(q.queryResults(self.Z.pool()),
989 cmp=lambda x,y: cmpEVR(zypp.asKindPackage(x), zypp.asKindPackage(y)),
993 item = zypp.asKindPackage(items[0])
994 url = self.get_url(item)
995 proxies = self.get_proxies(item)
996 return (url, proxies)