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
105 def _cleanupRpmdbLocks(self, installroot):
106 # cleans up temporary files left by bdb so that differing
107 # versions of rpm don't cause problems
109 for f in glob.glob(installroot + "/var/lib/rpm/__db*"):
112 def _cleanupZyppJunk(self, installroot):
114 shutil.rmtree(os.path.join(installroot, '.zypp'))
119 self._cleanupRpmdbLocks(self.instroot)
121 def whatObsolete(self, pkg):
122 query = zypp.PoolQuery()
123 query.addKind(zypp.ResKind.package)
124 query.addAttribute(zypp.SolvAttr.obsoletes, pkg)
125 query.setMatchExact()
126 for pi in query.queryResults(self.Z.pool()):
130 def _zyppQueryPackage(self, pkg):
131 query = zypp.PoolQuery()
132 query.addKind(zypp.ResKind.package)
133 query.addAttribute(zypp.SolvAttr.name,pkg)
134 query.setMatchExact()
135 for pi in query.queryResults(self.Z.pool()):
139 def _splitPkgString(self, pkg):
140 sp = pkg.rsplit(".",1)
145 sysarch = zypp.Arch(self.target_arch)
146 if not zypp.Arch(arch).compatible_with (sysarch):
151 def selectPackage(self, pkg):
152 """Select a given package or package pattern, can be specified
153 with name.arch or name* or *name
157 self.__initialize_zypp()
159 def markPoolItem(obs, pi):
161 pi.status().setToBeInstalled (zypp.ResStatus.USER)
163 obs.status().setToBeInstalled (zypp.ResStatus.USER)
166 # compare criterion: arch compatibility first, then repo
167 # priority, and version last
170 if str(a1) != str(a2):
171 if a1.compatible_with(a2):
175 # Priority of a repository is an integer value between 0 (the
176 # highest priority) and 99 (the lowest priority)
177 pr1 = int(p1.repoInfo().priority())
178 pr2 = int(p2.repoInfo().priority())
186 (e1, v1, r1) = map(str, [ed1.epoch(), ed1.version(), ed1.release()])
187 (e2, v2, r2) = map(str, [ed2.epoch(), ed2.version(), ed2.release()])
188 return rpm.labelCompare((e1, v1, r1), (e2, v2, r2))
191 startx = pkg.startswith("*")
192 endx = pkg.endswith("*")
193 ispattern = startx or endx
194 name, arch = self._splitPkgString(pkg)
197 q.addKind(zypp.ResKind.package)
200 if startx and not endx:
201 pattern = '%s$' % (pkg[1:])
202 if endx and not startx:
203 pattern = '^%s' % (pkg[0:-1])
205 pattern = '%s' % (pkg[1:-1])
207 q.addAttribute(zypp.SolvAttr.name,pattern)
211 q.addAttribute(zypp.SolvAttr.name,name)
215 q.addAttribute(zypp.SolvAttr.name,pkg)
218 q.queryResults(self.Z.pool()),
219 cmp=lambda x,y: cmpEVR(zypp.asKindPackage(x), zypp.asKindPackage(y)),
221 item = zypp.asKindPackage(pitem)
222 if item.name() in self.excpkgs.keys() and \
223 self.excpkgs[item.name()] == item.repoInfo().name():
225 if item.name() in self.incpkgs.keys() and \
226 self.incpkgs[item.name()] != item.repoInfo().name():
230 obspkg = self.whatObsolete(item.name())
232 if arch == str(item.arch()):
233 item.status().setToBeInstalled (zypp.ResStatus.USER)
235 markPoolItem(obspkg, pitem)
239 # Can't match using package name, then search from packge
240 # provides infomation
241 if found == False and not ispattern:
242 q.addAttribute(zypp.SolvAttr.provides, pkg)
243 q.addAttribute(zypp.SolvAttr.name,'')
246 q.queryResults(self.Z.pool()),
247 cmp=lambda x,y: cmpEVR(zypp.asKindPackage(x), zypp.asKindPackage(y)),
249 item = zypp.asKindPackage(pitem)
250 if item.name() in self.excpkgs.keys() and \
251 self.excpkgs[item.name()] == item.repoInfo().name():
253 if item.name() in self.incpkgs.keys() and \
254 self.incpkgs[item.name()] != item.repoInfo().name():
258 obspkg = self.whatObsolete(item.name())
259 markPoolItem(obspkg, pitem)
265 raise CreatorError("Unable to find package: %s" % (pkg,))
267 def inDeselectPackages(self, pitem):
268 """check if specified pacakges are in the list of inDeselectPackages
270 item = zypp.asKindPackage(pitem)
272 for pkg in self.to_deselect:
273 startx = pkg.startswith("*")
274 endx = pkg.endswith("*")
275 ispattern = startx or endx
276 pkgname, pkgarch = self._splitPkgString(pkg)
279 if name == pkgname and str(item.arch()) == pkgarch:
285 if startx and name.endswith(pkg[1:]):
287 if endx and name.startswith(pkg[:-1]):
292 def deselectPackage(self, pkg):
293 """collect packages should not be installed"""
294 self.to_deselect.append(pkg)
296 def selectGroup(self, grp, include = ksparser.GROUP_DEFAULT):
298 self.__initialize_zypp()
301 q.addKind(zypp.ResKind.pattern)
302 for pitem in q.queryResults(self.Z.pool()):
303 item = zypp.asKindPattern(pitem)
304 summary = "%s" % item.summary()
305 name = "%s" % item.name()
306 if name == grp or summary == grp:
308 pitem.status().setToBeInstalled (zypp.ResStatus.USER)
312 if include == ksparser.GROUP_REQUIRED:
314 lambda p: self.deselectPackage(p),
315 grp.default_packages.keys())
319 raise CreatorError("Unable to find pattern: %s" % (grp,))
321 def addRepository(self, name,
325 proxy_username = None,
326 proxy_password = None,
333 # TODO: Handle cost attribute for repos
335 if not self.repo_manager:
336 self.__initialize_repo_manager()
338 if not proxy and url:
339 proxy = get_proxy_for(url)
341 repo = RepositoryStub()
345 repo.proxy_username = proxy_username
346 repo.proxy_password = proxy_password
347 repo.ssl_verify = ssl_verify
348 repo.nocache = nocache
349 repo.baseurl.append(url)
352 self.incpkgs[pkg] = name
355 self.excpkgs[pkg] = name
358 repo.mirrorlist = mirrorlist
360 # Enable gpg check for verifying corrupt packages
362 if priority is not None:
363 # priority 0 has issue in RepoInfo.setPriority
364 repo.priority = priority + 1
367 repo_info = zypp.RepoInfo()
368 repo_info.setAlias(repo.name)
369 repo_info.setName(repo.name)
370 repo_info.setEnabled(repo.enabled)
371 repo_info.setAutorefresh(repo.autorefresh)
372 repo_info.setKeepPackages(repo.keeppackages)
373 baseurl = zypp.Url(repo.baseurl[0])
375 baseurl.setQueryParam("ssl_verify", "no")
377 scheme, host, path, parm, query, frag = urlparse.urlparse(proxy)
379 proxyinfo = host.rsplit(":", 1)
383 if len(proxyinfo) > 1:
386 if proxy.startswith("socks") and len(proxy.rsplit(':', 1)) == 2:
387 host = proxy.rsplit(':', 1)[0]
388 port = proxy.rsplit(':', 1)[1]
390 # parse user/pass from proxy host
391 proxyinfo = host.rsplit("@", 1)
392 if len(proxyinfo) == 2:
394 # Known Issue: If password contains ":", which should be
395 # quoted, for example, use '123%3Aabc' instead of 123:abc
396 userpassinfo = proxyinfo[0].rsplit(":", 1)
397 if len(userpassinfo) == 2:
398 proxy_username = userpassinfo[0]
399 proxy_password = userpassinfo[1]
400 elif len(userpassinfo) == 1:
401 proxy_username = userpassinfo[0]
403 baseurl.setQueryParam ("proxy", host)
404 baseurl.setQueryParam ("proxyport", port)
406 baseurl.setQueryParam ("proxyuser", proxy_username)
408 baseurl.setQueryParam ("proxypass", proxy_password)
410 baseurl.setQueryParam ("proxy", "_none_")
412 repo.baseurl[0] = baseurl.asCompleteString()
413 self.repos.append(repo)
415 repo_info.addBaseUrl(baseurl)
417 if repo.priority is not None:
418 repo_info.setPriority(repo.priority)
420 # this hack is used to change zypp credential file location
421 # the default one is $HOME/.zypp, which cause conflicts when
422 # installing some basic packages, and the location doesn't
423 # have any interface actually, so use a tricky way anyway
425 if 'HOME' in os.environ:
426 homedir = os.environ['HOME']
427 os.environ['HOME'] = '/'
429 os.environ['HOME'] = '/'
431 self.repo_manager.addRepository(repo_info)
433 # save back the $HOME env
435 os.environ['HOME'] = homedir
437 del os.environ['HOME']
439 self.__build_repo_cache(name)
441 except RuntimeError, e:
442 raise CreatorError(str(e))
444 msger.verbose('repo: %s was added' % name)
447 def installHasFile(self, file):
450 def preInstall(self, pkg):
451 self.pre_pkgs.append(pkg)
453 def checkPackage(self, pkg):
454 self.check_pkgs.append(pkg)
456 def runInstall(self, checksize = 0):
457 os.environ["HOME"] = "/"
458 os.environ["LD_PRELOAD"] = ""
459 self.buildTransaction()
461 todo = zypp.GetResolvablesToInsDel(self.Z.pool())
462 installed_pkgs = todo._toInstall
465 for pitem in installed_pkgs:
466 if not zypp.isKindPattern(pitem) and \
467 not self.inDeselectPackages(pitem):
468 item = zypp.asKindPackage(pitem)
471 if item.name() in self.check_pkgs:
472 self.check_pkgs.remove(item.name())
474 if not self.install_debuginfo or str(item.arch()) == "noarch":
477 dipkg = self._zyppQueryPackage("%s-debuginfo" % item.name())
479 ditem = zypp.asKindPackage(dipkg)
482 msger.warning("No debuginfo rpm found for: %s" \
486 raise CreatorError('Packages absent in image: %s' % ','.join(self.check_pkgs))
488 # record all pkg and the content
489 localpkgs = self.localpkgs.keys()
492 if pkg.name() in localpkgs:
493 hdr = rpmmisc.readRpmHeader(self.ts, self.localpkgs[pkg.name()])
494 pkg_long_name = misc.RPM_FMT % {
497 'version': hdr['version'],
498 'release': hdr['release']
500 license = hdr['license']
503 pkg_long_name = misc.RPM_FMT % {
506 'version': pkg.edition().version(),
507 'release': pkg.edition().release()
510 license = pkg.license()
512 if license in self.__pkgs_license.keys():
513 self.__pkgs_license[license].append(pkg_long_name)
515 self.__pkgs_license[license] = [pkg_long_name]
517 total_count = len(dlpkgs)
519 download_total_size = sum(map(lambda x: int(x.downloadSize()), dlpkgs))
520 localpkgs = self.localpkgs.keys()
522 msger.info("Checking packages cached ...")
524 # Check if it is cached locally
525 if po.name() in localpkgs:
528 local = self.getLocalPkgPath(po)
529 name = str(po.repoInfo().name())
531 repo = filter(lambda r: r.name == name, self.repos)[0]
534 nocache = repo.nocache if repo else False
536 if os.path.exists(local):
537 if nocache or self.checkPkg(local) !=0:
540 download_total_size -= int(po.downloadSize())
542 cache_avail_size = misc.get_filesystem_avail(self.cachedir)
543 if cache_avail_size < download_total_size:
544 raise CreatorError("No enough space used for downloading.")
546 # record the total size of installed pkgs
547 install_total_size = sum(map(lambda x: int(x.installSize()), dlpkgs))
548 # check needed size before actually download and install
550 # FIXME: for multiple partitions for loop type, check fails
551 # skip the check temporarily
552 #if checksize and install_total_size > checksize:
553 # raise CreatorError("No enough space used for installing, "
554 # "please resize partition size in ks file")
556 download_count = total_count - cached_count
557 msger.info("Packages: %d Total, %d Cached, %d Missed" \
558 % (total_count, cached_count, download_count))
561 if download_count > 0:
562 msger.info("Downloading packages ...")
563 self.downloadPkgs(dlpkgs, download_count)
565 self.installPkgs(dlpkgs)
567 except (RepoError, RpmError):
570 raise CreatorError("Package installation failed: %s" % (e,))
572 def getVcsInfo(self):
573 if self.__pkgs_vcsinfo:
577 self.__initialize_transaction()
579 mi = self.ts.dbMatch()
581 lname = misc.RPM_FMT % {
584 'version': hdr['version'],
585 'release': hdr['release']
588 self.__pkgs_vcsinfo[lname] = hdr['VCS']
590 # if rpm not support VCS, set to None
591 self.__pkgs_vcsinfo[lname] = None
593 return self.__pkgs_vcsinfo
595 def getAllContent(self):
596 if self.__pkgs_content:
597 return self.__pkgs_content
600 self.__initialize_transaction()
602 mi = self.ts.dbMatch()
604 lname = misc.RPM_FMT % {
607 'version': hdr['version'],
608 'release': hdr['release']
610 self.__pkgs_content[lname] = hdr['FILENAMES']
612 return self.__pkgs_content
614 def getPkgsLicense(self):
615 return self.__pkgs_license
617 def getFilelist(self, pkgname):
622 self.__initialize_transaction()
624 mi = self.ts.dbMatch('name', pkgname)
626 return header['FILENAMES']
628 def __initialize_repo_manager(self):
629 if self.repo_manager:
632 # Clean up repo metadata
633 shutil.rmtree(self.cachedir + "/etc", ignore_errors = True)
634 shutil.rmtree(self.cachedir + "/solv", ignore_errors = True)
635 shutil.rmtree(self.cachedir + "/raw", ignore_errors = True)
637 zypp.KeyRing.setDefaultAccept( zypp.KeyRing.ACCEPT_UNSIGNED_FILE
638 | zypp.KeyRing.ACCEPT_VERIFICATION_FAILED
639 | zypp.KeyRing.ACCEPT_UNKNOWNKEY
640 | zypp.KeyRing.TRUST_KEY_TEMPORARILY
643 self.repo_manager_options = \
644 zypp.RepoManagerOptions(zypp.Pathname(self.instroot))
646 self.repo_manager_options.knownReposPath = \
647 zypp.Pathname(self.cachedir + "/etc/zypp/repos.d")
649 self.repo_manager_options.repoCachePath = \
650 zypp.Pathname(self.cachedir)
652 self.repo_manager_options.repoRawCachePath = \
653 zypp.Pathname(self.cachedir + "/raw")
655 self.repo_manager_options.repoSolvCachePath = \
656 zypp.Pathname(self.cachedir + "/solv")
658 self.repo_manager_options.repoPackagesCachePath = \
659 zypp.Pathname(self.cachedir + "/packages")
661 self.repo_manager = zypp.RepoManager(self.repo_manager_options)
663 def __build_repo_cache(self, name):
664 repo = self.repo_manager.getRepositoryInfo(name)
665 if self.repo_manager.isCached(repo) or not repo.enabled():
668 msger.info('Refreshing repository: %s ...' % name)
669 self.repo_manager.buildCache(repo, zypp.RepoManager.BuildIfNeeded)
671 def __initialize_zypp(self):
675 zconfig = zypp.ZConfig_instance()
677 # Set system architecture
679 zconfig.setSystemArchitecture(zypp.Arch(self.target_arch))
681 msger.info("zypp architecture is <%s>" % zconfig.systemArchitecture())
683 # repoPackagesCachePath is corrected by this
684 self.repo_manager = zypp.RepoManager(self.repo_manager_options)
685 repos = self.repo_manager.knownRepositories()
687 if not repo.enabled():
689 self.repo_manager.loadFromCache(repo)
691 self.Z = zypp.ZYppFactory_instance().getZYpp()
692 self.Z.initializeTarget(zypp.Pathname(self.instroot))
693 self.Z.target().load()
695 def buildTransaction(self):
696 if not self.Z.resolver().resolvePool():
697 probs = self.Z.resolver().problems()
699 for problem in probs:
700 msger.warning("repo problem: %s, %s" \
701 % (problem.description().decode("utf-8"),
702 problem.details().decode("utf-8")))
704 raise RepoError("found %d resolver problem, abort!" \
707 def getLocalPkgPath(self, po):
708 repoinfo = po.repoInfo()
709 cacheroot = repoinfo.packagesPath()
710 location= po.location()
711 rpmpath = str(location.filename())
712 pkgpath = "%s/%s" % (cacheroot, os.path.basename(rpmpath))
715 def installLocal(self, pkg, po=None, updateonly=False):
717 self.__initialize_transaction()
719 solvfile = "%s/.solv" % (self.cachedir)
721 rc, out = runner.runtool([fs_related.find_binary_path("rpms2solv"),
724 f = open(solvfile, "w+")
728 warnmsg = self.repo_manager.loadSolvFile(solvfile,
729 os.path.basename(pkg))
731 msger.warning(warnmsg)
735 msger.warning('Can not get %s solv data.' % pkg)
737 hdr = rpmmisc.readRpmHeader(self.ts, pkg)
738 arch = zypp.Arch(hdr['arch'])
739 sysarch = zypp.Arch(self.target_arch)
741 if arch.compatible_with (sysarch):
742 pkgname = hdr['name']
743 self.localpkgs[pkgname] = pkg
744 self.selectPackage(pkgname)
745 msger.info("Marking %s to be installed" % (pkg))
748 msger.warning("Cannot add package %s to transaction. "
749 "Not a compatible architecture: %s" \
750 % (pkg, hdr['arch']))
752 def downloadPkgs(self, package_objects, count):
753 localpkgs = self.localpkgs.keys()
754 progress_obj = TextProgress(count)
756 for po in package_objects:
757 if po.name() in localpkgs:
760 filename = self.getLocalPkgPath(po)
761 if os.path.exists(filename):
762 if self.checkPkg(filename) == 0:
765 dirn = os.path.dirname(filename)
766 if not os.path.exists(dirn):
769 url = self.get_url(po)
770 proxies = self.get_proxies(po)
773 filename = myurlgrab(url, filename, proxies, progress_obj)
778 def preinstallPkgs(self):
780 self.__initialize_transaction()
783 cb = rpmmisc.RPMInstallCallback(self.ts_pre)
784 cb.headmsg = "Preinstall"
785 installlogfile = "%s/__catched_stderr.buf" % (self.instroot)
787 # start to catch stderr output from librpm
788 msger.enable_logstderr(installlogfile)
790 errors = self.ts_pre.run(cb.callback, '')
792 msger.disable_logstderr()
793 self.ts_pre.closeDB()
796 if errors is not None:
798 msger.warning('scriptlet or other non-fatal errors occurred '
799 'during transaction.')
804 raise RepoError('Could not run transaction.')
806 def installPkgs(self, package_objects):
808 self.__initialize_transaction()
811 self._cleanupRpmdbLocks(self.instroot)
812 self._cleanupZyppJunk(self.instroot)
815 for flag in self.probFilterFlags:
817 self.ts.setProbFilter(probfilter)
818 self.ts_pre.setProbFilter(probfilter)
820 localpkgs = self.localpkgs.keys()
822 for po in package_objects:
824 if pkgname in localpkgs:
825 rpmpath = self.localpkgs[pkgname]
827 rpmpath = self.getLocalPkgPath(po)
829 if not os.path.exists(rpmpath):
830 # Maybe it is a local repo
831 rpmuri = self.get_url(po)
832 if rpmuri.startswith("file:/"):
835 if not os.path.exists(rpmpath):
836 raise RpmError("Error: %s doesn't exist" % rpmpath)
838 h = rpmmisc.readRpmHeader(self.ts, rpmpath)
840 if pkgname in self.pre_pkgs:
841 msger.verbose("pre-install package added: %s" % pkgname)
842 self.ts_pre.addInstall(h, rpmpath, 'u')
844 self.ts.addInstall(h, rpmpath, 'u')
846 unresolved_dependencies = self.ts.check()
847 if not unresolved_dependencies:
849 self.preinstallPkgs()
852 cb = rpmmisc.RPMInstallCallback(self.ts)
853 installlogfile = "%s/__catched_stderr.buf" % (self.instroot)
855 # start to catch stderr output from librpm
856 msger.enable_logstderr(installlogfile)
858 errors = self.ts.run(cb.callback, '')
860 msger.disable_logstderr()
864 if errors is not None:
866 msger.warning('scriptlet or other non-fatal errors occurred '
867 'during transaction.')
872 raise RepoError('Could not run transaction.')
875 for pkg, need, needflags, sense, key in unresolved_dependencies:
876 package = '-'.join(pkg)
878 if needflags == rpm.RPMSENSE_LESS:
879 deppkg = ' < '.join(need)
880 elif needflags == rpm.RPMSENSE_EQUAL:
881 deppkg = ' = '.join(need)
882 elif needflags == rpm.RPMSENSE_GREATER:
883 deppkg = ' > '.join(need)
885 deppkg = '-'.join(need)
887 if sense == rpm.RPMDEP_SENSE_REQUIRES:
888 msger.warning("[%s] Requires [%s], which is not provided" \
891 elif sense == rpm.RPMDEP_SENSE_CONFLICTS:
892 msger.warning("[%s] Conflicts with [%s]" %(package,deppkg))
894 raise RepoError("Unresolved dependencies, transaction failed.")
896 def __initialize_transaction(self):
898 self.ts = rpm.TransactionSet(self.instroot)
899 # Set to not verify DSA signatures.
900 self.ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS)
903 self.ts_pre = rpm.TransactionSet(self.instroot)
904 # Just unpack the files, don't run scripts
905 self.ts_pre.setFlags(rpm.RPMTRANS_FLAG_ALLFILES | rpm.RPMTRANS_FLAG_NOSCRIPTS)
906 # Set to not verify DSA signatures.
907 self.ts_pre.setVSFlags(rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS)
909 def checkPkg(self, pkg):
911 if not os.path.exists(pkg):
913 ret = rpmmisc.checkRpmIntegrity('rpm', pkg)
915 msger.warning("package %s is damaged: %s" \
916 % (os.path.basename(pkg), pkg))
920 def _add_prob_flags(self, *flags):
922 if flag not in self.probFilterFlags:
923 self.probFilterFlags.append(flag)
925 def get_proxies(self, pobj):
931 repoinfo = pobj.repoInfo()
932 reponame = "%s" % repoinfo.name()
933 repos = filter(lambda r: r.name == reponame, self.repos)
934 repourl = str(repoinfo.baseUrls()[0])
937 proxy = repos[0].proxy
939 proxy = get_proxy_for(repourl)
941 proxies = {str(repourl.split(':')[0]): str(proxy)}
945 def get_url(self, pobj):
949 name = str(pobj.repoInfo().name())
951 repo = filter(lambda r: r.name == name, self.repos)[0]
955 baseurl = repo.baseurl[0]
957 index = baseurl.find("?")
959 baseurl = baseurl[:index]
961 location = pobj.location()
962 location = str(location.filename())
963 if location.startswith("./"):
964 location = location[2:]
966 return os.path.join(baseurl, location)
968 def package_url(self, pkgname):
973 (e1, v1, r1) = map(str, [ed1.epoch(), ed1.version(), ed1.release()])
974 (e2, v2, r2) = map(str, [ed2.epoch(), ed2.version(), ed2.release()])
975 return rpm.labelCompare((e1, v1, r1), (e2, v2, r2))
978 self.__initialize_zypp()
981 q.addKind(zypp.ResKind.package)
983 q.addAttribute(zypp.SolvAttr.name, pkgname)
984 items = sorted(q.queryResults(self.Z.pool()),
985 cmp=lambda x,y: cmpEVR(zypp.asKindPackage(x), zypp.asKindPackage(y)),
989 item = zypp.asKindPackage(items[0])
990 url = self.get_url(item)
991 proxies = self.get_proxies(item)
992 return (url, proxies)