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):
58 self.cachedir = cachedir
59 self.instroot = instroot
60 self.target_arch = target_arch
62 self.__pkgs_license = {}
63 self.__pkgs_content = {}
64 self.__pkgs_vcsinfo = {}
68 self.repo_manager = None
69 self.repo_manager_options = None
77 self.probFilterFlags = [ rpm.RPMPROB_FILTER_OLDPACKAGE,
78 rpm.RPMPROB_FILTER_REPLACEPKG ]
80 self.has_prov_query = True
81 self.install_debuginfo = False
83 def doFileLogSetup(self, uid, logfile):
84 # don't do the file log for the livecd as it can lead to open fds
85 # being left and an inability to clean up after ourself
102 if not os.path.exists("/etc/fedora-release") and \
103 not os.path.exists("/etc/meego-release"):
104 for i in range(3, os.sysconf("SC_OPEN_MAX")):
113 def _cleanupRpmdbLocks(self, installroot):
114 # cleans up temporary files left by bdb so that differing
115 # versions of rpm don't cause problems
117 for f in glob.glob(installroot + "/var/lib/rpm/__db*"):
120 def _cleanupZyppJunk(self, installroot):
122 shutil.rmtree(os.path.join(installroot, '.zypp'))
127 self._cleanupRpmdbLocks(self.instroot)
129 def whatObsolete(self, pkg):
130 query = zypp.PoolQuery()
131 query.addKind(zypp.ResKind.package)
132 query.addAttribute(zypp.SolvAttr.obsoletes, pkg)
133 query.setMatchExact()
134 for pi in query.queryResults(self.Z.pool()):
138 def _zyppQueryPackage(self, pkg):
139 query = zypp.PoolQuery()
140 query.addKind(zypp.ResKind.package)
141 query.addAttribute(zypp.SolvAttr.name,pkg)
142 query.setMatchExact()
143 for pi in query.queryResults(self.Z.pool()):
147 def _splitPkgString(self, pkg):
148 sp = pkg.rsplit(".",1)
153 sysarch = zypp.Arch(self.target_arch)
154 if not zypp.Arch(arch).compatible_with (sysarch):
159 def selectPackage(self, pkg):
160 """Select a given package or package pattern, can be specified
161 with name.arch or name* or *name
165 self.__initialize_zypp()
167 def markPoolItem(obs, pi):
169 pi.status().setToBeInstalled (zypp.ResStatus.USER)
171 obs.status().setToBeInstalled (zypp.ResStatus.USER)
174 # compare criterion: arch compatibility first, then repo
175 # priority, and version last
178 if str(a1) != str(a2):
179 if a1.compatible_with(a2):
183 # Priority of a repository is an integer value between 0 (the
184 # highest priority) and 99 (the lowest priority)
185 pr1 = int(p1.repoInfo().priority())
186 pr2 = int(p2.repoInfo().priority())
194 (e1, v1, r1) = map(str, [ed1.epoch(), ed1.version(), ed1.release()])
195 (e2, v2, r2) = map(str, [ed2.epoch(), ed2.version(), ed2.release()])
196 return rpm.labelCompare((e1, v1, r1), (e2, v2, r2))
199 startx = pkg.startswith("*")
200 endx = pkg.endswith("*")
201 ispattern = startx or endx
202 name, arch = self._splitPkgString(pkg)
205 q.addKind(zypp.ResKind.package)
208 if startx and not endx:
209 pattern = '%s$' % (pkg[1:])
210 if endx and not startx:
211 pattern = '^%s' % (pkg[0:-1])
213 pattern = '%s' % (pkg[1:-1])
215 q.addAttribute(zypp.SolvAttr.name,pattern)
219 q.addAttribute(zypp.SolvAttr.name,name)
223 q.addAttribute(zypp.SolvAttr.name,pkg)
226 q.queryResults(self.Z.pool()),
227 cmp=lambda x,y: cmpEVR(zypp.asKindPackage(x), zypp.asKindPackage(y)),
229 item = zypp.asKindPackage(pitem)
230 if item.name() in self.excpkgs.keys() and \
231 self.excpkgs[item.name()] == item.repoInfo().name():
233 if item.name() in self.incpkgs.keys() and \
234 self.incpkgs[item.name()] != item.repoInfo().name():
238 obspkg = self.whatObsolete(item.name())
240 if arch == str(item.arch()):
241 item.status().setToBeInstalled (zypp.ResStatus.USER)
243 markPoolItem(obspkg, pitem)
247 # Can't match using package name, then search from packge
248 # provides infomation
249 if found == False and not ispattern:
250 q.addAttribute(zypp.SolvAttr.provides, pkg)
251 q.addAttribute(zypp.SolvAttr.name,'')
254 q.queryResults(self.Z.pool()),
255 cmp=lambda x,y: cmpEVR(zypp.asKindPackage(x), zypp.asKindPackage(y)),
257 item = zypp.asKindPackage(pitem)
258 if item.name() in self.excpkgs.keys() and \
259 self.excpkgs[item.name()] == item.repoInfo().name():
261 if item.name() in self.incpkgs.keys() and \
262 self.incpkgs[item.name()] != item.repoInfo().name():
266 obspkg = self.whatObsolete(item.name())
267 markPoolItem(obspkg, pitem)
273 raise CreatorError("Unable to find package: %s" % (pkg,))
275 def inDeselectPackages(self, pitem):
276 """check if specified pacakges are in the list of inDeselectPackages
278 item = zypp.asKindPackage(pitem)
280 for pkg in self.to_deselect:
281 startx = pkg.startswith("*")
282 endx = pkg.endswith("*")
283 ispattern = startx or endx
284 pkgname, pkgarch = self._splitPkgString(pkg)
287 if name == pkgname and str(item.arch()) == pkgarch:
293 if startx and name.endswith(pkg[1:]):
295 if endx and name.startswith(pkg[:-1]):
300 def deselectPackage(self, pkg):
301 """collect packages should not be installed"""
302 self.to_deselect.append(pkg)
304 def selectGroup(self, grp, include = ksparser.GROUP_DEFAULT):
306 self.__initialize_zypp()
309 q.addKind(zypp.ResKind.pattern)
310 for pitem in q.queryResults(self.Z.pool()):
311 item = zypp.asKindPattern(pitem)
312 summary = "%s" % item.summary()
313 name = "%s" % item.name()
314 if name == grp or summary == grp:
316 pitem.status().setToBeInstalled (zypp.ResStatus.USER)
320 if include == ksparser.GROUP_REQUIRED:
322 lambda p: self.deselectPackage(p),
323 grp.default_packages.keys())
327 raise CreatorError("Unable to find pattern: %s" % (grp,))
329 def addRepository(self, name,
333 proxy_username = None,
334 proxy_password = None,
341 # TODO: Handle cost attribute for repos
343 if not self.repo_manager:
344 self.__initialize_repo_manager()
346 if not proxy and url:
347 proxy = get_proxy_for(url)
349 repo = RepositoryStub()
353 repo.proxy_username = proxy_username
354 repo.proxy_password = proxy_password
355 repo.ssl_verify = ssl_verify
356 repo.nocache = nocache
357 repo.baseurl.append(url)
360 self.incpkgs[pkg] = name
363 self.excpkgs[pkg] = name
365 # check LICENSE files
366 if not rpmmisc.checkRepositoryEULA(name, repo):
367 msger.warning('skip repo:%s for failed EULA confirmation' % name)
371 repo.mirrorlist = mirrorlist
373 # Enable gpg check for verifying corrupt packages
375 if priority is not None:
376 # priority 0 has issue in RepoInfo.setPriority
377 repo.priority = priority + 1
380 repo_info = zypp.RepoInfo()
381 repo_info.setAlias(repo.name)
382 repo_info.setName(repo.name)
383 repo_info.setEnabled(repo.enabled)
384 repo_info.setAutorefresh(repo.autorefresh)
385 repo_info.setKeepPackages(repo.keeppackages)
386 baseurl = zypp.Url(repo.baseurl[0])
388 baseurl.setQueryParam("ssl_verify", "no")
390 scheme, host, path, parm, query, frag = urlparse.urlparse(proxy)
392 proxyinfo = host.split(":")
396 if len(proxyinfo) > 1:
399 if proxy.startswith("socks") and len(proxy.rsplit(':', 1)) == 2:
400 host = proxy.rsplit(':', 1)[0]
401 port = proxy.rsplit(':', 1)[1]
403 baseurl.setQueryParam ("proxy", host)
404 baseurl.setQueryParam ("proxyport", port)
406 repo.baseurl[0] = baseurl.asCompleteString()
407 self.repos.append(repo)
409 repo_info.addBaseUrl(baseurl)
411 if repo.priority is not None:
412 repo_info.setPriority(repo.priority)
414 # this hack is used to change zypp credential file location
415 # the default one is $HOME/.zypp, which cause conflicts when
416 # installing some basic packages, and the location doesn't
417 # have any interface actually, so use a tricky way anyway
419 if 'HOME' in os.environ:
420 homedir = os.environ['HOME']
421 os.environ['HOME'] = '/'
423 os.environ['HOME'] = '/'
425 self.repo_manager.addRepository(repo_info)
427 # save back the $HOME env
429 os.environ['HOME'] = homedir
431 del os.environ['HOME']
433 self.__build_repo_cache(name)
435 except RuntimeError, e:
436 raise CreatorError(str(e))
438 msger.verbose('repo: %s was added' % name)
441 def installHasFile(self, file):
444 def preInstall(self, pkg):
445 self.pre_pkgs.append(pkg)
447 def checkPackage(self, pkg):
448 self.check_pkgs.append(pkg)
450 def runInstall(self, checksize = 0):
451 os.environ["HOME"] = "/"
452 os.environ["LD_PRELOAD"] = ""
453 self.buildTransaction()
455 todo = zypp.GetResolvablesToInsDel(self.Z.pool())
456 installed_pkgs = todo._toInstall
459 for pitem in installed_pkgs:
460 if not zypp.isKindPattern(pitem) and \
461 not self.inDeselectPackages(pitem):
462 item = zypp.asKindPackage(pitem)
465 if item.name() in self.check_pkgs:
466 self.check_pkgs.remove(item.name())
468 if not self.install_debuginfo or str(item.arch()) == "noarch":
471 dipkg = self._zyppQueryPackage("%s-debuginfo" % item.name())
473 ditem = zypp.asKindPackage(dipkg)
476 msger.warning("No debuginfo rpm found for: %s" \
480 raise CreatorError('Packages absent in image: %s' % ','.join(self.check_pkgs))
482 # record all pkg and the content
483 localpkgs = self.localpkgs.keys()
486 if pkg.name() in localpkgs:
487 hdr = rpmmisc.readRpmHeader(self.ts, self.localpkgs[pkg.name()])
488 pkg_long_name = misc.RPM_FMT % {
491 'version': hdr['version'],
492 'release': hdr['release']
494 license = hdr['license']
497 pkg_long_name = misc.RPM_FMT % {
500 'version': pkg.edition().version(),
501 'release': pkg.edition().release()
504 license = pkg.license()
506 if license in self.__pkgs_license.keys():
507 self.__pkgs_license[license].append(pkg_long_name)
509 self.__pkgs_license[license] = [pkg_long_name]
511 total_count = len(dlpkgs)
513 download_total_size = sum(map(lambda x: int(x.downloadSize()), dlpkgs))
514 localpkgs = self.localpkgs.keys()
516 msger.info("Checking packages cached ...")
518 # Check if it is cached locally
519 if po.name() in localpkgs:
522 local = self.getLocalPkgPath(po)
523 name = str(po.repoInfo().name())
525 repo = filter(lambda r: r.name == name, self.repos)[0]
528 nocache = repo.nocache if repo else False
530 if os.path.exists(local):
531 if nocache or self.checkPkg(local) !=0:
534 download_total_size -= int(po.downloadSize())
536 cache_avail_size = misc.get_filesystem_avail(self.cachedir)
537 if cache_avail_size < download_total_size:
538 raise CreatorError("No enough space used for downloading.")
540 # record the total size of installed pkgs
541 install_total_size = sum(map(lambda x: int(x.installSize()), dlpkgs))
542 # check needed size before actually download and install
544 # FIXME: for multiple partitions for loop type, check fails
545 # skip the check temporarily
546 #if checksize and install_total_size > checksize:
547 # raise CreatorError("No enough space used for installing, "
548 # "please resize partition size in ks file")
550 download_count = total_count - cached_count
551 msger.info("Packages: %d Total, %d Cached, %d Missed" \
552 % (total_count, cached_count, download_count))
555 if download_count > 0:
556 msger.info("Downloading packages ...")
557 self.downloadPkgs(dlpkgs, download_count)
559 self.installPkgs(dlpkgs)
561 except (RepoError, RpmError):
564 raise CreatorError("Package installation failed: %s" % (e,))
566 def getVcsInfo(self):
567 if self.__pkgs_vcsinfo:
571 self.__initialize_transaction()
573 mi = self.ts.dbMatch()
575 lname = misc.RPM_FMT % {
578 'version': hdr['version'],
579 'release': hdr['release']
582 self.__pkgs_vcsinfo[lname] = hdr['VCS']
584 # if rpm not support VCS, set to None
585 self.__pkgs_vcsinfo[lname] = None
587 return self.__pkgs_vcsinfo
589 def getAllContent(self):
590 if self.__pkgs_content:
591 return self.__pkgs_content
594 self.__initialize_transaction()
596 mi = self.ts.dbMatch()
598 lname = misc.RPM_FMT % {
601 'version': hdr['version'],
602 'release': hdr['release']
604 self.__pkgs_content[lname] = hdr['FILENAMES']
606 return self.__pkgs_content
608 def getPkgsLicense(self):
609 return self.__pkgs_license
611 def getFilelist(self, pkgname):
616 self.__initialize_transaction()
618 mi = self.ts.dbMatch('name', pkgname)
620 return header['FILENAMES']
622 def __initialize_repo_manager(self):
623 if self.repo_manager:
626 # Clean up repo metadata
627 shutil.rmtree(self.cachedir + "/etc", ignore_errors = True)
628 shutil.rmtree(self.cachedir + "/solv", ignore_errors = True)
629 shutil.rmtree(self.cachedir + "/raw", ignore_errors = True)
631 zypp.KeyRing.setDefaultAccept( zypp.KeyRing.ACCEPT_UNSIGNED_FILE
632 | zypp.KeyRing.ACCEPT_VERIFICATION_FAILED
633 | zypp.KeyRing.ACCEPT_UNKNOWNKEY
634 | zypp.KeyRing.TRUST_KEY_TEMPORARILY
637 self.repo_manager_options = \
638 zypp.RepoManagerOptions(zypp.Pathname(self.instroot))
640 self.repo_manager_options.knownReposPath = \
641 zypp.Pathname(self.cachedir + "/etc/zypp/repos.d")
643 self.repo_manager_options.repoCachePath = \
644 zypp.Pathname(self.cachedir)
646 self.repo_manager_options.repoRawCachePath = \
647 zypp.Pathname(self.cachedir + "/raw")
649 self.repo_manager_options.repoSolvCachePath = \
650 zypp.Pathname(self.cachedir + "/solv")
652 self.repo_manager_options.repoPackagesCachePath = \
653 zypp.Pathname(self.cachedir + "/packages")
655 self.repo_manager = zypp.RepoManager(self.repo_manager_options)
657 def __build_repo_cache(self, name):
658 repo = self.repo_manager.getRepositoryInfo(name)
659 if self.repo_manager.isCached(repo) or not repo.enabled():
662 msger.info('Refreshing repository: %s ...' % name)
663 self.repo_manager.buildCache(repo, zypp.RepoManager.BuildIfNeeded)
665 def __initialize_zypp(self):
669 zconfig = zypp.ZConfig_instance()
671 # Set system architecture
673 zconfig.setSystemArchitecture(zypp.Arch(self.target_arch))
675 msger.info("zypp architecture is <%s>" % zconfig.systemArchitecture())
677 # repoPackagesCachePath is corrected by this
678 self.repo_manager = zypp.RepoManager(self.repo_manager_options)
679 repos = self.repo_manager.knownRepositories()
681 if not repo.enabled():
683 self.repo_manager.loadFromCache(repo)
685 self.Z = zypp.ZYppFactory_instance().getZYpp()
686 self.Z.initializeTarget(zypp.Pathname(self.instroot))
687 self.Z.target().load()
689 def buildTransaction(self):
690 if not self.Z.resolver().resolvePool():
691 probs = self.Z.resolver().problems()
693 for problem in probs:
694 msger.warning("repo problem: %s, %s" \
695 % (problem.description().decode("utf-8"),
696 problem.details().decode("utf-8")))
698 raise RepoError("found %d resolver problem, abort!" \
701 def getLocalPkgPath(self, po):
702 repoinfo = po.repoInfo()
703 cacheroot = repoinfo.packagesPath()
704 location= po.location()
705 rpmpath = str(location.filename())
706 pkgpath = "%s/%s" % (cacheroot, os.path.basename(rpmpath))
709 def installLocal(self, pkg, po=None, updateonly=False):
711 self.__initialize_transaction()
713 solvfile = "%s/.solv" % (self.cachedir)
715 rc, out = runner.runtool([fs_related.find_binary_path("rpms2solv"),
718 f = open(solvfile, "w+")
722 warnmsg = self.repo_manager.loadSolvFile(solvfile,
723 os.path.basename(pkg))
725 msger.warning(warnmsg)
729 msger.warning('Can not get %s solv data.' % pkg)
731 hdr = rpmmisc.readRpmHeader(self.ts, pkg)
732 arch = zypp.Arch(hdr['arch'])
733 sysarch = zypp.Arch(self.target_arch)
735 if arch.compatible_with (sysarch):
736 pkgname = hdr['name']
737 self.localpkgs[pkgname] = pkg
738 self.selectPackage(pkgname)
739 msger.info("Marking %s to be installed" % (pkg))
742 msger.warning("Cannot add package %s to transaction. "
743 "Not a compatible architecture: %s" \
744 % (pkg, hdr['arch']))
746 def downloadPkgs(self, package_objects, count):
747 localpkgs = self.localpkgs.keys()
748 progress_obj = TextProgress(count)
750 for po in package_objects:
751 if po.name() in localpkgs:
754 filename = self.getLocalPkgPath(po)
755 if os.path.exists(filename):
756 if self.checkPkg(filename) == 0:
759 dirn = os.path.dirname(filename)
760 if not os.path.exists(dirn):
763 url = self.get_url(po)
764 proxies = self.get_proxies(po)
767 filename = myurlgrab(url, filename, proxies, progress_obj)
772 def preinstallPkgs(self):
774 self.__initialize_transaction()
777 cb = rpmmisc.RPMInstallCallback(self.ts_pre)
778 cb.headmsg = "Preinstall"
779 installlogfile = "%s/__catched_stderr.buf" % (self.instroot)
781 # start to catch stderr output from librpm
782 msger.enable_logstderr(installlogfile)
784 errors = self.ts_pre.run(cb.callback, '')
786 msger.disable_logstderr()
787 self.ts_pre.closeDB()
790 if errors is not None:
792 msger.warning('scriptlet or other non-fatal errors occurred '
793 'during transaction.')
798 raise RepoError('Could not run transaction.')
800 def installPkgs(self, package_objects):
802 self.__initialize_transaction()
805 self._cleanupRpmdbLocks(self.instroot)
806 self._cleanupZyppJunk(self.instroot)
809 for flag in self.probFilterFlags:
811 self.ts.setProbFilter(probfilter)
812 self.ts_pre.setProbFilter(probfilter)
814 localpkgs = self.localpkgs.keys()
816 for po in package_objects:
818 if pkgname in localpkgs:
819 rpmpath = self.localpkgs[pkgname]
821 rpmpath = self.getLocalPkgPath(po)
823 if not os.path.exists(rpmpath):
824 # Maybe it is a local repo
825 rpmuri = self.get_url(po)
826 if rpmuri.startswith("file:/"):
829 if not os.path.exists(rpmpath):
830 raise RpmError("Error: %s doesn't exist" % rpmpath)
832 h = rpmmisc.readRpmHeader(self.ts, rpmpath)
834 if pkgname in self.pre_pkgs:
835 msger.verbose("pre-install package added: %s" % pkgname)
836 self.ts_pre.addInstall(h, rpmpath, 'u')
838 self.ts.addInstall(h, rpmpath, 'u')
840 unresolved_dependencies = self.ts.check()
841 if not unresolved_dependencies:
843 self.preinstallPkgs()
846 cb = rpmmisc.RPMInstallCallback(self.ts)
847 installlogfile = "%s/__catched_stderr.buf" % (self.instroot)
849 # start to catch stderr output from librpm
850 msger.enable_logstderr(installlogfile)
852 errors = self.ts.run(cb.callback, '')
854 msger.disable_logstderr()
858 if errors is not None:
860 msger.warning('scriptlet or other non-fatal errors occurred '
861 'during transaction.')
866 raise RepoError('Could not run transaction.')
869 for pkg, need, needflags, sense, key in unresolved_dependencies:
870 package = '-'.join(pkg)
872 if needflags == rpm.RPMSENSE_LESS:
873 deppkg = ' < '.join(need)
874 elif needflags == rpm.RPMSENSE_EQUAL:
875 deppkg = ' = '.join(need)
876 elif needflags == rpm.RPMSENSE_GREATER:
877 deppkg = ' > '.join(need)
879 deppkg = '-'.join(need)
881 if sense == rpm.RPMDEP_SENSE_REQUIRES:
882 msger.warning("[%s] Requires [%s], which is not provided" \
885 elif sense == rpm.RPMDEP_SENSE_CONFLICTS:
886 msger.warning("[%s] Conflicts with [%s]" %(package,deppkg))
888 raise RepoError("Unresolved dependencies, transaction failed.")
890 def __initialize_transaction(self):
892 self.ts = rpm.TransactionSet(self.instroot)
893 # Set to not verify DSA signatures.
894 self.ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS)
897 self.ts_pre = rpm.TransactionSet(self.instroot)
898 # Just unpack the files, don't run scripts
899 self.ts_pre.setFlags(rpm.RPMTRANS_FLAG_ALLFILES | rpm.RPMTRANS_FLAG_NOSCRIPTS)
900 # Set to not verify DSA signatures.
901 self.ts_pre.setVSFlags(rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS)
903 def checkPkg(self, pkg):
905 if not os.path.exists(pkg):
907 ret = rpmmisc.checkRpmIntegrity('rpm', pkg)
909 msger.warning("package %s is damaged: %s" \
910 % (os.path.basename(pkg), pkg))
914 def _add_prob_flags(self, *flags):
916 if flag not in self.probFilterFlags:
917 self.probFilterFlags.append(flag)
919 def get_proxies(self, pobj):
925 repoinfo = pobj.repoInfo()
926 reponame = "%s" % repoinfo.name()
927 repos = filter(lambda r: r.name == reponame, self.repos)
928 repourl = str(repoinfo.baseUrls()[0])
931 proxy = repos[0].proxy
933 proxy = get_proxy_for(repourl)
935 proxies = {str(repourl.split(':')[0]): str(proxy)}
939 def get_url(self, pobj):
943 name = str(pobj.repoInfo().name())
945 repo = filter(lambda r: r.name == name, self.repos)[0]
949 baseurl = repo.baseurl[0]
951 index = baseurl.find("?")
953 baseurl = baseurl[:index]
955 location = pobj.location()
956 location = str(location.filename())
957 if location.startswith("./"):
958 location = location[2:]
960 return os.path.join(baseurl, location)
962 def package_url(self, pkgname):
967 (e1, v1, r1) = map(str, [ed1.epoch(), ed1.version(), ed1.release()])
968 (e2, v2, r2) = map(str, [ed2.epoch(), ed2.version(), ed2.release()])
969 return rpm.labelCompare((e1, v1, r1), (e2, v2, r2))
972 self.__initialize_zypp()
975 q.addKind(zypp.ResKind.package)
977 q.addAttribute(zypp.SolvAttr.name, pkgname)
978 items = sorted(q.queryResults(self.Z.pool()),
979 cmp=lambda x,y: cmpEVR(zypp.asKindPackage(x), zypp.asKindPackage(y)),
983 item = zypp.asKindPackage(items[0])
984 url = self.get_url(item)
985 proxies = self.get_proxies(item)
986 return (url, proxies)