[yast-devel] Y2Packager::Resolvable - search by RPM dependencies
Hi all, I have improved the Y2Packager::Resolvable call (and the internally used Pkg.Resolvables call) to allow searching by RPM dependencies (provides, obsoletes, conflicts, requires, recommends, suggests, supplements, enhances). Examples: Just use the dependency name as the additional parameter: Y2Packager::Resolvable.find(kind: :package, provides: "application()") This searches for the exact string. Optionally you can use a regular expression, just add the "_regexp" suffix to the dependency name: Y2Packager::Resolvable.find(kind: :package, obsoletes_regexp: "^yast2-config-") The regular expression is a POSIX extended regular expression, not a Ruby regular expression! The regexp parameter is just passed to the underlying libzypp/libsolv. The filtering happens directly on the C++ level so it's much faster than filtering on the Ruby level. Do not forget to escape regexp metacharacters like []() # seach for autoyast() supplements Y2Packager::Resolvable.find(kind: :package, supplements_regexp: "^autoyast\\(.*\\)") If an invalid regexp is passed then the ArgumentError exception is raised. You can combine more dependencies like "provides" and "obsoletes" in one call (if that makes sense). The result is logical AND, all dependencies must match. To use this new feature you need yast2-pkg-bindings-4.3.0 and yast2-4.3.21 (or newer). The old Pkg.PkgQueryProvides() call has been marked as obsolete. The enhanced Pkg.Resolvables() call is more powerful as it covers also the other dependencies than "Provides" and allows using a regexp. Enjoy! :) -- Ladislav Slezák YaST Developer SUSE LINUX, s.r.o. Corso IIa Křižíkova 148/34 18600 Praha 8 -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
Hello Ladislav, On Mon, 2020-08-31 at 16:28 +0200, Ladislav Slezak wrote:
Hi all,
I have improved the Y2Packager::Resolvable call (and the internally used Pkg.Resolvables call) to allow searching by RPM dependencies (provides, obsoletes, conflicts, requires, recommends, suggests, supplements, enhances).
This is fantastic! Thank you for implementing these! If you don't mind me asking this question: what are your or YaST team's opinion on using yast2-pkg-bindings in a standalone Ruby script? I haven't yet tried this out, but ever since libzypp-*-bindings have been deprecated, I've been looking for an alternative. I really like the yast2-pkg-bindings API implementation and I've dabbled a little bit with it over the years. Would it work in a non-YaST script? If this is not supported or not recommended, then I'll continue to parse the output of "zypper -q --xml ...". :-( Regards, Srinidhi.
Dne 31. 08. 20 v 16:41 Srinidhi B napsal(a):
This is fantastic! Thank you for implementing these!
Welcome!
I really like the yast2-pkg-bindings API implementation and I've dabbled a little bit with it over the years. Would it work in a non-YaST script? If this is not supported or not recommended, then I'll continue to parse the output of "zypper -q --xml ...". :-(
It depends what a "non-YaST script" actually means. If that means a script which does not use UI, is not integrated to YaST control center, etc... then yes, you can use it that way. Actually we already do that at some places, for example this script [1] runs several Pkg calls and serves as a simple unit/integration test in Travis CI. Another example [2] regularly checks whether the packages used/configured by the yast2-http-server package are still present in the distro. So yes, that works pretty well. But if that means running your script without YaST (just with yast2-pkg-bindings and libzypp) then the answer is "no". The yast2-pkg-bindings only provide an API for the old YCP component system, if you want to use it from a Ruby script you need at least the yast2-core and yast2-ruby-bindings packages (and their dependencies). But there is an alternative way, instead of the libzypp bindings you can use the libsolv bindings. Obviously it provides only a subset of the libzypp functionality but maybe it could be enough for your use case. We use it for scanning the available products on the FULL SLE15-SP2 installation medium and their dependencies. We do not use libzypp for that because it is too slow, it has quite big overhead with doing GPG signature checks, building repository caches, etc... for repositories which will not be used in the end (you can choose only one base product to install). See [3] and [4] how we do that. (Of course, after the user selects the base product to install we do the full work via libzypp, ie. check the GPGs, build the cache... so there is no problem with that "out-of-libzypp" step.) The advantage is then you do not rely on YaST at all and you can write a real standalone script. Just a note at the end: libsolv is a plain C library and its Ruby bindings do not hide that fact much. If you look at some examples [5] sometimes it feels like a C code written in Ruby... HTH, Ladislav [1] https://github.com/yast/yast-pkg-bindings/blob/master/smoke_test_run.rb [2] https://github.com/yast/yast-http-server/blob/master/travis_package_check.rb [3] https://github.com/yast/yast-packager/blob/master/src/lib/y2packager/solvabl... [4] https://github.com/yast/yast-packager/blob/master/src/lib/y2packager/product... [5] https://github.com/openSUSE/libsolv/blob/master/examples/rbsolv -- Ladislav Slezák YaST Developer SUSE LINUX, s.r.o. Corso IIa Křižíkova 148/34 18600 Praha 8 -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
participants (2)
-
Ladislav Slezak
-
Srinidhi B