From: Michael Andres Date: Wed, 7 Jul 2010 10:54:03 +0000 (+0200) Subject: Cleanup in Testcase X-Git-Tag: 7.8.0~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6d293ec75f19741fdd0cb4be5d775344fbb7c3e4;p=platform%2Fupstream%2Flibzypp.git Cleanup in Testcase --- diff --git a/zypp/solver/detail/Testcase.cc b/zypp/solver/detail/Testcase.cc index 0ce55fedc..c5ff70c1f 100644 --- a/zypp/solver/detail/Testcase.cc +++ b/zypp/solver/detail/Testcase.cc @@ -17,20 +17,22 @@ #include "zypp/solver/detail/Testcase.h" #include "zypp/base/Logger.h" #include "zypp/base/LogControl.h" -#include "zypp/ZConfig.h" -#include "zypp/PathInfo.h" -#include "zypp/Product.h" -#include "zypp/Package.h" -#include "zypp/Edition.h" -#include "zypp/parser/xml/XmlEscape.h" +#include "zypp/base/GzStream.h" #include "zypp/base/String.h" #include "zypp/base/PtrTypes.h" -#include "zypp/Capabilities.h" -#include "zypp/sat/Solvable.h" +#include "zypp/base/NonCopyable.h" +#include "zypp/base/ReferenceCounted.h" + +#include "zypp/parser/xml/XmlEscape.h" + +#include "zypp/ZConfig.h" +#include "zypp/PathInfo.h" +#include "zypp/ResPool.h" +#include "zypp/Repository.h" + #include "zypp/sat/detail/PoolImpl.h" #include "zypp/solver/detail/SystemCheck.h" - ///////////////////////////////////////////////////////////////////////// namespace zypp { /////////////////////////////////////////////////////////////////////// @@ -47,7 +49,7 @@ namespace zypp using namespace std; using namespace zypp::str; -IMPL_PTR_TYPE(HelixResolvable); +//--------------------------------------------------------------------------- inline std::string xml_escape( const std::string &text ) { @@ -68,7 +70,6 @@ inline std::string xml_tag_enclose( const std::string &text, const std::string & return result; } - template std::string helixXML( const T &obj ); //undefined @@ -210,182 +211,34 @@ std::string helixXML( const PoolItem &item ) return str.str(); } -//--------------------------------------------------------------------------- - -Testcase::Testcase() - :dumpPath("/var/log/YaST2/solverTestcase") -{ -} - -Testcase::Testcase(const std::string & path) - :dumpPath(path) -{ -} - - -Testcase::~Testcase() -{ -} - - -bool Testcase::createTestcasePool(const ResPool &pool) -{ - PathInfo path (dumpPath); - - if ( !path.isExist() ) { - if (zypp::filesystem::mkdir (dumpPath)!=0) { - ERR << "Cannot create directory " << dumpPath << endl; - return false; - } - } else { - if (!path.isDir()) { - ERR << dumpPath << " is not a directory." << endl; - return false; - } - // remove old stuff - zypp::filesystem::clean_dir (dumpPath); - } - - RepositoryTable repoTable; - HelixResolvable system (dumpPath + "/solver-system.xml.gz"); - - for ( ResPool::const_iterator it = pool.begin(); it != pool.end(); ++it ) - { - if ( it->status().isInstalled() ) { - // system channel - system.addResolvable (*it); - } else { - // repo channels - Repository repo = it->resolvable()->satSolvable().repository(); - if (repoTable.find (repo) == repoTable.end()) { - repoTable[repo] = new HelixResolvable(dumpPath + "/" - + str::numstring((long)repo.id()) - + "-package.xml.gz"); - } - repoTable[repo]->addResolvable (*it); - } - } - return true; -} - -bool Testcase::createTestcase(Resolver & resolver, bool dumpPool, bool runSolver) -{ - PathInfo path (dumpPath); - - if ( !path.isExist() ) { - if (zypp::filesystem::assert_dir (dumpPath)!=0) { - ERR << "Cannot create directory " << dumpPath << endl; - return false; - } - } else { - if (!path.isDir()) { - ERR << dumpPath << " is not a directory." << endl; - return false; - } - // remove old stuff if pool will be dump - if (dumpPool) - zypp::filesystem::clean_dir (dumpPath); - } - - if (runSolver) { - zypp::base::LogControl::TmpLineWriter tempRedirect; - zypp::base::LogControl::instance().logfile( dumpPath +"/y2log" ); - zypp::base::LogControl::TmpExcessive excessive; - - resolver.resolvePool(); - } - - ResPool pool = resolver.pool(); - RepositoryTable repoTable; - PoolItemList items_to_install; - PoolItemList items_to_remove; - PoolItemList items_locked; - PoolItemList items_keep; - HelixResolvable_Ptr system = NULL; - - if (dumpPool) - system = new HelixResolvable(dumpPath + "/solver-system.xml.gz"); - - for ( ResPool::const_iterator it = pool.begin(); it != pool.end(); ++it ) - { - Resolvable::constPtr res = it->resolvable(); - - if ( system && it->status().isInstalled() ) { - // system channel - system->addResolvable (*it); - } else { - // repo channels - Repository repo = it->resolvable()->satSolvable().repository(); - if (dumpPool) { - if (repoTable.find (repo) == repoTable.end()) { - repoTable[repo] = new HelixResolvable(dumpPath + "/" - + str::numstring((long)repo.id()) - + "-package.xml.gz"); - } - repoTable[repo]->addResolvable (*it); - } - } - - if ( it->status().isToBeInstalled() - && !(it->status().isBySolver())) { - items_to_install.push_back (*it); - } - if ( it->status().isKept() - && !(it->status().isBySolver())) { - items_keep.push_back (*it); - } - if ( it->status().isToBeUninstalled() - && !(it->status().isBySolver())) { - items_to_remove.push_back (*it); - } - if ( it->status().isLocked() - && !(it->status().isBySolver())) { - items_locked.push_back (*it); - } - } +/////////////////////////////////////////////////////////////////// +// +// CLASS NAME : HelixResolvable +/** + * Creates a file in helix format which includes all available + * or installed packages,patches,selections..... + **/ +class HelixResolvable : public base::ReferenceCounted, private base::NonCopyable{ - // writing control file "*-test.xml" - HelixControl control (dumpPath + "/solver-test.xml", - repoTable, - ZConfig::instance().systemArchitecture(), - pool.getRequestedLocales(), - "solver-system.xml.gz", - resolver.forceResolve(), - resolver.onlyRequires(), - resolver.ignoreAlreadyRecommended() ); + private: + std::string dumpFile; // Path of the generated testcase + ofgzstream *file; - for (PoolItemList::const_iterator iter = items_to_install.begin(); iter != items_to_install.end(); iter++) { - control.installResolvable (iter->resolvable(), iter->status()); - } + public: + HelixResolvable (const std::string & path); + ~HelixResolvable (); - for (PoolItemList::const_iterator iter = items_locked.begin(); iter != items_locked.end(); iter++) { - control.lockResolvable (iter->resolvable(), iter->status()); - } + void addResolvable (const PoolItem item) + { *file << helixXML (item); } - for (PoolItemList::const_iterator iter = items_keep.begin(); iter != items_keep.end(); iter++) { - control.keepResolvable (iter->resolvable(), iter->status()); - } + std::string filename () + { return dumpFile; } +}; - for (PoolItemList::const_iterator iter = items_to_remove.begin(); iter != items_to_remove.end(); iter++) { - control.deleteResolvable (iter->resolvable(), iter->status()); - } - - control.addDependencies (resolver.extraRequires(), resolver.extraConflicts()); - control.addDependencies (SystemCheck::instance().requiredSystemCap(), - SystemCheck::instance().conflictSystemCap()); - control.addUpgradeRepos( resolver.upgradeRepos() ); - - if (resolver.isUpgradeMode()) - control.distupgrade (); - if (resolver.isUpdateMode()) - control.update(); - if (resolver.isVerifyingMode()) - control.verifySystem(); - - return true; -} +DEFINE_PTR_TYPE(HelixResolvable); +IMPL_PTR_TYPE(HelixResolvable); -//--------------------------------------------------------------------------- +typedef std::map RepositoryTable; HelixResolvable::HelixResolvable(const std::string & path) :dumpFile (path) @@ -404,13 +257,48 @@ HelixResolvable::~HelixResolvable() delete(file); } - -void HelixResolvable::addResolvable(const PoolItem item) -{ - *file << helixXML (item); -} - -//--------------------------------------------------------------------------- +/////////////////////////////////////////////////////////////////// +// +// CLASS NAME : HelixControl +/** + * Creates a file in helix format which contains all controll + * action of a testcase ( file is known as *-test.xml) + **/ +class HelixControl { + + private: + std::string dumpFile; // Path of the generated testcase + std::ofstream *file; + + public: + HelixControl (const std::string & controlPath, + const RepositoryTable & sourceTable, + const Arch & systemArchitecture, + const LocaleSet &languages, + const std::string & systemPath = "solver-system.xml.gz", + const bool forceResolve = false, + const bool onlyRequires = false, + const bool ignorealreadyrecommended = false); + HelixControl (); + ~HelixControl (); + + void installResolvable (const ResObject::constPtr &resObject, + const ResStatus &status); + void lockResolvable (const ResObject::constPtr &resObject, + const ResStatus &status); + void keepResolvable (const ResObject::constPtr &resObject, + const ResStatus &status); + void deleteResolvable (const ResObject::constPtr &resObject, + const ResStatus &status); + void addDependencies (const CapabilitySet &capRequire, const CapabilitySet &capConflict); + void addUpgradeRepos( const std::set & upgradeRepos_r ); + + void distupgrade (); + void verifySystem (); + void update (); + + std::string filename () { return dumpFile; } +}; HelixControl::HelixControl(const std::string & controlPath, const RepositoryTable & repoTable, @@ -556,6 +444,136 @@ void HelixControl::update() *file << "" << endl; } +//--------------------------------------------------------------------------- + +Testcase::Testcase() + :dumpPath("/var/log/YaST2/solverTestcase") +{} + +Testcase::Testcase(const std::string & path) + :dumpPath(path) +{} + +Testcase::~Testcase() +{} + +bool Testcase::createTestcase(Resolver & resolver, bool dumpPool, bool runSolver) +{ + PathInfo path (dumpPath); + + if ( !path.isExist() ) { + if (zypp::filesystem::assert_dir (dumpPath)!=0) { + ERR << "Cannot create directory " << dumpPath << endl; + return false; + } + } else { + if (!path.isDir()) { + ERR << dumpPath << " is not a directory." << endl; + return false; + } + // remove old stuff if pool will be dump + if (dumpPool) + zypp::filesystem::clean_dir (dumpPath); + } + + if (runSolver) { + zypp::base::LogControl::TmpLineWriter tempRedirect; + zypp::base::LogControl::instance().logfile( dumpPath +"/y2log" ); + zypp::base::LogControl::TmpExcessive excessive; + + resolver.resolvePool(); + } + + ResPool pool = resolver.pool(); + RepositoryTable repoTable; + PoolItemList items_to_install; + PoolItemList items_to_remove; + PoolItemList items_locked; + PoolItemList items_keep; + HelixResolvable_Ptr system = NULL; + + if (dumpPool) + system = new HelixResolvable(dumpPath + "/solver-system.xml.gz"); + + for ( ResPool::const_iterator it = pool.begin(); it != pool.end(); ++it ) + { + Resolvable::constPtr res = it->resolvable(); + + if ( system && it->status().isInstalled() ) { + // system channel + system->addResolvable (*it); + } else { + // repo channels + Repository repo = it->resolvable()->satSolvable().repository(); + if (dumpPool) { + if (repoTable.find (repo) == repoTable.end()) { + repoTable[repo] = new HelixResolvable(dumpPath + "/" + + str::numstring((long)repo.id()) + + "-package.xml.gz"); + } + repoTable[repo]->addResolvable (*it); + } + } + + if ( it->status().isToBeInstalled() + && !(it->status().isBySolver())) { + items_to_install.push_back (*it); + } + if ( it->status().isKept() + && !(it->status().isBySolver())) { + items_keep.push_back (*it); + } + if ( it->status().isToBeUninstalled() + && !(it->status().isBySolver())) { + items_to_remove.push_back (*it); + } + if ( it->status().isLocked() + && !(it->status().isBySolver())) { + items_locked.push_back (*it); + } + } + + // writing control file "*-test.xml" + HelixControl control (dumpPath + "/solver-test.xml", + repoTable, + ZConfig::instance().systemArchitecture(), + pool.getRequestedLocales(), + "solver-system.xml.gz", + resolver.forceResolve(), + resolver.onlyRequires(), + resolver.ignoreAlreadyRecommended() ); + + for (PoolItemList::const_iterator iter = items_to_install.begin(); iter != items_to_install.end(); iter++) { + control.installResolvable (iter->resolvable(), iter->status()); + } + + for (PoolItemList::const_iterator iter = items_locked.begin(); iter != items_locked.end(); iter++) { + control.lockResolvable (iter->resolvable(), iter->status()); + } + + for (PoolItemList::const_iterator iter = items_keep.begin(); iter != items_keep.end(); iter++) { + control.keepResolvable (iter->resolvable(), iter->status()); + } + + for (PoolItemList::const_iterator iter = items_to_remove.begin(); iter != items_to_remove.end(); iter++) { + control.deleteResolvable (iter->resolvable(), iter->status()); + } + + control.addDependencies (resolver.extraRequires(), resolver.extraConflicts()); + control.addDependencies (SystemCheck::instance().requiredSystemCap(), + SystemCheck::instance().conflictSystemCap()); + control.addUpgradeRepos( resolver.upgradeRepos() ); + + if (resolver.isUpgradeMode()) + control.distupgrade (); + if (resolver.isUpdateMode()) + control.update(); + if (resolver.isVerifyingMode()) + control.verifySystem(); + + return true; +} + /////////////////////////////////////////////////////////////////// };// namespace detail diff --git a/zypp/solver/detail/Testcase.h b/zypp/solver/detail/Testcase.h index d7854b88d..16ceb9b66 100644 --- a/zypp/solver/detail/Testcase.h +++ b/zypp/solver/detail/Testcase.h @@ -13,17 +13,8 @@ #ifndef ZYPP_SOLVER_DETAIL_TESTCASE_H #define ZYPP_SOLVER_DETAIL_TESTCASE_H -#include #include -#include "zypp/base/ReferenceCounted.h" -#include "zypp/base/NonCopyable.h" -#include "zypp/base/PtrTypes.h" #include "zypp/solver/detail/Resolver.h" -#include "zypp/Capabilities.h" -#include "zypp/ResPool.h" -#include "zypp/base/GzStream.h" -#include "zypp/Repository.h" -#include "zypp/Locale.h" ///////////////////////////////////////////////////////////////////////// namespace zypp @@ -35,121 +26,26 @@ namespace zypp namespace detail { /////////////////////////////////////////////////////////////////// - -template -std::string helixXML( const T &obj ); //undefined - -template<> -std::string helixXML( const Edition &edition ); - -template<> -std::string helixXML( const Arch &arch ); - -template<> -std::string helixXML( const Capability &cap ); - -template<> -std::string helixXML( const Capabilities &caps ); - -template<> -std::string helixXML( const CapabilitySet &caps ); - -template<> -std::string helixXML( const PoolItem &item ); - - -/////////////////////////////////////////////////////////////////// -// -// CLASS NAME : HelixResolvable -/** - * Creates a file in helix format which includes all available - * or installed packages,patches,selections..... - **/ -class HelixResolvable : public base::ReferenceCounted, private base::NonCopyable{ - - private: - std::string dumpFile; // Path of the generated testcase - ofgzstream *file; - - public: - HelixResolvable (const std::string & path); - ~HelixResolvable (); - - void addResolvable (const PoolItem item); - std::string filename () { return dumpFile; } -}; - -DEFINE_PTR_TYPE(HelixResolvable); -typedef std::map RepositoryTable; - -/////////////////////////////////////////////////////////////////// -// -// CLASS NAME : HelixControl -/** - * Creates a file in helix format which contains all controll - * action of a testcase ( file is known as *-test.xml) - **/ -class HelixControl { - - private: - std::string dumpFile; // Path of the generated testcase - std::ofstream *file; - - public: - HelixControl (const std::string & controlPath, - const RepositoryTable & sourceTable, - const Arch & systemArchitecture, - const LocaleSet &languages, - const std::string & systemPath = "solver-system.xml.gz", - const bool forceResolve = false, - const bool onlyRequires = false, - const bool ignorealreadyrecommended = false); - HelixControl (); - ~HelixControl (); - - void installResolvable (const ResObject::constPtr &resObject, - const ResStatus &status); - void lockResolvable (const ResObject::constPtr &resObject, - const ResStatus &status); - void keepResolvable (const ResObject::constPtr &resObject, - const ResStatus &status); - void deleteResolvable (const ResObject::constPtr &resObject, - const ResStatus &status); - void addDependencies (const CapabilitySet &capRequire, const CapabilitySet &capConflict); - void addUpgradeRepos( const std::set & upgradeRepos_r ); - - void distupgrade (); - void verifySystem (); - void update (); - - std::string filename () { return dumpFile; } -}; - - - - -/////////////////////////////////////////////////////////////////// -// -// CLASS NAME : Testcase -/** - * Generating a testcase of the current pool and solver state - **/ -class Testcase { - - private: - std::string dumpPath; // Path of the generated testcase - - public: - Testcase (const std::string & path); - Testcase (); - ~Testcase (); - - bool createTestcase (Resolver & resolver, bool dumpPool = true, bool runSolver = true); - bool createTestcasePool(const ResPool &pool); -}; - - -/////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : Testcase + /** + * Generating a testcase of the current pool and solver state. + **/ + class Testcase + { + private: + std::string dumpPath; // Path of the generated testcase + + public: + Testcase(); + Testcase( const std::string & path ); + ~Testcase(); + + bool createTestcase( Resolver & resolver, bool dumpPool = true, bool runSolver = true ); + }; + + /////////////////////////////////////////////////////////////////// };// namespace detail ///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////