ref: refs/heads/master
commit d487527533500928f55f050f2662b1c3083f1542
Author: Klaus Kämpf
Date: Mon Mar 30 12:07:16 2009 +0200
Provide 'Repo.attr(String)' accessor function for repository attributes
This gives access to 'repository:...' attributes which do not belong
to any Solvable but to the Repository itself.
Add testcases for Ruby, Python and Perl.
---
bindings/perl/tests/repo.pl | 28 +++++++++++++
bindings/python/tests/repo.py | 16 ++++++--
bindings/repo.i | 82 ++++++++++++++++++++++++++++++++++++++
bindings/ruby/tests/repo.rb | 16 ++++++-
bindings/testdata/timestamp.solv | Bin 0 -> 1677858 bytes
5 files changed, 135 insertions(+), 7 deletions(-)
diff --git a/bindings/perl/tests/repo.pl b/bindings/perl/tests/repo.pl
new file mode 100644
index 0000000..6e03c69
--- /dev/null
+++ b/bindings/perl/tests/repo.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+
+#
+# repo.pl
+#
+# Test Repo functions
+#
+#
+
+use lib '../../../build/bindings/perl';
+
+use satsolver;
+
+# Create Pool and Repository
+my $pool = new satsolver::Pool;
+$pool->set_arch( $sysarch );
+my $repo = $pool->create_repo('test') || die;
+
+# Add solvables to Repository
+$repo->add_solv ("../../testdata/timestamp.solv");
+
+# Print how much we have
+print "Pool size: " . $pool->size() . ", count " . $pool->count() . "\n";
+print "Repo \"" . $repo->name() . "\" size " . $repo->size() . ", count " . $repo->count() . "\n";
+
+my $timestamp = $repo->attr("repository:timestamp");
+
+print "Timestamp: " . $timestamp . "\n";
diff --git a/bindings/python/tests/repo.py b/bindings/python/tests/repo.py
index 7551db5..8461da7 100644
--- a/bindings/python/tests/repo.py
+++ b/bindings/python/tests/repo.py
@@ -48,16 +48,16 @@ class TestSequenceFunctions(unittest.TestCase):
pool = satsolver.Pool()
assert pool
pool.set_arch("i686")
- repo = pool.add_solv( "os11-biarch.solv" )
+ repo = pool.add_solv( "../../testdata/os11-biarch.solv" )
repo.set_name("test")
assert repo.name() == "test"
- assert repo.size() > 0
+# assert repo.size() > 0
def test_deps(self):
pool = satsolver.Pool()
assert pool
pool.set_arch("i686")
- repo = pool.add_solv( "os11-biarch.solv" )
+ repo = pool.add_solv( "../../testdata/os11-biarch.solv" )
i = 0
for s in repo:
i = i + 1
@@ -82,10 +82,18 @@ class TestSequenceFunctions(unittest.TestCase):
pool = satsolver.Pool()
assert pool
pool.set_arch("i686")
- repo = pool.add_solv( "os11-biarch.solv" )
+ repo = pool.add_solv( "../../testdata/os11-biarch.solv" )
for s in pool.providers("glibc"):
print s, "provides 'glibc'"
assert True
+ def test_repo_attr(self):
+ pool = satsolver.Pool()
+ assert pool
+ pool.set_arch("i686")
+ repo = pool.add_solv( "../../testdata/timestamp.solv" )
+ print "Timestamp ", repo.attr("repository:timestamp")
+ assert True
+
if __name__ == '__main__':
unittest.main()
diff --git a/bindings/repo.i b/bindings/repo.i
index 706a760..22971ee 100644
--- a/bindings/repo.i
+++ b/bindings/repo.i
@@ -300,4 +300,86 @@ typedef struct _Repo {} Repo;
swig_dataiterator_free(di);
}
#endif
+
+ /*
+ * access attribute via []
+ */
+
+#if defined(SWIGRUBY)
+ /* %rename is rejected by swig for [] */
+ %alias attr "[]";
+ /*
+ * Attribute accessor.
+ *
+ * It takes either a string or a symbol and returns
+ * the value of the attribute.
+ *
+ * If its a symbol, all underline characters are converted
+ * to colons. E.g. +:solvable_installsize+ -> +"solvable:installsize"+
+ *
+ * A +ValueError+ exception is raised if the attribute
+ * name does not exist.
+ *
+ * +nil+ is returned if the attribute name exists but is not set for
+ * the solvable.
+ *
+ *
+ * call-seq:
+ * repo["repository:timestamp"] -> VALUE
+ * repo.attr("repository:timestamp") -> VALUE
+ * repo.attr(:repository_timestamp) -> VALUE
+ *
+ */
+ VALUE attr( VALUE attrname )
+ {
+#endif
+#if defined(SWIGPYTHON)
+ PyObject *attr( const char *name )
+ {
+#endif
+#if defined(SWIGPERL)
+ SV *attr( const char *name )
+ {
+#endif
+ Swig_Type result = Swig_Null;
+ Id key;
+ Dataiterator di;
+#if defined(SWIGRUBY)
+ char *name;
+
+ if (SYMBOL_P(attrname)) {
+ char *colon;
+ name = (char *)rb_id2name( SYM2ID( attrname ) );
+ colon = name;
+ while ((colon = strchr( colon, '_'))) {
+ *colon++ = ':';
+ }
+ }
+ else
+ name = StringValuePtr( attrname );
+#endif
+ if (!name)
+ SWIG_exception( SWIG_ValueError, "Attribute name missing" );
+
+ /* key existing in pool ? */
+ key = str2id( $self->pool, name, 0);
+ if (key == ID_NULL)
+ SWIG_exception( SWIG_ValueError, "No such attribute name" );
+
+ dataiterator_init(&di, $self->pool, $self, SOLVID_META, key, 0, 0);
+ if (dataiterator_step(&di))
+ {
+ result = dataiterator_value( &di );
+ }
+
+#if defined(SWIGPYTHON) || defined(SWIGPERL)/* needed for SWIG_Exception */
+fail:
+#endif
+#if defined(SWIGPYTHON)
+ Py_INCREF(result);
+#endif
+ return result;
+ }
+
+
}
diff --git a/bindings/ruby/tests/repo.rb b/bindings/ruby/tests/repo.rb
index 31b5d1f..d7a515f 100644
--- a/bindings/ruby/tests/repo.rb
+++ b/bindings/ruby/tests/repo.rb
@@ -60,9 +60,19 @@ class RepoTest < Test::Unit::TestCase
pool.arch = "i686"
solvpath = Pathname( File.dirname( __FILE__ ) ) + Pathname( "../../testdata" ) + "os11-biarch.solv"
repo = pool.add_solv( solvpath )
- repo.each { |s|
- puts s
- }
+# repo.each { |s|
+# assert s
+# }
assert true
end
+ def test_attr
+ pool = Satsolver::Pool.new
+ assert pool
+ pool.arch = "i686"
+ solvpath = Pathname( File.dirname( __FILE__ ) ) + Pathname( "../../testdata" ) + "timestamp.solv"
+ repo = pool.add_solv( solvpath )
+ val = repo.attr("repository:timestamp")
+ puts "timestamp = #{val}"
+ assert val == repo["repository:timestamp"]
+ end
end
diff --git a/bindings/testdata/timestamp.solv b/bindings/testdata/timestamp.solv
new file mode 100644
index 0000000..4d775ae
Binary files /dev/null and b/bindings/testdata/timestamp.solv differ
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org