[zypp-devel] libzypp related queries
Hi, I had some queries regarding some libzypp functions. 1.) I want to retrieve information regarding packages such as size, version of the package. How can I get this information? 2.) I am using defaultLoadSystem( "/" ) for a particular function. I am getting the error 'zypp instance already created'. I havent called getZypp() anywhere before this line. I just loaded some repositories into the pool using RepoManager, and that was in some other module. How can I avoid this error? Regards,. Saurabh -- To unsubscribe, e-mail: zypp-devel+unsubscribe@opensuse.org To contact the owner, e-mail: zypp-devel+owner@opensuse.org
On Friday 27 July 2012 13:36:04 Saurabh Sood wrote:
Hi, I had some queries regarding some libzypp functions.
1.) I want to retrieve information regarding packages such as size, version of the package. How can I get this information?
Common attributes are available via class ResObject[Resolvable]. To acces if from a PoolItem you can use: ResObject::constPtr PooolItem::resolvable() const; or ResObject::constPtr operator->() const; Example: PooolItem pi; pi.resolvable()->size(); or pi->size(); (or from a sat::Solvable: sat::Solvable s; PooolItem pi( s ); ...) Attributes specific to packages/patch/pattern/product are available via the coresponding classes Package[ResObject[Resolvable]]. To test whether a ResObject actually refers to a e.g. Package use 'isKind': ResObject::constPtr obj; if ( isKind<Package>( obj ) ) or if ( obj->isKind<Package>() ) or if ( obj->isKind( ResKind::package ) ) PooolItem pi; if ( pi->isKind<Package>() ) or if ( pi->isKind( ResKind::package ) To convert use 'asKind': ResObject::constPtr obj; Package::constPtr pkg( asKind<Package>( obj ) ); or Package::constPtr pkg( obj->asKind<Package>() ); PooolItem pi; Package::constPtr pkg( asKind<Package>( pi.resolvable() ) ); or Package::constPtr pkg( pi->asKind<Package>() ); 'asKind' performs a dynamic cast, so it returns a nullptr if the object is not of the right type. 'isKind' simply tests whether 'asKinf' returned a nullptr. In doubt use asKind and test for a nullptr. ResObject::constPtr obj; Package::constPtr pkg( asKind<Package>( obj ) ); // one cast if ( pkg ) { ... ResObject::constPtr obj; if ( isKind<Package>( obj ) ) // 1st cast { Package::constPtr pkg( asKind<Package>( obj ) ); // 2nd cast ...
2.) I am using defaultLoadSystem( "/" ) for a particular function. I am getting the error 'zypp instance already created'. I havent called getZypp() anywhere before this line. I just loaded some repositories into the pool using RepoManager, and that was in some other module.
There are a actions which may call getZypp() internally. You should call defaultLoadSystem before doing anything else, or do the setup manually. -- cu, Michael Andres +------------------------------------------------------------------+ Key fingerprint = 2DFA 5D73 18B1 E7EF A862 27AC 3FB8 9E3A 27C6 B0E4 +------------------------------------------------------------------+ Michael Andres SUSE LINUX Products GmbH, Development, ma@suse.de GF:Jeff Hawn,Jennifer Guild,Felix Imendörffer, HRB16746(AG Nürnberg) Maxfeldstrasse 5, D-90409 Nuernberg, Germany, ++49 (0)911 - 740 53-0 +------------------------------------------------------------------+ -- To unsubscribe, e-mail: zypp-devel+unsubscribe@opensuse.org To contact the owner, e-mail: zypp-devel+owner@opensuse.org
participants (2)
-
Michael Andres
-
Saurabh Sood