[New: openFATE 312825] Objects in YCP (YaST)

Feature added by: Martin Vidner (mvidner) Feature #312825, revision 1 Title: Objects in YCP (YaST) Hackweek VII: Unconfirmed Priority Requester: Important Requested by: Martin Vidner (mvidner) Partner organization: openSUSE.org Description: 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?v... // 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); } -- openSUSE Feature: https://features.opensuse.org/312825

Feature changed by: Martin Vidner (mvidner) Feature #312825, revision 2 Title: Objects in YCP (YaST) - Hackweek VII: Unconfirmed + Hackweek VII: Implementation Priority Requester: Important Requested by: Martin Vidner (mvidner) Partner organization: openSUSE.org Description: 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?v... // 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); } -- openSUSE Feature: https://features.opensuse.org/312825

Feature changed by: Martin Vidner (mvidner) Feature #312825, revision 3 Title: Objects in YCP (YaST) Hackweek VII: Implementation Priority Requester: Important Requested by: Martin Vidner (mvidner) Partner organization: openSUSE.org Description: 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?v... // 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); } + Discussion: + #1: Martin Vidner (mvidner) (2011-10-03 17:59:33) + yast2-ruby-bindings-0.3.8, soon in Factory + (https://build.opensuse.org/request/show/86266) , has my progress so + far: + instead of uri->scheme() , write URI::scheme(uri); + It works until Ruby runs garbage collection :-( I need to debug why + gc_mark did not have the intended effect. -- openSUSE Feature: https://features.opensuse.org/312825

Feature changed by: Martin Vidner (mvidner) Feature #312825, revision 4 Title: Objects in YCP (YaST) - Hackweek VII: Implementation + Hackweek VII: Done Priority Requester: Important Requested by: Martin Vidner (mvidner) Partner organization: openSUSE.org Description: 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?v... // 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); } Discussion: #1: Martin Vidner (mvidner) (2011-10-03 17:59:33) yast2-ruby-bindings-0.3.8, soon in Factory (https://build.opensuse.org/request/show/86266) , has my progress so far: instead of uri->scheme() , write URI::scheme(uri); It works until Ruby runs garbage collection :-( I need to debug why gc_mark did not have the intended effect. + #2: Martin Vidner (mvidner) (2013-10-04 16:21:58) + In the meantime we simply killed YCP, so this one is not needed + anymore. http://mvidner.blogspot.cz/2013/08/yast-in-ruby.html -- openSUSE Feature: https://features.opensuse.org/312825
participants (1)
-
fate_noreply@suse.de