From: Duncan Mac-Vicar P Date: Fri, 11 Aug 2006 09:47:51 +0000 (+0000) Subject: - Introduce examples/ X-Git-Tag: BASE-SuSE-SLE-10-SP2-Branch~486 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2cf7e2eac1d860d45a0095e69653701805a15a48;p=platform%2Fupstream%2Flibzypp.git - Introduce examples/ much like devel.* programs with one difference: - must compile. They are documentation. - Included in compilation - they should show only useful tasks. like installing a package, but not how to use templates to draw the suse logo in ascii. - they must be zypp user examples, not zypp developer examples - fix some svn ignores --- diff --git a/Makefile.am b/Makefile.am index 12d907a..1918f8e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,7 +4,7 @@ # Do NOT list 'devel' in subdirs. It's developers playgound # and must not prevent anything from building. -SUBDIRS = zypp zypp2 testsuite po doc +SUBDIRS = zypp zypp2 examples testsuite po doc ## ################################################## diff --git a/configure.ac b/configure.ac index 98ca05d..3974143 100644 --- a/configure.ac +++ b/configure.ac @@ -241,7 +241,8 @@ AC_OUTPUT( po/Makefile.in\ testsuite/target/tests/Makefile \ testsuite/media/Makefile \ testsuite/media/tests/Makefile \ - zypp/Makefile \ + examples/Makefile \ + zypp/Makefile \ zypp/base/Makefile \ zypp/thread/Makefile \ zypp/detail/Makefile \ diff --git a/devel/devel.dmacvicar/testbed.cc b/devel/devel.dmacvicar/testbed.cc index 9af1434..6ad0ced 100644 --- a/devel/devel.dmacvicar/testbed.cc +++ b/devel/devel.dmacvicar/testbed.cc @@ -1,39 +1,11 @@ -#include -#include -#include -#include - -#include "boost/filesystem/operations.hpp" // includes boost/filesystem/path.hpp -#include "boost/filesystem/fstream.hpp" // ditto - -#include - #include -#include #include #include -#include -/////////////////////////////////////////////////////////////////// - -#include - -#include -#include - -#include "zypp/CapFactory.h" -#include "zypp/KeyRing.h" #include "zypp/Product.h" -#include "zypp/Selection.h" #include "zypp/Package.h" -#include "zypp/PublicKey.h" - -#include "zypp/ZYppFactory.h" -#include "zypp/MediaSetAccess.h" #include "zypp/SourceFactory.h" -#include "zypp2/source/yum/YUMSourceCacher.h" - #include "testsuite/src/utils/TestUtils.h" using namespace zypp::detail; @@ -63,13 +35,7 @@ int main() zypp::Package::Ptr res = asKind( *it ); MIL << res->name() << " " << res->edition() << " " << res->location() << std::endl; } - - /*for (ResStore::resfilter_const_iterator it = z->target()->byKindBegin(ResTraits::kind); it != z->target()->byKindEnd(ResTraits::kind); ++it) - { - zypp::TestKind::constPtr res = asKind( *it ); - MIL << res->name() << " " << res->edition() << std::endl; - }*/ - + } catch ( const Exception &e ) { diff --git a/examples/Makefile.am b/examples/Makefile.am new file mode 100644 index 0000000..59ecce9 --- /dev/null +++ b/examples/Makefile.am @@ -0,0 +1,28 @@ +## Process this file with automake to produce Makefile.in +## ################################################## + +noinst_PROGRAMS = read_plaindir_source + +## ################################################## + +INCLUDES = -I$(oldincludedir)/libxml2 +AM_LDFLAGS = + +AM_CXXFLAGS = +# gperf: -pg + +LDADD = -L$(top_srcdir)/zypp/.libs -lzypp -lboost_regex -lxml2 -lz $(top_srcdir)/testsuite/src/utils/lib@PACKAGE@_testsuite_utils.la + +## ################################################## + +read_plaindir_source_SOURCES = read_plaindir_source.cc +read_plaindir_source_LDFLAGS = -static + +.PHONY: always + +$(noinst_PROGRAMS): $(top_srcdir)/zypp/lib@PACKAGE@.la + +$(top_srcdir)/zypp/lib@PACKAGE@.la: always + $(MAKE) -C $(top_srcdir)/zypp + +## ################################################## diff --git a/examples/README b/examples/README new file mode 100644 index 0000000..62523d4 --- /dev/null +++ b/examples/README @@ -0,0 +1,8 @@ + +ZyPP Examples +============= + +* read_plaindir_source.cc + Read a sirectory with rpm files (no metadata) and loop over the resolvables. + + \ No newline at end of file diff --git a/examples/read_plaindir_source.cc b/examples/read_plaindir_source.cc new file mode 100644 index 0000000..4842db7 --- /dev/null +++ b/examples/read_plaindir_source.cc @@ -0,0 +1,53 @@ +// ZyPP Example +// Read a directory with rpms as a source +// No need for metadata, it is read from the rpms + +#include +#include +#include + +#include "zypp/Product.h" +#include "zypp/Package.h" + +#include "zypp/SourceFactory.h" +#include "testsuite/src/utils/TestUtils.h" + +using namespace std; +using namespace zypp; +using namespace zypp::source; + +int +main (int argc, char **argv) +{ + if (argc < 2) { + cerr << "1|usage: " << argv[0] << " " << endl; + return 1; + } + + try + { + ZYpp::Ptr z = getZYpp(); + + // plaindir sources are not signed so we don't need to initialize the + // target to import the system public keys. + //z->initializeTarget("/"); + + Source_Ref source = SourceFactory().createFrom( Url(argv[1]), "/", "testsource", Pathname() ); + ResStore store = source.resolvables(); + //zypp::testsuite::utils::dump(store, true, true); + + for (ResStore::const_iterator it = store.begin(); it != store.end(); ++it) + { + zypp::Package::Ptr res = asKind( *it ); + MIL << res->name() << " " << res->edition() << " " << res->location() << std::endl; + } + + } + catch ( const Exception &e ) + { + MIL << "Exception ocurred, bye" << endl; + } +} + + +