Mailinglist Archive: yast-devel (74 mails)

< Previous Next >
[yast-devel] Objects in YCP (HackWeek?)
Hi,

I have this idea and Lukas has pointed out that someone could be
interested in it for the Hack Week, so here goes:

As I am thinking about refactoring the network code, not having
objects in YCP is a pain. The twist is, I don't want to add YCP
objects but use Ruby objects. (We can already use Perl objects,
yast2-storage does it, but it's limited.)

Here's sample code to show how it could look, modeled after
http://www.ruby-doc.org/stdlib-1.8.7/libdoc/uri/rdoc/classes/URI.html

{
import "Assert";
// Yes, you can! (also in SP2)
//
http://svn.opensuse.org/viewvc/yast/trunk/yast2/library/modules/Assert.ycp?view=markup

// Original Ruby code:
// require 'uri'
import $[
"what": "uri",
"language": "ruby",
"namespaces": ["URI", "URI::HTTP"]
];
/*
The above complicated syntax enables
- loading modules from elsewhere than /usr/share/YaST2/modules
- loading YCP namespaces (Ruby modules (classes))
named otherwise than the file they are in,
without needing to annotate them with TYPEINFO
(like perl-bindings/pluglib-bindings do)
*/

// uri = URI.parse("http://www.ruby-lang.org/";)
any uri = URI::parse("http://www.ruby-lang.org/";); // [1]
// assert_equal "http", uri.scheme
Assert::Equal("http", uri->scheme());

// newuri = URI::HTTP.build( {:host => 'www.example.com', :path =>
'/foo/bar'})
any newuri = URI::HTTP::build($[ `host: "www.example.com", `path:
"/foo/bar"]);
// assert_equal "http://www.example.com/foo/bar";, newuri.request_uri
Assert::Equal ("http://www.example.com/foo/bar";, newuri->request_uri());
}

Formally, whereas now YCP has
NAMESPACE :: IDENTIFIER ( PARAMS )
which calls a function (a module/class method in Ruby, a class
method in Perl), we add
EXPRESSION -> IDENTIFIER ( PARAMS )
which calls a method (an instance method in Ruby.

[1] "any" is a lie, the type is actually a distinct one,
called YCPExternal in C++. We could use "extern" which is currently
an unused reserved word in YCP.

But URIs are not my target. I am aiming for

{
any eth = SUSE::Ifcfg::new("eth0");

any br = SUSE::Ifcfg::Bridge::new("br0");
br->startmode(`auto);
br->add(eth);
/*
br->add will also set:
eth->bootproto(`none);
eth->startmode(br->startmode());
*/

any tap = SUSE::Ifcfg::Tap::new("tap0")->tunnel_set_owner("tux");
br->add(tap);

foreach(any i, [br, tap, eth], { i->save(); });
}


if (you->are_interested()) {
you->please()->tell(martin);
}
--
Martin Vidner, YaST developer
http://en.opensuse.org/User:Mvidner

kthxbai();
< Previous Next >
Follow Ups