Author: jsuchome Date: Wed Nov 4 16:11:22 2009 New Revision: 59291 URL: http://svn.opensuse.org/viewcvs/yast?rev=59291&view=rev Log: - SERVICES.pm use ruby-bindings to read yml file (bnc#551276) - 2.17.74 Modified: branches/SuSE-Code-11-SP1-Branch/yast2/VERSION branches/SuSE-Code-11-SP1-Branch/yast2/library/runlevel/src/YaPI/SERVICES.pm branches/SuSE-Code-11-SP1-Branch/yast2/package/yast2.changes Modified: branches/SuSE-Code-11-SP1-Branch/yast2/VERSION URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/yast2/VERSION?rev=59291&r1=59290&r2=59291&view=diff ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/yast2/VERSION (original) +++ branches/SuSE-Code-11-SP1-Branch/yast2/VERSION Wed Nov 4 16:11:22 2009 @@ -1 +1 @@ -2.17.73 +2.17.74 Modified: branches/SuSE-Code-11-SP1-Branch/yast2/library/runlevel/src/YaPI/SERVICES.pm URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/yast2/library/runlevel/src/YaPI/SERVICES.pm?rev=59291&r1=59290&r2=59291&view=diff ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/yast2/library/runlevel/src/YaPI/SERVICES.pm (original) +++ branches/SuSE-Code-11-SP1-Branch/yast2/library/runlevel/src/YaPI/SERVICES.pm Wed Nov 4 16:11:22 2009 @@ -6,6 +6,9 @@ use Data::Dumper; # ------------------- imported modules +YaST::YCP::Import ("Directory"); +YaST::YCP::Import ("FileUtils"); +YaST::YCP::Import ("Package"); YaST::YCP::Import ("Service"); YaST::YCP::Import ("SCR"); # ------------------------------------- @@ -14,11 +17,107 @@ our @CAPABILITIES = ('SLES11'); our %TYPEINFO; +my $custom_services_file = "/tmp/custom_services.yml"; + +my $error_message = ""; + +# log error message and fill it into $error_message variable +sub report_error { + $error_message = shift; + y2error ($error_message); +} + +# parse the file with custom services and return the hash describing the file +sub parse_custom_services { + + if (!FileUtils->Exists ($custom_services_file)) { + report_error ("$custom_services_file file not present"); + return {}; + } + + if (!Package->Installed ("yast2-ruby-bindings")) { + report_error ("yast2-ruby-bindings not installed, cannot read custom services"); + return {}; + } + + if (!FileUtils->Exists (Directory->moduledir()."/YML.rb")) { + report_error ("YML.rb not present, cannot parse config file"); + return {}; + } + + YaST::YCP::Import ("YML"); + + my $parsed = YML->parse ($custom_services_file); + + if (!defined $parsed || ref ($parsed) ne "HASH") { + report_error ("custom services file could not be read"); + return {}; + } + return $parsed; +} + +# read the list of custom services and return the information about them +# if requested, read the status of services +sub read_custom_services { + + my $args = shift; + my @ret = (); + my $services = parse_custom_services (); + foreach my $name (keys %$services) { + my $s = { + "name" => $name, + "description" => $services->{$name}{"description"} || "" + }; + if ($args->{"read_status"} || 0) + { + my $cmd = $services->{$name}{"status"}; + if (!$cmd) { + report_error ("status script for $name not defined or empty"); + next; + } + my $out = SCR->Execute (".target.bash_output", $cmd); + $s->{"status"} = $out->{"exit"}; + } + push @ret, $s; + } + return \@ret; +} + +# read infomation about custom service and execute given command with it +sub execute_custom_script { + + my $name = shift; + my $action = shift; + my $services = parse_custom_services (); + my $ret = { + "stdout" => "", + "stderr" => "failure", + "exit" => 255 + }; + + if (%$services) { + my $service = $services->{$name}; + if (!defined $service || ref ($service) ne "HASH" || ! %$service) { + report_error ("service $name not defined or empty in config file"); + $ret->{"stderr"} = $error_message; + return $ret; + } + my $cmd = $services->{$name}{$action}; + if (!$cmd) { + report_error ("'$action' script for $name not defined or empty"); + $ret->{"stderr"} = $error_message; + return $ret; + } + $ret = SCR->Execute (".target.bash_output", $cmd); + } + return $ret; +} # Return the map of services enabled in given runlevel # Parameter is an argument map with possible keys: # "runlevel" : integer # "read_status" : if present, service status will be queried +# "custom" : if present, custom services (defined in config file) will be read # returns array of hashes BEGIN{$TYPEINFO{Read} = ["function", ["list", [ "map", "string", "any"]], @@ -32,6 +131,10 @@ my $runlevel = 5; $runlevel = $args->{"runlevel"} if defined $args->{"runlevel"}; + if ($args->{"custom"} || 0) { + return read_custom_services ($args); + } + foreach my $name (@{Service->EnabledServices ($runlevel)}) { my $s = { "name" => $name @@ -59,13 +162,21 @@ # return value is map with "exit", "stdout" and "stderr" keys BEGIN{$TYPEINFO{Execute} = ["function", [ "map", "string", "any"], - "string", "string" ]; + [ "map", "string", "any"]]; } sub Execute { my $self = shift; - my $name = shift; - my $action = shift; - return Service->RunInitScriptOutput ($name, $action); + + my $args = shift; + my $name = $args->{"name"} || ""; + my $action = $args->{"action"} || ""; + + if ($args->{"custom"} || 0) { + return execute_custom_script ($name, $action); + } + else { + return Service->RunInitScriptOutput ($name, $action); + } } 1; Modified: branches/SuSE-Code-11-SP1-Branch/yast2/package/yast2.changes URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Code-11-SP1-Branch/yast2/package/yast2.changes?rev=59291&r1=59290&r2=59291&view=diff ============================================================================== --- branches/SuSE-Code-11-SP1-Branch/yast2/package/yast2.changes (original) +++ branches/SuSE-Code-11-SP1-Branch/yast2/package/yast2.changes Wed Nov 4 16:11:22 2009 @@ -1,4 +1,10 @@ ------------------------------------------------------------------- +Wed Nov 4 15:40:57 CET 2009 - jsuchome@suse.cz + +- SERVICES.pm use ruby-bindings to read yml file (bnc#551276) +- 2.17.74 + +------------------------------------------------------------------- Mon Oct 26 16:59:01 CET 2009 - mzugec@suse.cz - NetworkPopup: display link state (FaTE#307166) -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org