Author: jsuchome Date: Mon Feb 22 16:23:09 2010 New Revision: 60948 URL: http://svn.opensuse.org/viewcvs/yast?rev=60948&view=rev Log: - SERVICES.pm: use ruby-bindings to read yml file (bnc#551276) - SERVICES.pm: read descriptions (bnc#570298); get single service status from the Read function (bnc#570968) - 2.18.29 Modified: branches/SuSE-Linux-11_2-Branch/yast2/VERSION branches/SuSE-Linux-11_2-Branch/yast2/library/runlevel/src/YaPI/SERVICES.pm branches/SuSE-Linux-11_2-Branch/yast2/package/yast2.changes Modified: branches/SuSE-Linux-11_2-Branch/yast2/VERSION URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Linux-11_2-Branch/yast2/VERSION?rev=60948&r1=60947&r2=60948&view=diff ============================================================================== --- branches/SuSE-Linux-11_2-Branch/yast2/VERSION (original) +++ branches/SuSE-Linux-11_2-Branch/yast2/VERSION Mon Feb 22 16:23:09 2010 @@ -1 +1 @@ -2.18.28 +2.18.29 Modified: branches/SuSE-Linux-11_2-Branch/yast2/library/runlevel/src/YaPI/SERVICES.pm URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Linux-11_2-Branch/yast2/library/runlevel/src/YaPI/SERVICES.pm?rev=60948&r1=60947&r2=60948&view=diff ============================================================================== --- branches/SuSE-Linux-11_2-Branch/yast2/library/runlevel/src/YaPI/SERVICES.pm (original) +++ branches/SuSE-Linux-11_2-Branch/yast2/library/runlevel/src/YaPI/SERVICES.pm Mon Feb 22 16:23:09 2010 @@ -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,12 +17,110 @@ our @CAPABILITIES = ('SLES11'); our %TYPEINFO; +my $custom_services_file = "/etc/webyast/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 -# returns array of hashes +# "read_status" : if true, service status will be queried +# "custom" : if true, custom services (defined in config file) will be read +# "description" : if true, read the description of each service +# "service" : if defined, the status of this given service will be returned +# @returns array of hashes BEGIN{$TYPEINFO{Read} = ["function", ["list", [ "map", "string", "any"]], ["map", "string", "any"]]; @@ -32,11 +133,35 @@ my $runlevel = 5; $runlevel = $args->{"runlevel"} if defined $args->{"runlevel"}; + # only read status of one service if the name was given + if ($args->{"service"} || "") { + my $exec = $self->Execute ({ + "name" => $args->{"service"} || "", + "action" => "status", + "custom" => $args->{"custom"} || 0 + }); + my $s = { + "name" => $args->{"service"} || "", + "status" => $exec->{"exit"} || 0 + }; + push @ret, $s; + return \@ret; + } + + if ($args->{"custom"} || 0) { + return read_custom_services ($args); + } + foreach my $name (@{Service->EnabledServices ($runlevel)}) { my $s = { "name" => $name }; $s->{"status"} = Service->Status ($name) if ($args->{"read_status"} || 0); + if (($args->{"description"} || 0) || ($args->{"shortdescription"} || 0)) { + my $info = Service->Info ($name); + $s->{"description"} = ($info->{"description"} || "") if $args->{"description"} || 0; + $s->{"shortdescription"}= ($info->{"shortdescription"} || "") if $args->{"shortdescription"} || 0; + } push @ret, $s; } return \@ret; @@ -59,13 +184,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-Linux-11_2-Branch/yast2/package/yast2.changes URL: http://svn.opensuse.org/viewcvs/yast/branches/SuSE-Linux-11_2-Branch/yast2/package/yast2.changes?rev=60948&r1=60947&r2=60948&view=diff ============================================================================== --- branches/SuSE-Linux-11_2-Branch/yast2/package/yast2.changes (original) +++ branches/SuSE-Linux-11_2-Branch/yast2/package/yast2.changes Mon Feb 22 16:23:09 2010 @@ -1,4 +1,12 @@ ------------------------------------------------------------------- +Thu Jan 14 12:48:50 CET 2010 - jsuchome@suse.cz + +- SERVICES.pm: use ruby-bindings to read yml file (bnc#551276) +- SERVICES.pm: read descriptions (bnc#570298); get single service + status from the Read function (bnc#570968) +- 2.18.29 + +------------------------------------------------------------------- Mon Dec 7 13:03:25 CET 2009 - jsrain@suse.cz - translate module names properly in NCurses CC (bnc#553644) -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org