Author: dmacvicar
Date: Wed Apr 11 19:11:03 2007
New Revision: 5345
URL: http://svn.opensuse.org/viewcvs/zypp?rev=5345&view=rev
Log:
- prototype of a YUM downloader, also a experiment to learn Michael's
XML parser and implement later the YUM cacher.
- still doesnt download the patches, comes tomorrow.
Added:
trunk/libzypp/devel/devel.dmacvicar/SUSETagsDownloader_tp.cc
- copied unchanged from r5333, trunk/libzypp/devel/devel.dmacvicar/SUSETagsDownloader.cc
trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.cc
trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.h
trunk/libzypp/devel/devel.dmacvicar/YUMDownloader_tp.cc
Removed:
trunk/libzypp/devel/devel.dmacvicar/SUSETagsDownloader.cc
Modified:
trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt
trunk/libzypp/devel/devel.dmacvicar/testbed.cc
trunk/libzypp/zypp/source/susetags/SUSETagsDownloader.cc
Modified: trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt?rev=5345&r1=5344&r2=5345&view=diff
==============================================================================
--- trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt (original)
+++ trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt Wed Apr 11 19:11:03 2007
@@ -2,76 +2,14 @@
ADD_DEFINITIONS(-DSRC_DIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\")
-########### next target ###############
-SET(test_SRCS
-zypp-keyring.cc
-)
-
-#ADD_EXECUTABLE(test ${test_SRCS})
-#TARGET_LINK_LIBRARIES(test zypp )
-
-########### next target ###############
-
-SET(lock_SRCS
-zypp-lock.cc
-)
-
-#ADD_EXECUTABLE(lock ${lock_SRCS})
-#TARGET_LINK_LIBRARIES(lock zypp )
-
-
-########### next target ###############
-
-SET(testbed_SRCS
-testbed.cc
-)
-
-#ADD_EXECUTABLE(testbed ${testbed_SRCS})
-#TARGET_LINK_LIBRARIES(testbed zypp )
-
-########### next target ###############
-
-SET(aj_SRCS
-aj.cc
-)
-
-#ADD_EXECUTABLE(aj ${aj_SRCS})
-#TARGET_LINK_LIBRARIES(aj zypp )
-
-
-########### next target ###############
-
-SET(yumparser_SRCS
-yum-parser.cc
-)
-
-#ADD_EXECUTABLE(yumparser ${yumparser_SRCS})
-#TARGET_LINK_LIBRARIES(yumparser zypp )
-
-
-########### next target ###############
-
-SET(media_SRCS
-media-glob.cc
-)
-
-#ADD_EXECUTABLE(media ${media_SRCS})
-#TARGET_LINK_LIBRARIES(media zypp )
-
-########### next target ###############
-
-SET(mediaaccess_SRCS
-mediaaccess.cc
-)
-
-ADD_EXECUTABLE(mediaaccess ${mediaaccess_SRCS})
+ADD_EXECUTABLE(mediaaccess mediaaccess.cc)
TARGET_LINK_LIBRARIES(mediaaccess zypp )
ADD_EXECUTABLE(scansource ScanSource.cc)
TARGET_LINK_LIBRARIES(scansource zypp )
-ADD_EXECUTABLE(susetags-downloader SUSETagsDownloader.cc)
+ADD_EXECUTABLE(susetags-downloader SUSETagsDownloader_tp.cc)
TARGET_LINK_LIBRARIES(susetags-downloader zypp )
ADD_EXECUTABLE(cachestore CacheStore.cc)
@@ -84,4 +22,12 @@
ADD_EXECUTABLE(tagsparser SUSETagsParser.cc)
TARGET_LINK_LIBRARIES(tagsparser zypp )
-TARGET_LINK_LIBRARIES(tagsparser zypp2 )
\ No newline at end of file
+TARGET_LINK_LIBRARIES(tagsparser zypp2 )
+
+ADD_EXECUTABLE(testbed testbed.cc)
+TARGET_LINK_LIBRARIES(testbed zypp )
+TARGET_LINK_LIBRARIES(testbed zypp2 )
+
+ADD_EXECUTABLE(yum-downloader YUMDownloader.cc YUMDownloader_tp.cc)
+TARGET_LINK_LIBRARIES(yum-downloader zypp )
+TARGET_LINK_LIBRARIES(yum-downloader zypp2 )
\ No newline at end of file
Added: trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.cc?rev=5345&view=auto
==============================================================================
--- trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.cc (added)
+++ trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.cc Wed Apr 11 19:11:03 2007
@@ -0,0 +1,163 @@
+
+#include <fstream>
+#include "zypp/base/String.h"
+#include "zypp/base/Logger.h"
+#include "zypp/base/Function.h"
+
+#include "zypp/Date.h"
+
+#include "YUMDownloader.h"
+
+using namespace std;
+using namespace zypp::xml;
+
+namespace zypp
+{
+namespace source
+{
+namespace yum
+{
+
+class RepomdFileReader
+{
+public:
+ typedef function ProcessResource;
+
+ enum Tag
+ {
+ tag_NONE,
+ tag_Repomd,
+ tag_Data,
+ tag_Location,
+ tag_CheckSum,
+ tag_Timestamp,
+ tag_OpenCheckSum
+ };
+
+ RepomdFileReader( const Pathname &repomd_file, ProcessResource callback )
+ : _tag(tag_NONE), _callback(callback)
+ {
+ Reader reader( repomd_file );
+ MIL << "Reading " << repomd_file << endl;
+ reader.foreachNode( bind( &RepomdFileReader::consumeNode, this, _1 ) );
+ }
+
+ bool consumeNode( Reader & reader_r )
+ {
+ //MIL << reader_r->name() << endl;
+ std::string data_type;
+ if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT )
+ {
+ if ( reader_r->name() == "repomd" )
+ {
+ _tag = tag_Repomd;
+ return true;
+ }
+ if ( reader_r->name() == "data" )
+ {
+ _tag = tag_Data;
+ _type = reader_r->getAttribute("type").asString();
+ return true;
+ }
+ if ( reader_r->name() == "location" )
+ {
+ _tag = tag_Location;
+ _location.filename( reader_r->getAttribute("href").asString() );
+ return true;
+ }
+ if ( reader_r->name() == "checksum" )
+ {
+ _tag = tag_CheckSum;
+ string checksum_type = reader_r->getAttribute("type").asString() ;
+ string checksum_vaue = reader_r.nodeText().asString();
+ _location.checksum( CheckSum( checksum_type, checksum_vaue ) );
+ return true;
+ }
+ if ( reader_r->name() == "timestamp" )
+ {
+ // ignore it
+ return true;
+ }
+ }
+ else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
+ {
+ //MIL << "end element" << endl;
+ if ( reader_r->name() == "data" )
+ _callback( _location, _type );
+ return true;
+ }
+ return true;
+ }
+
+ private:
+ OnMediaLocation _location;
+ Tag _tag;
+ std::string _type;
+ ProcessResource _callback;
+ CheckSum _checksum;
+ std::string _checksum_type;
+ Date _timestamp;
+};
+
+YUMDownloader::YUMDownloader( const Url &url, const Pathname &path )
+ : _url(url), _path(path)
+{
+}
+
+bool YUMDownloader::repomd_Callback( const OnMediaLocation &loc, const string &dtype )
+{
+ MIL << loc << " " << dtype << endl;
+ fetcher.enqueue(loc);
+ 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;
+
+ 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 );
+}
+
+}// ns yum
+}// ns source
+} // ns zypp
Added: trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.h?rev=5345&view=auto
==============================================================================
--- trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.h (added)
+++ trunk/libzypp/devel/devel.dmacvicar/YUMDownloader.h Wed Apr 11 19:11:03 2007
@@ -0,0 +1,42 @@
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+
+#ifndef ZYPP_SOURCE_YUM_DOWNLOADER
+#define ZYPP_SOURCE_YUM_DOWNLOADER
+
+#include "zypp/Url.h"
+#include "zypp/Pathname.h"
+#include "zypp/Fetcher.h"
+#include "zypp/OnMediaLocation.h"
+#include "zypp/parser/xml/Reader.h"
+
+namespace zypp
+{
+ namespace source
+ {
+ namespace yum
+ {
+
+ class YUMDownloader
+ {
+ public:
+ YUMDownloader( const Url &url, const Pathname &path );
+ void download( const Pathname &dest_dir );
+ bool repomd_Callback( const OnMediaLocation &loc, const std::string &dtype );
+ private:
+ Url _url;
+ Pathname _path;
+ Fetcher fetcher;
+ };
+
+ } // ns yum
+ } // ns source
+} // ns zypp
+
+#endif
Added: trunk/libzypp/devel/devel.dmacvicar/YUMDownloader_tp.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.dmacvicar/YUMDownloader_tp.cc?rev=5345&view=auto
==============================================================================
--- trunk/libzypp/devel/devel.dmacvicar/YUMDownloader_tp.cc (added)
+++ trunk/libzypp/devel/devel.dmacvicar/YUMDownloader_tp.cc Wed Apr 11 19:11:03 2007
@@ -0,0 +1,46 @@
+#include
+
+#include <iostream>
+#include <fstream>
+
+#include <list>
+#include <set>
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "zypp/Product.h"
+#include "zypp/Package.h"
+
+
+using namespace std;
+using namespace zypp;
+using namespace media;
+using namespace source::yum;
+
+int main(int argc, char **argv)
+{
+ try
+ {
+ ZYpp::Ptr z = getZYpp();
+ YUMDownloader downloader(Url(argv[1]), "/");
+ downloader.download(argv[2]);
+ }
+ catch ( const Exception &e )
+ {
+ cout << "ups! " << e.msg() << std::endl;
+ }
+ return 0;
+}
+
+
+
Modified: trunk/libzypp/devel/devel.dmacvicar/testbed.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.dmacvicar/testbed.cc?rev=5345&r1=5344&r2=5345&view=diff
==============================================================================
--- trunk/libzypp/devel/devel.dmacvicar/testbed.cc (original)
+++ trunk/libzypp/devel/devel.dmacvicar/testbed.cc Wed Apr 11 19:11:03 2007
@@ -11,37 +11,14 @@
#include "zypp/detail/PackageImplIf.h"
#include "zypp/Package.h"
-#include "zypp2/cache/SourceCacheInitializer.h"
-
-#include "zypp2/source/sqlite-source/SqliteAccess.h"
-#include "zypp2/source/sqlite-source/SqliteSources.h"
-
+#include "zypp2/source/cached/CachedSourceImpl.h"
#include "zypp/data/ResolvableData.h"
using namespace std;
using namespace zypp;
+using namespace zypp::source;
+using namespace zypp::source::cached;
-class TimeCount
-{
- public:
-
- TimeCount()
- {
- gettimeofday( &_start, NULL);
- }
-
- void tick( const std::string &msg )
- {
- timeval curr;
- gettimeofday( &curr, NULL);
- timeval tmp = curr;
- MIL << "[TICK] " << msg << " : " << (curr.tv_sec - _start.tv_sec) << "." << curr.tv_usec - _start.tv_usec << endl;
- _start = tmp;
- }
-
- private:
- timeval _start;
-};
int main(int argc, char **argv)
{
@@ -49,51 +26,16 @@
{
ZYpp::Ptr z = getZYpp();
- TimeCount t;
- Pathname dbfile = Pathname(getenv("PWD")) + "data.db";
- SqliteAccess db(dbfile);
+ Pathname dbpath = Pathname(getenv("PWD"));
- if ( ! filesystem::PathInfo(dbfile).isExist() )
- {
- zypp::cache::SourceCacheInitializer init( "/", dbfile );
- t.tick("init sqlite database");
-
- //return 1;
-
- z->initializeTarget("/");
- t.tick("init target");
- ResStore s = z->target()->resolvables();
- t.tick("load target");
-
- SqliteAccess db(dbfile);
- db.openDb(true);
-
- db.insertCatalog( Url("http://www.google.com"), Pathname("/"), "duncan", "A test catalog" );
- db.writeStore( s, ResStatus::uninstalled, "duncan" );
-
- t.tick("write store");
-
- // for ( ResStore::const_iterator it = s.begin(); it != s.end(); ++it )
- // {
- // Package::Ptr p = asKind<Package>(*it);
- // cout << "ja 1 paquete" << endl;
- // oa << p;
- // }
- }
-
- SqliteSources sqsrcs(db.db());
- SourcesList srcs = sqsrcs.sources();
- t.tick("create sources");
- for ( SourcesList::const_iterator it = srcs.begin(); it != srcs.end(); ++it )
- {
- Source_Ref src = *it;
- ResStore dbres = src.resolvables();
- t.tick("read source");
- }
+ CachedSourceImpl source(dbpath);
+ //ResStore dbres = src.resolvables();
+
}
catch ( const Exception &e )
{
ZYPP_CAUGHT(e);
+ cout << e.msg() << endl;
}
return 0;
Modified: trunk/libzypp/zypp/source/susetags/SUSETagsDownloader.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/source/susetags/SUSETagsDownloader.cc?rev=5345&r1=5344&r2=5345&view=diff
==============================================================================
--- trunk/libzypp/zypp/source/susetags/SUSETagsDownloader.cc (original)
+++ trunk/libzypp/zypp/source/susetags/SUSETagsDownloader.cc Wed Apr 11 19:11:03 2007
@@ -2,6 +2,7 @@
#include <fstream>
#include "zypp/base/String.h"
#include "zypp/OnMediaLocation.h"
+#include "zypp/MediaSetAccess.h"
#include "zypp/Fetcher.h"
#include "zypp/source/susetags/SUSETagsDownloader.h"
@@ -23,9 +24,10 @@
void SUSETagsDownloader::download( const Pathname &dest_dir )
{
- Fetcher fetcher(_url, _path);
+ MediaSetAccess media(_url, _path);
+ Fetcher fetcher;
fetcher.enqueue( OnMediaLocation().filename("/content") );
- fetcher.start( dest_dir );
+ fetcher.start( dest_dir, media );
fetcher.reset();
std::ifstream file((dest_dir + "/content").asString().c_str());
@@ -61,7 +63,7 @@
}
}
file.close();
- fetcher.start( dest_dir );
+ fetcher.start( dest_dir, media );
}
}// ns susetags
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org