Hello community,
here is the log from the commit of package yast2-ruby-bindings
checked in at Thu Sep 20 14:34:56 CEST 2007.
--------
--- yast2-ruby-bindings/yast2-ruby-bindings.changes 2007-08-09 12:50:06.000000000 +0200
+++ /mounts/work_src_done/STABLE/yast2-ruby-bindings/yast2-ruby-bindings.changes 2007-09-20 11:50:22.000000000 +0200
@@ -1,0 +2,7 @@
+Wed Sep 19 16:42:35 CEST 2007 - dmacvicar(a)suse.de
+
+- Lot of improvements, examples and
+ support for the YaST UI
+- 0.2.0
+
+-------------------------------------------------------------------
Old:
----
yast2-ruby-bindings-0.1.0.tar.bz2
New:
----
yast2-ruby-bindings-0.2.0.tar.bz2
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ yast2-ruby-bindings.spec ++++++
--- /var/tmp/diff_new_pack.a21580/_old 2007-09-20 14:34:43.000000000 +0200
+++ /var/tmp/diff_new_pack.a21580/_new 2007-09-20 14:34:43.000000000 +0200
@@ -1,5 +1,5 @@
#
-# spec file for package yast2-ruby-bindings (Version 0.1.0)
+# spec file for package yast2-ruby-bindings (Version 0.2.0)
#
# Copyright (c) 2007 SUSE LINUX Products GmbH, Nuernberg, Germany.
# This file and all modifications and additions to the pristine
@@ -11,13 +11,13 @@
# norootforbuild
Name: yast2-ruby-bindings
-Version: 0.1.0
-Release: 3
+Version: 0.2.0
+Release: 1
License: GPL v2 or later
Group: System/YaST
BuildRoot: %{_tmppath}/%{name}-%{version}-build
Source0: yast2-ruby-bindings-%{version}.tar.bz2
-prefix: /usr
+Prefix: /usr
BuildRequires: cmake gcc-c++ libxcrypt-devel swig yast2-core-devel yast2-devtools
# libzypp-devel is missing .la requires
BuildRequires: ruby-devel
@@ -57,9 +57,13 @@
%files
%defattr (-, root, root)
%{_libdir}/YaST2/plugin/libpy2lang_ruby.so
-%{_libdir}/ruby/vendor_ruby/%{rb_ver}/%{rb_arch}/yast.so
-
+%{_libdir}/ruby/vendor_ruby/%{rb_ver}/%{rb_arch}/yastx.so
+%{_libdir}/ruby/vendor_ruby/%{rb_ver}/yast.rb
%changelog
+* Wed Sep 19 2007 - dmacvicar(a)suse.de
+- Lot of improvements, examples and
+ support for the YaST UI
+- 0.2.0
* Thu Aug 09 2007 - dmacvicar(a)suse.de
- Fix build on 64 bits
- Use ruby vendor arch dir
++++++ yast2-ruby-bindings-0.1.0.tar.bz2 -> yast2-ruby-bindings-0.2.0.tar.bz2 ++++++
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/yast2-ruby-bindings-0.1.0/examples/ruby/libycp.rb new/yast2-ruby-bindings-0.2.0/examples/ruby/libycp.rb
--- old/yast2-ruby-bindings-0.1.0/examples/ruby/libycp.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/yast2-ruby-bindings-0.2.0/examples/ruby/libycp.rb 2007-09-20 11:17:19.000000000 +0200
@@ -0,0 +1,45 @@
+require 'ryast'
+include Ryast
+
+def get_ns(name)
+ import = Import.new(name)
+ ns = import.name_space
+ puts ns.filename
+ #ns.initialize
+
+ return ns
+end
+
+component = Y2ComponentBroker.get_namespace_component("Arch");
+#puts component.methods
+#Y2Namespace *ns = c->import(RSTRING (namespace_name)->ptr);
+nsname = "Arch"
+fncname = "sparc32"
+ns = get_ns(nsname)
+#/**/
+#t = Type.from_signature("bool()")
+#puts t
+sym = ns.table.find(fncname);
+puts sym.class
+if (sym.nil?)
+ raise ("No such symbol #{nsname}::#{fncname}")
+elsif (sym.sentry.is_variable or sym.sentry.reference? )
+ # set the variable
+ #ret_yv = YCP_getset_variable (aTHX_ ns_name, sym_te->sentry (), args);
+else
+ fnccall = ns.create_function_call(fncname, nil)
+ if fnccall.nil?
+ raise("No such function #{nsname}::#{fncname}")
+ end
+end
+exit
+
+h = ns.lookup_symbol("sparc32")
+puts h.class
+exit
+function = ns.create_function_call("sparc32",0)
+#call->appendParameter (v);
+function.finish_parameters
+res = function.evaluate_call
+puts res
+exit
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/yast2-ruby-bindings-0.1.0/examples/ruby/logger.rb new/yast2-ruby-bindings-0.2.0/examples/ruby/logger.rb
--- old/yast2-ruby-bindings-0.1.0/examples/ruby/logger.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/yast2-ruby-bindings-0.2.0/examples/ruby/logger.rb 2007-09-20 11:17:19.000000000 +0200
@@ -0,0 +1,5 @@
+require 'yast'
+include YaST
+#ui = YaST::Module.new("UI")
+
+y2milestone("Hello")
\ No newline at end of file
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/yast2-ruby-bindings-0.1.0/examples/ruby/module-arch.rb new/yast2-ruby-bindings-0.2.0/examples/ruby/module-arch.rb
--- old/yast2-ruby-bindings-0.1.0/examples/ruby/module-arch.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/yast2-ruby-bindings-0.2.0/examples/ruby/module-arch.rb 2007-09-20 11:17:19.000000000 +0200
@@ -0,0 +1,6 @@
+require 'yast'
+
+m = YaST::Module.new("Arch")
+puts m.sparc32
+puts m.arch_short
+puts m.is_xen
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/yast2-ruby-bindings-0.1.0/examples/ruby/module-storage.rb new/yast2-ruby-bindings-0.2.0/examples/ruby/module-storage.rb
--- old/yast2-ruby-bindings-0.1.0/examples/ruby/module-storage.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/yast2-ruby-bindings-0.2.0/examples/ruby/module-storage.rb 2007-09-20 11:17:19.000000000 +0200
@@ -0,0 +1,7 @@
+require 'yast'
+
+m = YaST::Module.new("Storage")
+dp = m.GetDiskPartition("/dev/sda1")
+dp.each do | key, value |
+ puts "#{key} #{value}"
+end
\ No newline at end of file
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/yast2-ruby-bindings-0.1.0/examples/ruby/module-timezone.rb new/yast2-ruby-bindings-0.2.0/examples/ruby/module-timezone.rb
--- old/yast2-ruby-bindings-0.1.0/examples/ruby/module-timezone.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/yast2-ruby-bindings-0.2.0/examples/ruby/module-timezone.rb 2007-09-20 11:17:19.000000000 +0200
@@ -0,0 +1,12 @@
+require 'yast'
+
+m = YaST::Module.new("Timezone")
+zonemap = m.get_zonemap()
+puts zonemap.class
+zonemap.each do | element |
+ element.each do | key, value |
+ value.each do | k, v |
+ puts "#{k} #{v}"
+ end
+ end
+end
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/yast2-ruby-bindings-0.1.0/examples/ruby/test1.rb new/yast2-ruby-bindings-0.2.0/examples/ruby/test1.rb
--- old/yast2-ruby-bindings-0.1.0/examples/ruby/test1.rb 2007-08-09 12:49:30.000000000 +0200
+++ new/yast2-ruby-bindings-0.2.0/examples/ruby/test1.rb 1970-01-01 01:00:00.000000000 +0100
@@ -1,45 +0,0 @@
-require 'ryast'
-include Ryast
-
-def get_ns(name)
- import = Import.new(name)
- ns = import.name_space
- puts ns.filename
- #ns.initialize
-
- return ns
-end
-
-component = Y2ComponentBroker.get_namespace_component("Arch");
-#puts component.methods
-#Y2Namespace *ns = c->import(RSTRING (namespace_name)->ptr);
-nsname = "Arch"
-fncname = "sparc32"
-ns = get_ns(nsname)
-#/**/
-#t = Type.from_signature("bool()")
-#puts t
-sym = ns.table.find(fncname);
-puts sym.class
-if (sym.nil?)
- raise ("No such symbol #{nsname}::#{fncname}")
-elsif (sym.sentry.is_variable or sym.sentry.reference? )
- # set the variable
- #ret_yv = YCP_getset_variable (aTHX_ ns_name, sym_te->sentry (), args);
-else
- fnccall = ns.create_function_call(fncname, nil)
- if fnccall.nil?
- raise("No such function #{nsname}::#{fncname}")
- end
-end
-exit
-
-h = ns.lookup_symbol("sparc32")
-puts h.class
-exit
-function = ns.create_function_call("sparc32",0)
-#call->appendParameter (v);
-function.finish_parameters
-res = function.evaluate_call
-puts res
-exit
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/yast2-ruby-bindings-0.1.0/examples/ruby/ui.rb new/yast2-ruby-bindings-0.2.0/examples/ruby/ui.rb
--- old/yast2-ruby-bindings-0.1.0/examples/ruby/ui.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/yast2-ruby-bindings-0.2.0/examples/ruby/ui.rb 2007-09-20 11:17:19.000000000 +0200
@@ -0,0 +1,22 @@
+require 'yast'
+ui = YaST::Module.new("UI")
+YaST::Ui::init("qt")
+include YaST::Ui
+
+t = HBox( Label("Welcome to Ruby!"), PushButton("Push me") )
+
+puts "#{t.to_s} #{t.class}"
+
+ui.OpenDialog(t)
+ui.UserInput()
+
+# You can also use downcase, as the symbols are aliased
+t = hbox( label("Welcome to Ruby!"), pushbutton("Push me") )
+
+puts "#{t.to_s} #{t.class}"
+
+ui.OpenDialog(t)
+ui.UserInput()
+
+
+exit
\ No newline at end of file
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/yast2-ruby-bindings-0.1.0/examples/ruby/ycp_from_ruby.rb new/yast2-ruby-bindings-0.2.0/examples/ruby/ycp_from_ruby.rb
--- old/yast2-ruby-bindings-0.1.0/examples/ruby/ycp_from_ruby.rb 2007-08-09 12:49:30.000000000 +0200
+++ new/yast2-ruby-bindings-0.2.0/examples/ruby/ycp_from_ruby.rb 1970-01-01 01:00:00.000000000 +0100
@@ -1,35 +0,0 @@
-require 'yast'
-
-m = YaST::Module.new("SCR")
-m.Read(".proc.modules")
-
-exit
-m = YaST::Module.new("Timezone")
-zonemap = m.get_zonemap()
-puts zonemap.class
-zonemap.each do | element |
- element.each do | key, value |
- value.each do | k, v |
- puts "#{k} #{v}"
- end
- end
-end
-
-
-exit
-m = YaST::Module.new("Arch")
-puts m.sparc32
-puts m.arch_short
-puts m.is_xen
-
-m = YaST::Module.new("Popup")
-m.Message("Hello")
-
-
-m = YaST::Module.new("Storage")
-dp = m.GetDiskPartition("/dev/sda1")
-dp.each do | key, value |
- puts "#{key} #{value}"
-end
-
-
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/yast2-ruby-bindings-0.1.0/src/ruby/CMakeLists.txt new/yast2-ruby-bindings-0.2.0/src/ruby/CMakeLists.txt
--- old/yast2-ruby-bindings-0.1.0/src/ruby/CMakeLists.txt 2007-08-09 12:49:30.000000000 +0200
+++ new/yast2-ruby-bindings-0.2.0/src/ruby/CMakeLists.txt 2007-09-20 11:17:19.000000000 +0200
@@ -32,14 +32,16 @@
INCLUDE_DIRECTORIES( ${RUBY_INCLUDE_PATH} )
INCLUDE_DIRECTORIES( ${YAST_INCLUDE_DIR} )
-ADD_LIBRARY( yast SHARED ${yast_ruby_module_SRCS})
-SET_TARGET_PROPERTIES( yast PROPERTIES PREFIX "" )
-TARGET_LINK_LIBRARIES( yast ${YAST_LIBRARY} )
-TARGET_LINK_LIBRARIES( yast ${YAST_YCP_LIBRARY} )
-TARGET_LINK_LIBRARIES( yast ${YAST_PLUGIN_WFM_LIBRARY} )
-TARGET_LINK_LIBRARIES( yast ${YAST_PLUGIN_SCR_LIBRARY} )
-TARGET_LINK_LIBRARIES( yast ${RUBY_LIBRARY} )
-INSTALL(TARGETS yast LIBRARY DESTINATION ${RUBY_VENDORARCH_DIR} )
+ADD_LIBRARY( yastx SHARED ${yast_ruby_module_SRCS})
+SET_TARGET_PROPERTIES( yastx PROPERTIES PREFIX "" )
+TARGET_LINK_LIBRARIES( yastx ${YAST_LIBRARY} )
+TARGET_LINK_LIBRARIES( yastx ${YAST_YCP_LIBRARY} )
+TARGET_LINK_LIBRARIES( yastx ${YAST_PLUGIN_WFM_LIBRARY} )
+TARGET_LINK_LIBRARIES( yastx ${YAST_PLUGIN_SCR_LIBRARY} )
+TARGET_LINK_LIBRARIES( yastx ${RUBY_LIBRARY} )
+INSTALL(TARGETS yastx LIBRARY DESTINATION ${RUBY_VENDORARCH_DIR} )
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/yast.rb DESTINATION ${RUBY_VENDORLIB_DIR} )
ADD_LIBRARY( py2lang_ruby SHARED ${ruby_yast_plugin_SRCS})
TARGET_LINK_LIBRARIES( py2lang_ruby ${YAST_LIBRARY} )
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/yast2-ruby-bindings-0.1.0/src/ruby/Y2CCRuby.cc new/yast2-ruby-bindings-0.2.0/src/ruby/Y2CCRuby.cc
--- old/yast2-ruby-bindings-0.1.0/src/ruby/Y2CCRuby.cc 2007-08-09 12:49:30.000000000 +0200
+++ new/yast2-ruby-bindings-0.2.0/src/ruby/Y2CCRuby.cc 2007-09-20 11:17:19.000000000 +0200
@@ -46,9 +46,10 @@
// is there a ruby module?
// must be the same in Y2CCRuby and Y2RubyComponent
string module = YCPPathSearch::find (YCPPathSearch::Module, string (name) + ".rb");
- y2milestone("Find result '%s'", module.c_str());
+
if (!module.empty ())
{
+ y2milestone("Find module result: '%s'", module.c_str());
if (!cruby)
{
y2milestone("new ruby component");
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/yast2-ruby-bindings-0.1.0/src/ruby/Y2RubyTypeConv.cc new/yast2-ruby-bindings-0.2.0/src/ruby/Y2RubyTypeConv.cc
--- old/yast2-ruby-bindings-0.1.0/src/ruby/Y2RubyTypeConv.cc 2007-08-09 12:49:30.000000000 +0200
+++ new/yast2-ruby-bindings-0.2.0/src/ruby/Y2RubyTypeConv.cc 2007-09-20 11:17:19.000000000 +0200
@@ -40,6 +40,8 @@
#include "Y2RubyTypeConv.h"
+#define IS_A(obj,klass) ((rb_obj_is_kind_of((obj),(klass))==Qtrue)?1:0)
+
static YCPMap rbhash_2_ycpmap( VALUE value )
{
YCPMap map;
@@ -96,7 +98,7 @@
}
else if (ycpval->isTerm())
{
- return ryast_term_from_term(ycpval->asTerm());
+ return ryast_rterm_from_yterm(ycpval->asTerm());
}
else if (ycpval->isInteger())
{
@@ -138,7 +140,7 @@
YCPSymbol symbol = ycpval->asSymbol();
return rb_intern(symbol->symbol_cstr());
}
- rb_raise( rb_eRuntimeError, "Conversion of YCP type %s not supported", ycpval->toString().c_str() );
+ rb_raise( rb_eTypeError, "Conversion of YCP type %s not supported", ycpval->toString().c_str() );
return Qnil;
}
@@ -146,7 +148,9 @@
YCPValue
rbvalue_2_ycpvalue( VALUE value )
{
- y2internal("type: '%d'", TYPE(value));
+ VALUE klass = rb_funcall( value, rb_intern("class"), 0);
+ //std::cout << RSTRING( rb_funcall( klass, rb_intern("to_s"), 0))->ptr << " | " << RSTRING(rb_funcall( value, rb_intern("inspect"), 0))->ptr << std::endl;
+ //y2internal("type: '%d'", TYPE(value));
// TODO conver integers, and add support for lists, ah, and boleans!
switch (TYPE(value))
{
@@ -175,12 +179,17 @@
break;
case T_SYMBOL:
return YCPSymbol(rb_id2name(rb_to_id(value)));
- case T_DATA:
- rb_raise( rb_eRuntimeError, "Object");
+ //case T_DATA:
+ // rb_raise( rb_eRuntimeError, "Object");
break;
default:
- std::cout << TYPE(value) << std::endl;
- rb_raise( rb_eRuntimeError, "Conversion of Ruby type not supported");
+ string class_name(RSTRING(rb_funcall(rb_funcall(value, rb_intern("class"), 0), rb_intern("to_s"), 0))->ptr);
+ /* get the Term class object */
+ if ( class_name == "YaST::Term" )
+ {
+ return ryast_yterm_from_rterm(value);
+ }
+ rb_raise( rb_eTypeError, "Conversion of Ruby type not supported");
return YCPValue();
}
}
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/yast2-ruby-bindings-0.1.0/src/ruby/Y2RubyTypeTerm.cc new/yast2-ruby-bindings-0.2.0/src/ruby/Y2RubyTypeTerm.cc
--- old/yast2-ruby-bindings-0.1.0/src/ruby/Y2RubyTypeTerm.cc 2007-08-09 12:49:30.000000000 +0200
+++ new/yast2-ruby-bindings-0.2.0/src/ruby/Y2RubyTypeTerm.cc 2007-09-20 11:17:19.000000000 +0200
@@ -48,13 +48,21 @@
}
VALUE
-ryast_term_from_term( const YCPTerm &term )
+ryast_rterm_from_yterm( const YCPTerm &term )
{
VALUE rterm_obj = rb_funcall( ryast_cTerm, rb_intern("new"), 0);
ryast_term_set_term( rterm_obj, term );
return rterm_obj;
}
+YCPTerm
+ryast_yterm_from_rterm( VALUE term )
+{
+ ryast_Term_Wrapper *wrapper;
+ Data_Get_Struct(term, ryast_Term_Wrapper, wrapper);
+ return wrapper->term;
+}
+
static void
ryast_term_mark (ryast_Term_Wrapper *r)
{
@@ -90,6 +98,27 @@
return self;
}
+static VALUE
+ryast_term_add( int argc, VALUE *argv, VALUE self )
+{
+ ryast_Term_Wrapper *wrapper;
+ Data_Get_Struct(self, ryast_Term_Wrapper, wrapper);
+
+ // we should be using rb_scan_args here but I couldn't get it to work.
+
+ // add the remaining YCPTerm arguments
+ if (argc > 0)
+ {
+ int i=0;
+ for ( ; i<argc; ++i )
+ {
+ //std::cout << "Hi! term::add: " << TYPE(argv[i]) << std::endl;
+ YCPValue value = rbvalue_2_ycpvalue(argv[i]);
+ wrapper->term->add(value);
+ }
+ }
+ return self;
+}
static VALUE
ryast_term_allocate(VALUE klass)
@@ -100,10 +129,43 @@
return Data_Wrap_Struct (klass, ryast_term_mark, ryast_term_free, wrapper);
}
+
+static VALUE
+ryast_term_to_s(VALUE self)
+{
+ ryast_Term_Wrapper *wrapper;
+ Data_Get_Struct(self, ryast_Term_Wrapper, wrapper);
+ return rb_str_new2(wrapper->term.toString().c_str());
+}
+
+static VALUE
+ryast_term_name(VALUE self)
+{
+ ryast_Term_Wrapper *wrapper;
+ Data_Get_Struct(self, ryast_Term_Wrapper, wrapper);
+ return rb_str_new2(wrapper->term.name().c_str());
+}
+
+// static VALUE
+// ryast_term_set_name(VALUE self, VALUE name)
+// {
+// Check_Type(name, T_STRING);
+// ryast_Term_Wrapper *wrapper;
+// Data_Get_Struct(self, ryast_Term_Wrapper, wrapper);
+//
+// wrapper->term->setName(RSTRING(name)->ptr);
+// return self;
+// }
+
void
ryast_term_init( VALUE super )
{
+ //std::cout << "Hi! term" << std::endl;
ryast_cTerm = rb_define_class_under( super, "Term", rb_cObject );
rb_define_alloc_func( ryast_cTerm, ryast_term_allocate );
rb_define_method( ryast_cTerm, "initialize", RB_METHOD( ryast_term_initialize ), -1 );
+ rb_define_method( ryast_cTerm, "add", RB_METHOD( ryast_term_add ), -1 );
+ //rb_define_method( ryast_cTerm, "name=", RB_METHOD( ryast_term_set_name ), 1 );
+ rb_define_method( ryast_cTerm, "name", RB_METHOD( ryast_term_name ), 0 );
+ rb_define_method( ryast_cTerm, "to_s", RB_METHOD( ryast_term_to_s ), 0 );
}
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/yast2-ruby-bindings-0.1.0/src/ruby/Y2RubyTypeTerm.h new/yast2-ruby-bindings-0.2.0/src/ruby/Y2RubyTypeTerm.h
--- old/yast2-ruby-bindings-0.1.0/src/ruby/Y2RubyTypeTerm.h 2007-08-09 12:49:30.000000000 +0200
+++ new/yast2-ruby-bindings-0.2.0/src/ruby/Y2RubyTypeTerm.h 2007-09-20 11:17:19.000000000 +0200
@@ -27,7 +27,10 @@
void ryast_term_init( VALUE super );
VALUE
-ryast_term_from_term( const YCPTerm &term );
+ryast_rterm_from_yterm( const YCPTerm &term );
+
+YCPTerm
+ryast_yterm_from_rterm( VALUE term );
#endif
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/yast2-ruby-bindings-0.1.0/src/ruby/yast.rb new/yast2-ruby-bindings-0.2.0/src/ruby/yast.rb
--- old/yast2-ruby-bindings-0.1.0/src/ruby/yast.rb 1970-01-01 01:00:00.000000000 +0100
+++ new/yast2-ruby-bindings-0.2.0/src/ruby/yast.rb 2007-09-20 11:17:19.000000000 +0200
@@ -0,0 +1,141 @@
+# -----------------------------------------------------------------------\
+# | |
+# | __ __ ____ _____ ____ |
+# | \ \ / /_ _/ ___|_ _|___ \ |
+# | \ V / _` \___ \ | | __) | |
+# | | | (_| |___) || | / __/ |
+# | |_|\__,_|____/ |_| |_____| |
+# | |
+# | |
+# | ruby language support (C) Novell Inc. |
+# \----------------------------------------------------------------------/
+#
+# Author: Duncan Mac-Vicar <dmacvicar(a)suse.de>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version
+# 2 of the License, or (at your option) any later version.
+#
+
+ENV['LD_LIBRARY_PATH'] = "/usr/lib/YaST2/plugin"
+
+# Load the native part (.so)
+require 'yastx'
+
+module YaST
+ module Ui
+ #my @e_logging = qw(y2debug y2milestone y2warning y2error y2security y2internal);
+
+ # Define symbols for the UI
+ ui_terms = [ :BarGraph, :Bottom, :CheckBox, :ColoredLabel, :ComboBox, :Date,
+ :DownloadProgress, :DumbTab, :DummySpecialWidget, :Empty, :Frame, :HBox, :HBoxvHCenter,
+ :HMultiProgressMeter, :HSpacing, :HSquash, :HStretch, :HVCenter, :HVSquash,
+ :HVStretch, :HWeight, :Heading, :IconButton, :Image, :IntField, :Label, :Left, :LogView,
+ :MarginBox, :MenuButton, :MinHeight, :MinSize, :MinWidth, :MultiLineEdit,
+ :MultiSelectionBox, :PackageSelector, :PatternSelector, :PartitionSplitter,
+ :Password, :PkgSpecial, :ProgressBar, :PushButton, :RadioButton,
+ :RadioButtonGroup, :ReplacePoint, :RichText, :Right, :SelectionBox, :Slider, :Table,
+ :TextEntry, :Time, :Top, :Tree, :VBox, :VCenter, :VMultiProgressMeter, :VSpacing,
+ :VSquash, :VStretch, :VWeight, :Wizard,
+ :id, :opt ]
+
+# buffer = String.new
+# buffer << "["
+# ui_terms.each do |t|
+# buffer << " :" << t.to_s.downcase << ","
+# end
+# buffer << " ]"
+# puts buffer
+ # If the method name contains underscores, convert to camel case
+# while method =~ /([^_]*)_(.)(.*)/
+# method = $1 + $2.upcase + $3
+# end
+
+ # for each symbol define a util function that will create a term
+ ui_terms.each do | term_name |
+ define_method(term_name) do | *args |
+ t = YaST::Term.new(term_name.to_s)
+ args.each do |arg|
+ t.add(arg)
+ end
+ return t
+ end
+ alias_method term_name.to_s.downcase, term_name
+ end
+
+ end # end Ui module
+end
+
+module YaST
+
+ class TermBuilder
+ # blank slate
+ instance_methods.each { |m| undef_method m unless (m =~ /^__|instance_eval$/)}
+
+ def initialize(&block)
+ @term = nil
+ @term = instance_eval(&block)
+ end
+
+ def method_missing(name, *args, &block )
+ # puts "hi #{name.to_s} | #{args}"
+ term = nil
+ elements = block ? nil : args
+ @__to_s = nil # invalidate to_s cache
+ term = YaST::Term.new(name.to_s)
+ if not elements.nil?
+ elements.each do | e |
+ term.add(e)
+ end
+ return term
+ else
+ r = instance_eval(&block)
+ puts term.class
+ term.add(r) if not r.nil?
+ end
+ return term
+ end
+
+ def to_s
+ return @term.to_s
+ end
+
+ def term
+ return @term
+ end
+
+ end
+
+ def y2_logger_helper(*args)
+ level = args.shift
+
+ caller[0] =~ /(.+):(\d+):in `([^']+)'/
+ y2_logger(level,"Ruby",$1,$2.to_i,"",args[0])
+ end
+
+ def y2debug(*args)
+ y2_logger_helper(0, args)
+ end
+
+ def y2milestone(*args)
+ y2_logger_helper(1, args)
+ end
+
+ def y2warning(*args)
+ y2_logger_helper(2, args)
+ end
+
+ def y2error(*args)
+ y2_logger_helper(3, args)
+ end
+
+ def y2security(*args)
+ y2_logger_helper(4, args)
+ end
+
+ def y2internal(*args)
+ y2_logger_helper(5, args)
+ end
+
+end # module YaST
\ No newline at end of file
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/yast2-ruby-bindings-0.1.0/src/ruby/YCP.cc new/yast2-ruby-bindings-0.2.0/src/ruby/YCP.cc
--- old/yast2-ruby-bindings-0.1.0/src/ruby/YCP.cc 2007-08-09 12:49:30.000000000 +0200
+++ new/yast2-ruby-bindings-0.2.0/src/ruby/YCP.cc 2007-09-20 11:17:19.000000000 +0200
@@ -57,6 +57,7 @@
#include "YRuby.h"
static VALUE rb_mYaST;
+static VALUE rb_mUi;
static VALUE rb_cBroker;
// make the compiler happy when
@@ -91,7 +92,7 @@
return ns;
}
-void init_wfm ()
+void init_wfm()
{
y2milestone("init_wfm");
// if (Y2WFMComponent::instance () == 0)
@@ -105,6 +106,53 @@
// }
}
+static VALUE
+rb_init_ui( int argc, VALUE *argv, VALUE self )
+{
+ const char *ui_name = "ncurses";
+
+ if (argc == 1)
+ {
+ Check_Type(argv[0], T_STRING);
+ ui_name = RSTRING(argv[0])->ptr;
+ }
+ else if (argc != 0)
+ {
+ y2error ("Zero or one arguments required (ui name, default %s", ui_name);
+ return Qnil;
+ }
+
+ Y2Component *c = YUIComponent::uiComponent ();
+ if (c == 0)
+ {
+ y2debug ("UI component not created yet, creating %s", ui_name);
+
+ c = Y2ComponentBroker::createServer (ui_name);
+ if (c == 0)
+ {
+ y2error ("Cannot create component %s", ui_name);
+ return Qnil;
+ }
+
+ if (YUIComponent::uiComponent () == 0)
+ {
+ y2error ("Component %s is not a UI", ui_name);
+ return Qnil;
+ }
+ else
+ {
+ // got it - initialize, remember
+ c->setServerOptions (0, NULL);
+ owned_uic = c;
+ }
+ }
+ else
+ {
+ y2debug ("UI component already present: %s", c->name ().c_str ());
+ }
+ return Qnil;
+}
+
typedef struct brokerinfo
{
Y2Component *component;
@@ -139,7 +187,7 @@
{
Check_Type(param_ns_name, T_STRING);
rb_iv_set(self, "@namespace_name", param_ns_name);
- init_wfm ();
+ init_wfm();
return self;
}
@@ -370,10 +418,34 @@
return ret_yv;
}
+
+
+//y2_logger_helper
+
+//y2_logger (level, comp, file, line, function, "%s", message);
+
+static VALUE
+rb_y2_logger( int argc, VALUE *argv, VALUE self )
+{
+ Check_Type(argv[0], T_FIXNUM);
+ Check_Type(argv[1], T_STRING);
+ Check_Type(argv[2], T_STRING);
+ Check_Type(argv[3], T_FIXNUM);
+ Check_Type(argv[4], T_STRING);
+
+ int i;
+ for ( i = 5; i < argc; i++)
+ {
+ Check_Type(argv[i], T_STRING);
+ }
+ y2_logger((loglevel_t)NUM2INT(argv[0]),RSTRING(argv[1])->ptr,RSTRING(argv[2])->ptr,NUM2INT(argv[3]),"",RSTRING(argv[5])->ptr);
+ return Qnil;
+}
+
extern "C"
{
void
- Init_yast()
+ Init_yastx()
{
YCPPathSearch::initialize ();
@@ -382,11 +454,12 @@
y2internal("%s\n", (*it).c_str() );
}
- string module = YCPPathSearch::find (YCPPathSearch::Module, string ("MyModule.ycp"));
- y2internal("%s\n", module.c_str() );
-
rb_mYaST = rb_define_module("YaST");
-
+ rb_mUi = rb_define_module_under(rb_mYaST, "Ui");
+ rb_define_singleton_method( rb_mUi, "init", RB_METHOD(rb_init_ui), -1);
+
+ rb_define_method( rb_mYaST, "y2_logger", RB_METHOD(rb_y2_logger), -1);
+
rb_cBroker = rb_define_class_under( rb_mYaST, "Module", rb_cObject);
//rb_define_singleton_method( rb_cBroker, "new", RB_METHOD(module_new), 1);
rb_define_alloc_func(rb_cBroker, yast_module_allocate);
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/yast2-ruby-bindings-0.1.0/VERSION.cmake new/yast2-ruby-bindings-0.2.0/VERSION.cmake
--- old/yast2-ruby-bindings-0.1.0/VERSION.cmake 2007-08-09 12:49:30.000000000 +0200
+++ new/yast2-ruby-bindings-0.2.0/VERSION.cmake 2007-09-20 11:17:19.000000000 +0200
@@ -1,3 +1,3 @@
SET(VERSION_MAJOR "0")
-SET(VERSION_MINOR "1")
+SET(VERSION_MINOR "2")
SET(VERSION_PATCH "0")
\ No newline at end of file
diff -urN --exclude=CVS --exclude=.cvsignore --exclude=.svn --exclude=.svnignore old/yast2-ruby-bindings-0.1.0/yast2-ruby-bindings.spec.in new/yast2-ruby-bindings-0.2.0/yast2-ruby-bindings.spec.in
--- old/yast2-ruby-bindings-0.1.0/yast2-ruby-bindings.spec.in 2007-08-09 12:49:30.000000000 +0200
+++ new/yast2-ruby-bindings-0.2.0/yast2-ruby-bindings.spec.in 2007-09-20 11:17:19.000000000 +0200
@@ -54,4 +54,6 @@
%files
%defattr (-, root, root)
%{_libdir}/YaST2/plugin/libpy2lang_ruby.so
-%{_libdir}/ruby/vendor_ruby/%{rb_ver}/%{rb_arch}/yast.so
+%{_libdir}/ruby/vendor_ruby/%{rb_ver}/%{rb_arch}/yastx.so
+%{_libdir}/ruby/vendor_ruby/%{rb_ver}/yast.rb
+
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Remember to have fun...
---------------------------------------------------------------------
To unsubscribe, e-mail: opensuse-commit+unsubscribe(a)opensuse.org
For additional commands, e-mail: opensuse-commit+help(a)opensuse.org