Re: [zypp-devel] Category filter for zypper patch

Patch for libzypp giving external access to the category string/enum mapping. diff --git a/tests/zypp/CMakeLists.txt b/tests/zypp/CMakeLists.txt index 2154389..487d57f 100644 --- a/tests/zypp/CMakeLists.txt +++ b/tests/zypp/CMakeLists.txt @@ -20,6 +20,7 @@ ADD_TESTS( KeyRing Locks MediaSetAccess + Patch PathInfo PluginFrame PoolQuery diff --git a/tests/zypp/Patch_test.cc b/tests/zypp/Patch_test.cc new file mode 100644 index 0000000..4f94dbc --- /dev/null +++ b/tests/zypp/Patch_test.cc @@ -0,0 +1,18 @@ +#include "zypp/Patch.h" + +#include <string> +#include <boost/test/auto_unit_test.hpp> + +using namespace zypp; +using namespace std; + + +BOOST_AUTO_TEST_CASE(patch_test) +{ + BOOST_CHECK_EQUAL(Patch::categoryEnum("security"), Patch::CAT_SECURITY); + BOOST_CHECK_EQUAL(Patch::categoryEnum("feature"), Patch::CAT_OPTIONAL); + BOOST_CHECK_EQUAL(Patch::categoryEnum("foobar"), Patch::CAT_OTHER); + + BOOST_CHECK_EQUAL(Patch::categoryString(Patch::CAT_RECOMMENDED), "recommended"); + BOOST_CHECK_EQUAL(Patch::categoryString(Patch::categoryEnum("bugfix")), "recommended"); +} diff --git a/zypp/Patch.cc b/zypp/Patch.cc index 892d6d1..14f4f69 100644 --- a/zypp/Patch.cc +++ b/zypp/Patch.cc @@ -46,7 +46,7 @@ namespace zypp // /////////////////////////////////////////////////////////////////// - Patch::Category Patch::categoryEnum() const + Patch::Category Patch::categoryEnum(const std::string& catstring) { static const IdString cat_yast ( "yast" ); static const IdString cat_security ( "security" ); @@ -58,7 +58,7 @@ namespace zypp static const IdString cat_document ( "document" ); // patch category is not poolized in the solv file (i.e. an IdString) ;( - IdString cat( sat::LookupAttr( sat::SolvAttr::patchcategory, satSolvable() ).begin().c_str() ); + IdString cat(catstring); if ( cat == cat_yast ) return CAT_YAST; @@ -74,6 +74,34 @@ namespace zypp return CAT_OTHER; } + std::string Patch::categoryString(const Patch::Category& catenum) + { + switch(catenum) + { + case Patch::CAT_YAST: + return "yast"; + case Patch::CAT_SECURITY: + return "security"; + case Patch::CAT_RECOMMENDED: + return "recommended"; + case Patch::CAT_OPTIONAL: + return "optional"; + case Patch::CAT_DOCUMENT: + return "document"; + case Patch::CAT_OTHER: + return "other"; + default: + // just in case + return ""; + } + } + + Patch::Category Patch::categoryEnum() const + { return categoryEnum( sat::LookupAttr(sat::SolvAttr::patchcategory, satSolvable()).begin().c_str() ); } + + std::string Patch::categoryString() const + { return categoryString(categoryEnum()); } + std::string Patch::message( const Locale & lang_r ) const { return lookupStrAttribute( sat::SolvAttr::message, lang_r ); } diff --git a/zypp/Patch.h b/zypp/Patch.h index 867e506..ad2f14c 100644 --- a/zypp/Patch.h +++ b/zypp/Patch.h @@ -14,6 +14,7 @@ #include "zypp/sat/SolvAttr.h" #include "zypp/ResObject.h" +#include <string> /////////////////////////////////////////////////////////////////// namespace zypp @@ -65,12 +66,27 @@ namespace zypp */ std::string category() const; + /** Patch category from string as enum of wellknown categories. + * Unknown values are mapped to \ref CAT_OTHER. + */ + static Patch::Category categoryEnum(const std::string& catstring); + /** Patch category as enum of wellknown categories. * Unknown values are mapped to \ref CAT_OTHER. */ Category categoryEnum() const; /** + * Patch category string representation of the given enum + */ + static std::string categoryString(const Patch::Category& catenum); + + /** + * Patch category string representation + */ + std::string categoryString() const; + + /** * Does the system need to reboot to finish the update process? */ bool rebootSuggested() const; -- To unsubscribe, e-mail: zypp-devel+unsubscribe@opensuse.org For additional commands, e-mail: zypp-devel+help@opensuse.org
participants (1)
-
Dominik Heidler