1 # -----------------------------------------------------------------------\
3 # | __ __ ____ _____ ____ |
4 # | \ \ / /_ _/ ___|_ _|___ \ |
5 # | \ V / _` \___ \ | | __) | |
6 # | | | (_| |___) || | / __/ |
7 # | |_|\__,_|____/ |_| |_____| |
10 # | ruby language support (C) Novell Inc. |
11 # \----------------------------------------------------------------------/
13 # Author: Duncan Mac-Vicar <dmacvicar@suse.de>
15 # This program is free software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation; either version
18 # 2 of the License, or (at your option) any later version.
21 ENV['LD_LIBRARY_PATH'] = "/usr/lib/YaST2/plugin"
23 # Load the native part (.so)
27 def self.method_missing(id, *args)
31 def self.add_ycp_module(mname)
32 puts "import #{mname}"
35 YCP::each_symbol(mname) do |sname,stype|
36 if (stype == :function) and !sname.empty?
37 m.module_eval <<-"END"
38 def self.#{sname}(*args)
39 args.insert(0, "#{mname}")
40 args.insert(0, :#{sname})
41 puts "to forward call #{sname.to_s} in #{mname}"
42 return YCP::forward_call(args)
47 YCP.const_set(mname, m)
52 alias require_ require
54 if name =~ /^ycp\/(.+)$/
56 YCP::add_ycp_module(ycpns.capitalize)
66 #my @e_logging = qw(y2debug y2milestone y2warning y2error y2security y2internal);
68 # Define symbols for the UI
69 ui_terms = [ :BarGraph, :Bottom, :CheckBox, :ColoredLabel, :ComboBox, :Date,
70 :DownloadProgress, :DumbTab, :DummySpecialWidget, :Empty, :Frame, :HBox, :HBoxvHCenter,
71 :HMultiProgressMeter, :HSpacing, :HSquash, :HStretch, :HVCenter, :HVSquash,
72 :HVStretch, :HWeight, :Heading, :IconButton, :Image, :IntField, :Label, :Left, :LogView,
73 :MarginBox, :MenuButton, :MinHeight, :MinSize, :MinWidth, :MultiLineEdit,
74 :MultiSelectionBox, :PackageSelector, :PatternSelector, :PartitionSplitter,
75 :Password, :PkgSpecial, :ProgressBar, :PushButton, :RadioButton,
76 :RadioButtonGroup, :ReplacePoint, :RichText, :Right, :SelectionBox, :Slider, :Table,
77 :TextEntry, :Time, :Top, :Tree, :VBox, :VCenter, :VMultiProgressMeter, :VSpacing,
78 :VSquash, :VStretch, :VWeight, :Wizard,
83 # ui_terms.each do |t|
84 # buffer << " :" << t.to_s.downcase << ","
88 # If the method name contains underscores, convert to camel case
89 # while method =~ /([^_]*)_(.)(.*)/
90 # method = $1 + $2.upcase + $3
93 # for each symbol define a util function that will create a term
94 ui_terms.each do | term_name |
95 define_method(term_name) do | *args |
96 t = YaST::Term.new(term_name.to_s)
102 alias_method term_name.to_s.downcase, term_name
112 instance_methods.each { |m| undef_method m unless (m =~ /^__|instance_eval$/)}
114 def initialize(&block)
116 @term = instance_eval(&block)
119 def method_missing(name, *args, &block )
120 # puts "hi #{name.to_s} | #{args}"
122 elements = block ? nil : args
123 @__to_s = nil # invalidate to_s cache
124 term = YaST::Term.new(name.to_s)
126 elements.each do | e |
131 r = instance_eval(&block)
133 term.add(r) if not r.nil?
148 def y2_logger_helper(*args)
151 caller[0] =~ /(.+):(\d+):in `([^']+)'/
152 y2_logger(level,"Ruby",$1,$2.to_i,"",args[0])
156 y2_logger_helper(0, args)
159 def y2milestone(*args)
160 y2_logger_helper(1, args)
164 y2_logger_helper(2, args)
168 y2_logger_helper(3, args)
171 def y2security(*args)
172 y2_logger_helper(4, args)
175 def y2internal(*args)
176 y2_logger_helper(5, args)