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 return YCP::forward_call("#{mname}", :#{sname}, *args)
44 YCP.const_set(mname, m)
49 alias require_ require
51 if name =~ /^ycp\/(.+)$/
53 YCP::add_ycp_module(ycpns.capitalize)
63 #my @e_logging = qw(y2debug y2milestone y2warning y2error y2security y2internal);
65 # Define symbols for the UI
66 ui_terms = [ :BarGraph, :Bottom, :CheckBox, :ColoredLabel, :ComboBox, :Date,
67 :DownloadProgress, :DumbTab, :DummySpecialWidget, :Empty, :Frame, :HBox, :HBoxvHCenter,
68 :HMultiProgressMeter, :HSpacing, :HSquash, :HStretch, :HVCenter, :HVSquash,
69 :HVStretch, :HWeight, :Heading, :IconButton, :Image, :IntField, :Label, :Left, :LogView,
70 :MarginBox, :MenuButton, :MinHeight, :MinSize, :MinWidth, :MultiLineEdit,
71 :MultiSelectionBox, :PackageSelector, :PatternSelector, :PartitionSplitter,
72 :Password, :PkgSpecial, :ProgressBar, :PushButton, :RadioButton,
73 :RadioButtonGroup, :ReplacePoint, :RichText, :Right, :SelectionBox, :Slider, :Table,
74 :TextEntry, :Time, :Top, :Tree, :VBox, :VCenter, :VMultiProgressMeter, :VSpacing,
75 :VSquash, :VStretch, :VWeight, :Wizard,
80 # ui_terms.each do |t|
81 # buffer << " :" << t.to_s.downcase << ","
85 # If the method name contains underscores, convert to camel case
86 # while method =~ /([^_]*)_(.)(.*)/
87 # method = $1 + $2.upcase + $3
90 # for each symbol define a util function that will create a term
91 ui_terms.each do | term_name |
92 define_method(term_name) do | *args |
93 t = YaST::Term.new(term_name.to_s)
99 alias_method term_name.to_s.downcase, term_name
109 instance_methods.each { |m| undef_method m unless (m =~ /^__|instance_eval$/)}
111 def initialize(&block)
113 @term = instance_eval(&block)
116 def method_missing(name, *args, &block )
117 # puts "hi #{name.to_s} | #{args}"
119 elements = block ? nil : args
120 @__to_s = nil # invalidate to_s cache
121 term = YaST::Term.new(name.to_s)
123 elements.each do | e |
128 r = instance_eval(&block)
130 term.add(r) if not r.nil?
145 def y2_logger_helper(*args)
148 caller[0] =~ /(.+):(\d+):in `([^']+)'/
149 y2_logger(level,"Ruby",$1,$2.to_i,"",args[0])
153 y2_logger_helper(0, args)
156 def y2milestone(*args)
157 y2_logger_helper(1, args)
161 y2_logger_helper(2, args)
165 y2_logger_helper(3, args)
168 def y2security(*args)
169 y2_logger_helper(4, args)
172 def y2internal(*args)
173 y2_logger_helper(5, args)