Author: dmacvicar Date: Mon Apr 16 12:18:23 2007 New Revision: 5383 URL: http://svn.opensuse.org/viewcvs/zypp?rev=5383&view=rev Log: YUM downloader ready! Modified: trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.cc trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.h Modified: trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.cc?rev=5383&r1=5382&r2=5383&view=diff ============================================================================== --- trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.cc (original) +++ trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.cc Mon Apr 16 12:18:23 2007 @@ -1,3 +1,11 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ #include <fstream> #include "zypp/base/String.h" @@ -6,8 +14,8 @@ #include "zypp/Date.h" - #include "zypp/parser/yum/RepomdFileReader.h" +#include "zypp/parser/yum/PatchesFileReader.h" #include "YUMDownloader.h" using namespace std; @@ -21,64 +29,51 @@ { YUMDownloader::YUMDownloader( const Url &url, const Pathname &path ) - : _url(url), _path(path) + : _url(url), _path(path), _media(url, path) +{ +} + +bool YUMDownloader::patches_Callback( const OnMediaLocation &loc, const string &id ) { + MIL << id << " : " << loc << endl; + _fetcher.enqueue(loc); + return true; } + bool YUMDownloader::repomd_Callback( const OnMediaLocation &loc, const string &dtype ) { - MIL << loc << " " << dtype << endl; - fetcher.enqueue(loc); + MIL << dtype << " : " << loc << endl; + _fetcher.enqueue(loc); + + // We got a patches file we need to read, to add patches listed + // there, so we transfer what we have in the queue, and + // queue the patches in the patches callback + if ( dtype == "patches" ) + { + _fetcher.start( _dest_dir, _media); + // now the patches.xml file must exists + PatchesFileReader( _dest_dir + loc.filename(), bind( &YUMDownloader::patches_Callback, this, _1, _2)); + } return true; } void YUMDownloader::download( const Pathname &dest_dir ) { - MediaSetAccess media(_url, _path); - fetcher.enqueue( OnMediaLocation().filename("/repodata/repomd.xml") ); - fetcher.start( dest_dir, media); - fetcher.reset(); - - //std::ifstream file((dest_dir + "/content").asString().c_str()); - //std::string buffer; - //Pathname descr_dir; - + _dest_dir = dest_dir; + _fetcher.enqueue( OnMediaLocation().filename("/repodata/repomd.xml") ); + _fetcher.start( dest_dir, _media); + _fetcher.reset(); + Reader reader( dest_dir + "/repodata/repomd.xml" ); RepomdFileReader( dest_dir + "/repodata/repomd.xml", bind( &YUMDownloader::repomd_Callback, this, _1, _2)); - fetcher.start( dest_dir, media); - //reader.foreachNode( bind( &YUMDownloader::consumeNode, this, _1 ) ); - // Note this code assumes DESCR comes before as META - -// while (file && !file.eof()) -// { -// getline(file, buffer); -// if ( buffer.substr( 0, 5 ) == "DESCR" ) -// { -// std::vectorstd::string words; -// if ( str::split( buffer, std::back_inserter(words) ) != 2 ) -// { -// // error -// ZYPP_THROW(Exception("bad DESCR line")); -// } -// descr_dir = words[1]; -// } -// else if ( buffer.substr( 0, 4 ) == "META" ) -// { -// std::vectorstd::string words; -// if ( str::split( buffer, std::back_inserter(words) ) != 4 ) -// { -// // error -// ZYPP_THROW(Exception("bad DESCR line")); -// } -// OnMediaLocation location; -// location.filename( descr_dir + words[3]).checksum( CheckSum( words[1], words[2] ) ); -// fetcher.enqueue(location); -// } -// } -// file.close(); -// fetcher.start( dest_dir ); + + // ready, go! + _fetcher.start( dest_dir, _media); } }// ns yum }// ns source } // ns zypp + + Modified: trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.h?rev=5383&r1=5382&r2=5383&view=diff ============================================================================== --- trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.h (original) +++ trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.h Mon Apr 16 12:18:23 2007 @@ -14,6 +14,7 @@ #include "zypp/Pathname.h" #include "zypp/Fetcher.h" #include "zypp/OnMediaLocation.h" +#include "zypp/MediaSetAccess.h" #include "zypp/parser/xml/Reader.h" namespace zypp @@ -22,17 +23,38 @@ { namespace yum { - + /** + * This class allows to retrieve a YUM repository + * to a local directory + * + * \code + * YUMDownloader yum(url, path); + * yum.download("localdir"); + * \endcode + */ class YUMDownloader { public: + /** + * Create the download object for a repository + * located in \a url with path \a path + */ YUMDownloader( const Url &url, const Pathname &path ); + /** + * starts the download to local directory \a dest_dir + */ void download( const Pathname &dest_dir ); + + protected: bool repomd_Callback( const OnMediaLocation &loc, const std::string &dtype ); + bool patches_Callback( const OnMediaLocation &loc, const std::string &id ); private: Url _url; Pathname _path; - Fetcher fetcher; + Fetcher _fetcher; + Pathname _dest_dir; + std::list<OnMediaLocation> _patches_files; + MediaSetAccess _media; }; } // ns yum -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org