Author: kkaempf
Date: Thu Feb 14 14:36:55 2008
New Revision: 8684
URL: http://svn.opensuse.org/viewcvs/zypp?rev=8684&view=rev
Log:
expose Repodata and Repokey in bindings
Added:
trunk/sat-solver/applayer/xrepokey.c
trunk/sat-solver/applayer/xrepokey.h
trunk/sat-solver/bindings/ruby/tests/10.3-x86_64.attr (with props)
trunk/sat-solver/bindings/ruby/tests/10.3-x86_64.solv (with props)
trunk/sat-solver/bindings/ruby/tests/repodata.rb
Modified:
trunk/sat-solver/applayer/CMakeLists.txt
trunk/sat-solver/bindings/satsolver.i
Modified: trunk/sat-solver/applayer/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/CMakeLists.txt?rev=8684&r1=8683&r2=8684&view=diff
==============================================================================
--- trunk/sat-solver/applayer/CMakeLists.txt (original)
+++ trunk/sat-solver/applayer/CMakeLists.txt Thu Feb 14 14:36:55 2008
@@ -5,12 +5,12 @@
ADD_SUBDIRECTORY(tests)
SET(libappsatsolver_SRCS action.c applayer.c covenant.c decision.c dependency.c
- problem.c relation.c solution.c transaction.c xsolvable.c)
+ problem.c relation.c solution.c transaction.c xrepokey.c xsolvable.c)
ADD_LIBRARY(appsatsolver STATIC ${libappsatsolver_SRCS})
SET(libappsatsolver_HEADERS action.h applayer.h covenant.h decision.h dependency.h
- problem.h relation.h solution.h transaction.h xsolvable.h)
+ problem.h relation.h solution.h transaction.h xrepokey.h xsolvable.h)
SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wall -Werror" )
Added: trunk/sat-solver/applayer/xrepokey.c
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/xrepokey.c?rev=8684&view=auto
==============================================================================
--- trunk/sat-solver/applayer/xrepokey.c (added)
+++ trunk/sat-solver/applayer/xrepokey.c Thu Feb 14 14:36:55 2008
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+/************************************************
+ * XRepokey - eXternally visible Repokey
+ *
+ * we cannot use a Repokey pointer since it doesn't reference the Pool
+ */
+
+#include
+#include
+
+#include "xrepokey.h"
+
+XRepokey *
+xrepokey_new( Repodata *repodata, int keynum )
+{
+ XRepokey *xrepokey = (XRepokey *)malloc( sizeof( XRepokey ));
+ xrepokey->repodata = repodata;
+ xrepokey->keynum = keynum;
+
+ return xrepokey;
+}
+
+
+void
+xrepokey_free( XRepokey *xr )
+{
+ free( xr );
+}
+
+
+Repokey *
+xrepokey_repokey( const XRepokey *xr )
+{
+ return xr->repodata->keys + xr->keynum;
+}
+
Added: trunk/sat-solver/applayer/xrepokey.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/applayer/xrepokey.h?rev=8684&view=auto
==============================================================================
--- trunk/sat-solver/applayer/xrepokey.h (added)
+++ trunk/sat-solver/applayer/xrepokey.h Thu Feb 14 14:36:55 2008
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2007, Novell Inc.
+ *
+ * This program is licensed under the BSD license, read LICENSE.BSD
+ * for further information
+ */
+
+#ifndef SATSOLVER_XREPOKEY_H
+#define SATSOLVER_XREPOKEY_H
+
+#include
+#include
+
+/************************************************
+ * XRepokey - eXternally visible Repokey
+ *
+ * we cannot use a Repokey pointer since it doesn't reference the Pool
+ */
+
+typedef struct _xrepokey {
+ Repodata *repodata;
+ int keynum;
+} XRepokey;
+
+XRepokey *xrepokey_new( Repodata *repodata, int keynum );
+void xrepokey_free( XRepokey *xr );
+Repokey *xrepokey_repokey( const XRepokey *xr );
+
+#endif /* SATSOLVER_XREPOKEY_H */
Added: trunk/sat-solver/bindings/ruby/tests/10.3-x86_64.attr
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/10.3-x86_64.attr?rev=8684&view=auto
==============================================================================
Binary file - no diff available.
Added: trunk/sat-solver/bindings/ruby/tests/10.3-x86_64.solv
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/10.3-x86_64.solv?rev=8684&view=auto
==============================================================================
Binary file - no diff available.
Added: trunk/sat-solver/bindings/ruby/tests/repodata.rb
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/ruby/tests/repodata.rb?rev=8684&view=auto
==============================================================================
--- trunk/sat-solver/bindings/ruby/tests/repodata.rb (added)
+++ trunk/sat-solver/bindings/ruby/tests/repodata.rb Thu Feb 14 14:36:55 2008
@@ -0,0 +1,37 @@
+#
+# Check Repodata of Repo
+#
+
+$:.unshift "../../../build/bindings/ruby"
+
+# test Repodata
+require 'test/unit'
+require 'satsolver'
+
+class RepodataTest < Test::Unit::TestCase
+ def test_repo_create
+ pool = SatSolver::Pool.new
+ assert pool
+ pool.arch = "x86_64"
+ repo = pool.add_solv( "10.3-x86_64.solv" )
+ repo.name = "10.3-x86_64"
+ puts "Repo #{repo.name} loaded with #{repo.size} solvables"
+
+ puts "Repo has #{repo.datasize} Repodatas attached"
+ assert repo.datasize > 0
+ assert repo.data(-1) == nil
+ assert repo.data(repo.datasize) == nil
+ assert repo.data(repo.datasize-1)
+ repo.each_data { |d|
+ assert d
+ }
+
+ repodata = repo.data(0)
+ assert repodata
+
+ puts "Repodata is at '#{repodata.location}' with #{repodata.keysize} keys"
+ repodata.each_key { |k|
+ puts " Key '#{k.name}' is #{k.type} with #{k.size} bytes"
+ }
+ end
+end
Modified: trunk/sat-solver/bindings/satsolver.i
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/satsolver.i?rev=8684&r1=8683&r2=8684&view=diff
==============================================================================
--- trunk/sat-solver/bindings/satsolver.i (original)
+++ trunk/sat-solver/bindings/satsolver.i Thu Feb 14 14:36:55 2008
@@ -4,7 +4,7 @@
* SatSolver is the module namespace for sat-solver bindings.
*
* sat-solver is a dependency solver for rpm-style dependencies
- * based on a Satifyability engine.
+ * based on a Satisfyability engine.
*
*
* It might make a lot of sense to make Pool* a singular within
@@ -48,6 +48,7 @@
/* satsolver application layer includes */
#include "applayer.h"
#include "xsolvable.h"
+#include "xrepokey.h"
#include "relation.h"
#include "dependency.h"
#include "action.h"
@@ -159,13 +160,25 @@
typedef int Id;
typedef unsigned int Offset;
+/*
+ * just define empty structs to expose the type to SWIG
+ */
+
%nodefault _Repo;
%rename(Repo) _Repo;
typedef struct _Repo {} Repo;
+%nodefault _Repodata;
+%rename(Repodata) _Repodata;
+typedef struct _Repodata {} Repodata;
+
+%nodefault _Repokey;
+%rename(Repokey) _Repokey;
+typedef struct _Repokey {} XRepokey; /* expose XRepokey as 'Repokey' */
+
%nodefault _Solvable;
%rename(Solvable) _Solvable;
-typedef struct _Solvable {} XSolvable;
+typedef struct _Solvable {} XSolvable; /* expose XSolvable as 'Solvable' */
%nodefault _Relation;
%rename(Relation) _Relation;
@@ -464,7 +477,7 @@
%alias get "[]";
#endif
/*
- * get solvable by index
+ * get xsolvable by index
*/
XSolvable *get( int i )
{ return xsolvable_get( $self->pool, i, $self ); }
@@ -475,6 +488,97 @@
XSolvable *find( char *name )
{ return xsolvable_find( $self->pool, name, $self ); }
+ /* return number of attached Repodata(s) */
+ int datasize()
+ { return $self->nrepodata; }
+
+ /*
+ * get Repodata by index
+ */
+ Repodata *data( int i )
+ {
+ if (i >= 0 && i < $self->nrepodata)
+ return $self->repodata + i;
+ return NULL;
+ }
+
+#if defined(SWIGRUBY)
+ /*
+ * Iterate over each Repodata
+ */
+ void each_data()
+ {
+ int i;
+ for (i = 0; i < $self->nrepodata; ++i ) {
+ rb_yield( SWIG_NewPointerObj((void*) $self->repodata + i, SWIGTYPE_p__Repodata, 0) );
+ }
+ }
+#endif
+}
+
+/*-------------------------------------------------------------*/
+/* Repodata */
+
+%extend Repodata {
+ /* no constructor, Repodata is embedded in Repo */
+
+ /* number of keys in this Repodata */
+ int keysize()
+ { return $self->nkeys-1; } /* key 0 is reserved */
+
+ /* (File) location of this Repodata, nil if embedded */
+ const char *location()
+ { return $self->location; }
+
+ /* access Repokey by index */
+ XRepokey *key( int i )
+ {
+ if (i >= 0 && i < $self->nkeys-1)
+ return xrepokey_new( $self, i+1 ); /* key 0 is reserved */
+ return NULL;
+ }
+
+#if defined(SWIGRUBY)
+ /*
+ * Iterate over each key
+ */
+ void each_key()
+ {
+ int i;
+ for (i = 1; i < $self->nkeys; ++i ) {
+ rb_yield( SWIG_NewPointerObj((void*) xrepokey_new( $self, i ), SWIGTYPE_p__Repokey, 0) );
+ }
+ }
+#endif
+}
+
+/*-------------------------------------------------------------*/
+/* XRepokey */
+
+%extend XRepokey {
+ /* no explicit constructor, Repokey is embedded in Repodata */
+
+ ~XRepokey()
+ { xrepokey_free( $self ); }
+
+ /* name of key */
+ const char *name()
+ {
+ Repokey *key = xrepokey_repokey( $self );
+ return my_id2str( $self->repodata->repo->pool, key->name );
+ }
+ /* type of key */
+ int type()
+ {
+ Repokey *key = xrepokey_repokey( $self );
+ return key->type;
+ }
+ /* size of key */
+ int size()
+ {
+ Repokey *key = xrepokey_repokey( $self );
+ return key->size;
+ }
}
/*-------------------------------------------------------------*/
@@ -611,7 +715,9 @@
XSolvable( Repo *repo, const char *name, const char *evr, const char *arch = NULL )
{ return xsolvable_create( repo, name, evr, arch ); }
-
+ ~XSolvable()
+ { return xsolvable_free( $self ); }
+
Repo *repo()
{ return xsolvable_solvable($self)->repo; }
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org