Author: dmacvicar
Date: Wed Sep 10 00:37:17 2008
New Revision: 10991
URL: http://svn.opensuse.org/viewcvs/zypp?rev=10991&view=rev
Log:
backup
simple rpmbuilder that can be used to create repos on runtime from simple spec files
this would be very useful in the testsuite, and I want it to test for example automatic
driver selection
We need to define some base testsuite utilities (a small library with utilities), as Jano mentioned
we also want to create the solv files while the testsuite runs
Added:
trunk/libzypp/devel/devel.dmacvicar/rpmbuilder.cc
Modified:
trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt
Modified: trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt?rev=10991&r1=10990&r2=10991&view=diff
==============================================================================
--- trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt (original)
+++ trunk/libzypp/devel/devel.dmacvicar/CMakeLists.txt Wed Sep 10 00:37:17 2008
@@ -1,29 +1,7 @@
-ADD_DEFINITIONS(-DSRC_DIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\")
+ADD_DEFINITIONS(-DSRC_DIR=${CMAKE_CURRENT_SOURCE_DIR})
-ADD_EXECUTABLE(mediaaccess mediaaccess.cc)
-TARGET_LINK_LIBRARIES(mediaaccess zypp )
-
-#ADD_EXECUTABLE(multiple-download multiple-download.cc)
-#TARGET_LINK_LIBRARIES(multiple-download zypp boost_thread)
-
-#ADD_EXECUTABLE(scansource ScanSource.cc)
-#TARGET_LINK_LIBRARIES(scansource zypp )
-
-#ADD_EXECUTABLE(susetags-downloader SUSETagsDownloader_tp.cc)
-#TARGET_LINK_LIBRARIES(susetags-downloader zypp )
-
-ADD_EXECUTABLE(testbed testbed.cc)
-TARGET_LINK_LIBRARIES(testbed zypp )
-
-#ADD_EXECUTABLE(yum-downloader YUMDownloader_tp.cc)
-#TARGET_LINK_LIBRARIES(yum-downloader zypp )
-
-# ADD_EXECUTABLE(yum-reader YUMReader_tp.cc)
-# TARGET_LINK_LIBRARIES(yum-reader zypp )
-
-
-ADD_EXECUTABLE(repomanager RepositoryManager_tp.cc)
-TARGET_LINK_LIBRARIES(repomanager zypp )
+ADD_EXECUTABLE(rpmbuilder rpmbuilder.cc)
+TARGET_LINK_LIBRARIES(rpmbuilder zypp )
FIND_PACKAGE(Zsync)
IF(ZSYNC_FOUND)
@@ -31,4 +9,4 @@
TARGET_LINK_LIBRARIES(zsync ${ZSYNC_LIBRARY} ${RCKSUM_LIBRARY})
TARGET_LINK_LIBRARIES(zsync zypp )
# TARGET_LINK_LIBRARIES(zsync zypp2 )
-ENDIF(ZSYNC_FOUND)
\ No newline at end of file
+ENDIF(ZSYNC_FOUND)
Added: trunk/libzypp/devel/devel.dmacvicar/rpmbuilder.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/devel/devel.dmacvicar/rpmbuilder.cc?rev=10991&view=auto
==============================================================================
--- trunk/libzypp/devel/devel.dmacvicar/rpmbuilder.cc (added)
+++ trunk/libzypp/devel/devel.dmacvicar/rpmbuilder.cc Wed Sep 10 00:37:17 2008
@@ -0,0 +1,160 @@
+#include
+
+#include <iostream>
+#include <fstream>
+
+#include
+#include
+#include
+
+#include "zypp/Product.h"
+#include "zypp/Package.h"
+
+#include "zypp/TmpPath.h"
+#include "zypp/ExternalProgram.h"
+#include "zypp/ProgressData.h"
+#include "zypp/repo/yum/Downloader.h"
+
+#include "zypp/sat/Pool.h"
+
+#include "zypp/PoolQuery.h"
+
+using namespace std;
+using namespace zypp;
+using namespace zypp::repo;
+using namespace zypp::filesystem;
+
+class RpmBuilder
+{
+public:
+ RpmBuilder()
+ {
+ Pathname top = _tmptop.path();
+ Pathname rcpath = _tmprc.path();
+
+ assert_dir(top / "build" );
+ assert_dir(top / "rpms" );
+
+ /* create a rpm configuration file and
+ setup the macros file */
+ std::ofstream rcfile(rcpath.c_str());
+ if (!rcfile)
+ ZYPP_THROW (Exception( "Can't open " + rcpath.asString() ) );
+
+ rcfile << "macrofiles: " << _tmpmacros.path() << endl;
+ rcfile.close();
+ }
+
+ Pathname rpmsDir() const
+ {
+ return _tmptop.path() / "rpms";
+ }
+
+ void createRpmMetadata() const
+ {
+ const char* argv[] =
+ {
+ "createrepo",
+ rpmsDir().c_str(),
+ NULL
+ };
+ ExternalProgram prog(argv,ExternalProgram::Normal_Stderr, false, -1, true);
+ string line;
+ int count;
+ for(line = prog.receiveLine(), count=0; !line.empty(); line = prog.receiveLine(), count++ )
+ {
+ cout << line;
+ }
+ prog.close();
+
+ }
+
+ void buildSpec( const Pathname &spec )
+ {
+ Pathname basedir = spec.dirname();
+ Pathname rcpath = _tmprc.path();
+ Pathname macrospath = _tmpmacros.path();
+
+ std::ofstream macrosfile(macrospath.c_str());
+ if (!macrosfile)
+ ZYPP_THROW (Exception( "Can't open " + macrospath.asString() ) );
+
+ macrosfile << "%topdir " << _tmptop.path() << endl;
+ macrosfile << "%_builddir %{topdir}/build" << endl;
+ macrosfile << "%_rpmdir %{topdir}/rpms" << endl;
+ macrosfile << "%_srcrpmdir %{topdir}/rpms" << endl;
+ macrosfile << "%_sourcedir " << basedir << endl;
+ macrosfile << "%_specdir " << basedir << endl;
+
+ macrosfile.close();
+
+ const char* argv[] =
+ {
+ "rpmbuild",
+ "--rcfile",
+ rcpath.c_str(),
+ "-bb",
+ //"--clean",
+ "--buildroot",
+ _tmpbuildroot.path().c_str(),
+ spec.c_str(),
+ NULL
+ };
+ ExternalProgram prog(argv,ExternalProgram::Normal_Stderr, false, -1, true);
+ string line;
+ int count;
+ for(line = prog.receiveLine(), count=0; !line.empty(); line = prog.receiveLine(), count++ )
+ {
+ cout << line;
+ }
+ prog.close();
+
+ }
+
+private:
+ TmpDir _tmptop;
+ TmpFile _tmprc;
+ TmpFile _tmpmacros;
+ TmpDir _tmpbuildroot;
+};
+
+int main(int argc, char **argv)
+{
+ try
+ {
+ ZYpp::Ptr z = getZYpp();
+
+ //z->initializeTarget("/");
+ //z->target()->load();
+
+ //sat::Pool::instance().addRepoSolv("./foo.solv");
+
+// for ( ResPool::const_iterator it = z->pool().begin(); it != z->pool().end(); ++it )
+// {
+// ResObject::constPtr res = it->resolvable();
+// if ( res->name() == "kde4-kcolorchooser")
+// {
+// cout << res << endl;
+// cout << res->summary() << " | " << res->size() << endl;
+// }
+// }
+
+ //query.execute("kde", &result_cb);
+
+ RpmBuilder builder;
+ builder.buildSpec("/space/git/hwenable/spec/testdriver.spec");
+ builder.createRpmMetadata();
+
+
+ }
+ catch ( const Exception &e )
+ {
+ ZYPP_CAUGHT(e);
+ cout << e.msg() << endl;
+ }
+
+ return 0;
+}
+
+
+
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org