Mailinglist Archive: zypp-commit (266 mails)

< Previous Next >
[zypp-commit] r11783 - in /trunk/sat-solver/bindings: perl/tests/attr_values.pl solvable.i
  • From: kkaempf@xxxxxxxxxxxxxxxx
  • Date: Mon, 24 Nov 2008 12:31:26 -0000
  • Message-id: <20081124123126.31B1AFB7FA@xxxxxxxxxxxxxxxx>
Author: kkaempf
Date: Mon Nov 24 13:31:25 2008
New Revision: 11783

URL: http://svn.opensuse.org/viewcvs/zypp?rev=11783&view=rev
Log:
provide 'attr_values' callback for solvable: Iterates over values of a
specific attribute

Added:
trunk/sat-solver/bindings/perl/tests/attr_values.pl
Modified:
trunk/sat-solver/bindings/solvable.i

Added: trunk/sat-solver/bindings/perl/tests/attr_values.pl
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/perl/tests/attr_values.pl?rev=11783&view=auto
==============================================================================
--- trunk/sat-solver/bindings/perl/tests/attr_values.pl (added)
+++ trunk/sat-solver/bindings/perl/tests/attr_values.pl Mon Nov 24 13:31:25 2008
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+
+#
+# attr_values.pl
+#
+# Test iterating over values of a specific attribute
+#
+#
+
+use lib '../../../build/bindings/perl';
+
+use satsolver;
+
+
+# Create Pool and Repository
+my $pool = new satsolver::Pool;
+$pool->set_arch( "i686" );
+my $repo = $pool->create_repo('test') || die;
+
+# Add Solvable to Repository
+$repo->add_solv ("../../testdata/os11-beta5-i386.solv");
+
+$pool->prepare();
+
+# Print how much we have
+print "\"" . $repo->name() . "\" size: " . $repo->size() . "\n";
+
+print "\nFinding values for attribute 'solvable:keywords' ...\n";
+
+my $solvable = $repo->find("perl") || die;
+foreach my $value ($solvable->attr_values("solvable:keywords")) {
+ print " solvable keyword: $value\n";
+}
+

Modified: trunk/sat-solver/bindings/solvable.i
URL:
http://svn.opensuse.org/viewcvs/zypp/trunk/sat-solver/bindings/solvable.i?rev=11783&r1=11782&r2=11783&view=diff
==============================================================================
--- trunk/sat-solver/bindings/solvable.i (original)
+++ trunk/sat-solver/bindings/solvable.i Mon Nov 24 13:31:25 2008
@@ -237,15 +237,46 @@
rb_yield( value );
}
}
+ void attr_values(const char *name)
+ {
+ Solvable *s = xsolvable_solvable($self);
+ Dataiterator di;
+ dataiterator_init(&di, s->repo->pool, s->repo, $self->id,
str2id(pool,name,0), 0, SEARCH_NO_STORAGE_SOLVABLE);
+ VALUE value;
+ while (dataiterator_step(&di))
+ {
+ value = dataiterator_value ( &di );
+ rb_yield( value );
+ }
+ }
#endif
#if defined(SWIGPYTHON)
%pythoncode %{
def attrs(self):
- d = Dataiterator(self.repo().pool(),
self.repo(),"",SEARCH_NO_STORAGE_SOLVABLE,self)
+ d =
Dataiterator(self.repo().pool(),self.repo(),None,SEARCH_NO_STORAGE_SOLVABLE,self)
+ while d.step():
+ yield d.value()
+ def attr_values(self,name):
+ d =
Dataiterator(self.repo().pool(),self.repo(),None,SEARCH_NO_STORAGE_SOLVABLE,self,name)
while d.step():
yield d.value()
%}
#endif
+#if defined(SWIGPERL)
+ %perlcode %{
+ sub attr_values {
+ my ($self, $name) = @_;
+ my @values = ();
+
+ my $di = new
satsolver::Dataiterator($self->repo()->pool(),$self->repo(),undef,0,$self,$name);
+ while ($di->step() != 0) {
+ push @values, $di->value();
+ }
+
+ return wantarray ? @values : $values[0];
+ }
+ %}
+#endif

/*
* check existance of attribute

--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages