Author: jsmeix Date: Wed Sep 3 17:09:37 2008 New Revision: 50630 URL: http://svn.opensuse.org/viewcvs/yast?rev=50630&view=rev Log: - Implemented cupsd status/start/restart/stop functionality. - 2.17.9 Modified: trunk/printer/VERSION trunk/printer/package/yast2-printer.changes trunk/printer/src/Printerlib.ycp trunk/printer/src/overview.ycp trunk/printer/src/printingvianetwork.ycp trunk/printer/tools/modify_cupsd_conf Modified: trunk/printer/VERSION URL: http://svn.opensuse.org/viewcvs/yast/trunk/printer/VERSION?rev=50630&r1=50629&r2=50630&view=diff ============================================================================== --- trunk/printer/VERSION (original) +++ trunk/printer/VERSION Wed Sep 3 17:09:37 2008 @@ -1 +1 @@ -2.17.8 +2.17.9 Modified: trunk/printer/package/yast2-printer.changes URL: http://svn.opensuse.org/viewcvs/yast/trunk/printer/package/yast2-printer.changes?rev=50630&r1=50629&r2=50630&view=diff ============================================================================== --- trunk/printer/package/yast2-printer.changes (original) +++ trunk/printer/package/yast2-printer.changes Wed Sep 3 17:09:37 2008 @@ -1,4 +1,10 @@ ------------------------------------------------------------------- +Wed Sep 3 17:05:45 CEST 2008 - jsmeix@suse.de + +- Implemented cupsd status/start/restart/stop functionality. +- 2.17.9 + +------------------------------------------------------------------- Tue Sep 2 16:31:57 CEST 2008 - jsmeix@suse.de - The 'Printing via Network'dialog writes the Browsing values Modified: trunk/printer/src/Printerlib.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/printer/src/Printerlib.ycp?rev=50630&r1=50629&r2=50630&view=diff ============================================================================== --- trunk/printer/src/Printerlib.ycp (original) +++ trunk/printer/src/Printerlib.ycp Wed Sep 3 17:09:37 2008 @@ -4,6 +4,10 @@ module "Printerlib"; textdomain "printer"; +import "Popup"; +import "Report"; +import "Service"; + // Fortunately the tools are for all architectures always // installed in /usr/lib/YaST2/bin/ (i.e. no "lib64"). // I tested this on Thu Aug 28 2008 using the command @@ -43,6 +47,96 @@ return true; } +// By default there is a local running cupsd. +// But to be on the safe side, assume it is not: +global boolean local_cupsd_accessible = false; + +global boolean GetAndSetCupsdStatus( string new_status ) +{ // Determine whether or not a local cupsd is accessible. + // The value 'false' is also the right one when the command itself fails + // (e.g. when there is no /usr/bin/lpstat binary or whatever broken stuff): + string local_cupsd_accessible_commandline = "/usr/bin/lpstat -h localhost -r"; + local_cupsd_accessible = ExecuteBashCommand( local_cupsd_accessible_commandline ); + // Start cupsd: + if( "start" == new_status ) + { if( local_cupsd_accessible ) + { // Do not start an already running (i.e. accessible) cupsd: + return true; + } + if( ! Service::Start( "cups" ) ) + { Report::Error( // Message of a Report::Error. + // Only a simple message because this error does not happen on a normal system + // (i.e. a system which is not totally broken or totally messed up). + _("Failed to start the CUPS daemon.") + ); + return false; + } + else + { Popup::TimedMessage( _("Started the CUPS daemon.\nWaiting one minute so that it is ready to operate..."), + 60 + ); + } + local_cupsd_accessible = ExecuteBashCommand( local_cupsd_accessible_commandline ); + if( ! local_cupsd_accessible ) + { Report::Error( // Message of a Report::Error. + // Only a simple message because this error does not happen on a normal system + // (i.e. a system which is not totally broken or totally messed up). + _("No local running CUPS daemon is accessible.") + ); + return false; + } + return true; + } + // Restart cupsd: + if( "restart" == new_status ) + { if( ! Service::Restart( "cups" ) ) + { Report::Error( // Message of a Report::Error. + // Only a simple message because this error does not happen on a normal system + // (i.e. a system which is not totally broken or totally messed up). + _("Failed to restart the CUPS daemon.") + ); + return false; + } + else + { Popup::TimedMessage( _("Restarted the CUPS daemon.\nWaiting one minute so that it is ready to operate..."), + 60 + ); + } + local_cupsd_accessible = ExecuteBashCommand( local_cupsd_accessible_commandline ); + if( ! local_cupsd_accessible ) + { Report::Error( // Message of a Report::Error. + // Only a simple message because this error does not happen on a normal system + // (i.e. a system which is not totally broken or totally messed up). + _("No local running CUPS daemon is accessible.") + ); + return false; + } + return true; + } + // Stop cupsd: + if( "stop" == new_status ) + { // To be on the safe side try to stop the cupsd regardless if it is accessible or not + // and ignore possible errors from Service::Stop when it is already stopped + // (the local_cupsd_accessible test below should be sufficient): + Service::Stop( "cups" ); + // Wait one second to make sure that cupsd has really finished (it may do some cleanup): + sleep( 1000 ); + local_cupsd_accessible = ExecuteBashCommand( local_cupsd_accessible_commandline ); + if( local_cupsd_accessible ) + { Report::Error( // Message of a Report::Error. + // Only a simple message because this error does not happen on a normal system + // (i.e. a system which is not totally broken or totally messed up). + _("A local running CUPS daemon is still accessible.") + ); + return false; + } + return true; + } + // If new_status is neither "start" nor "restart" nor "stop", + // return whether or not the local cupsd is accessible: + return local_cupsd_accessible; +} + // By default there is no active "ServerName" entry in /etc/cups/client.conf: global string client_conf_server_name = ""; global boolean client_only = false; Modified: trunk/printer/src/overview.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/printer/src/overview.ycp?rev=50630&r1=50629&r2=50630&view=diff ============================================================================== --- trunk/printer/src/overview.ycp (original) +++ trunk/printer/src/overview.ycp Wed Sep 3 17:09:37 2008 @@ -83,50 +83,27 @@ boolean local_content_selected = Printer::queue_filter_show_local; boolean remote_content_selected = Printer::queue_filter_show_remote; boolean local_cupsd_required = true; - boolean local_cupsd_accessible = Printerlib::ExecuteBashCommand( "/usr/bin/lpstat -h localhost -r" ); - // By default there is no /etc/cups/client.conf file at all - // and usually there is no ServerName entry in a /etc/cups/client.conf file. - // Therefore client_only is only true if there is a /etc/cups/client.conf file - // with an active ServerName entry which is not "localhost" or "127.0.0.1". + // Determine whether or not it is currently a real client_only config + // (i.e. a ServerName != "localhost/127.0.0.1" in /etc/cups/client.conf) + // and ignore when it fails (i.e. use the fallback value silently): + Printerlib::DetermineClientOnly(); if( Printerlib::client_only ) - { if( Printerlib::client_conf_server_name == "localhost" - || Printerlib::client_conf_server_name == "127.0.0.1" ) - { local_content_selected = true; - remote_content_selected = true; - } - else - { local_cupsd_required = false; - local_content_selected = false; - remote_content_selected = true; - } + { local_cupsd_required = false; + local_content_selected = false; + remote_content_selected = true; } - if( local_cupsd_required && ! local_cupsd_accessible ) - { Popup::ErrorDetails( _("Start local running CUPS daemon"), + // Determine whether or not a local cupsd is accessible: + if( local_cupsd_required && ! Printerlib::GetAndSetCupsdStatus( "" ) ) + { Popup::ErrorDetails( // Popup::ErrorDetails header: + _("Start local running CUPS daemon"), + // Popup::ErrorDetails body: _("A local running CUPS daemon is needed for your setup.") ); - if( ! Service::Start("cups") ) - { Report::Error( // Message of a Report::Error. - // Only a simple message because this error does not happen on a normal system - // (i.e. a system which is not totally broken or totally messed up). - _("Failed to start the CUPS daemon.") - ); - } - else - { Popup::TimedMessage( _("Waiting for the CUPS daemon to become ready to operate..."), - 60 - ); - } - local_cupsd_accessible = Printerlib::ExecuteBashCommand( "/usr/bin/lpstat -h localhost -r" ); - if( ! local_cupsd_accessible ) - Report::Error( // Message of a Report::Error. - // Only a simple message because this error does not happen on a normal system - // (i.e. a system which is not totally broken or totally messed up). - _("No local running CUPS daemon is accessible.") - ); + Printerlib::GetAndSetCupsdStatus( "start" ); } - UI::ChangeWidget(`local_content_checkbox, `Value, local_content_selected); - UI::ChangeWidget(`remote_content_checkbox, `Value, remote_content_selected); - UI::ChangeWidget(`overview_table, `Items, Printer::QueueItems( Printer::queue_filter_show_local, Printer::queue_filter_show_remote )); + UI::ChangeWidget(`local_content_checkbox, `Value, local_content_selected); + UI::ChangeWidget(`remote_content_checkbox, `Value, remote_content_selected); + UI::ChangeWidget(`overview_table, `Items, Printer::QueueItems( Printer::queue_filter_show_local, Printer::queue_filter_show_remote )); } /** @@ -245,10 +222,17 @@ } if (event["EventReason"]:"" == "Activated" && event["ID"]:nil == `add){ - // client only + // Determine whether or not it is a real client_only config + // (i.e. a ServerName != "localhost/127.0.0.1" in /etc/cups/client.conf). + // There is no new Printerlib::DetermineClientOnly() here because + // it was run in initOverview() and the client_only state cannot be + // changed in YaST while the Overview dialog runs: if( Printerlib::client_only ) - { if( ! Popup::YesNoHeadline( "Disable remote CUPS server setting", - "A remote CUPS server setting conflicts with adding a print queue." + { if( ! Popup::YesNoHeadline( // PopupYesNoHeadline headline + // where %1 will be replaced by the server name: + sformat( _("Disable remote CUPS server '%1'"), Printerlib::client_conf_server_name ), + // PopupYesNoHeadline body: + _("A remote CUPS server setting conflicts with adding a print queue.") ) ) return nil; @@ -262,31 +246,19 @@ return nil; } } - if( ! Printerlib::ExecuteBashCommand( "/usr/bin/lpstat -h localhost -r" ) ) + if( ! Printerlib::GetAndSetCupsdStatus( "" ) ) { // No local running cupsd is accessible: - if( ! Popup::YesNoHeadline( "Start local running CUPS daemon", - "A local running CUPS daemon is needed to add a print queue." + if( ! Popup::YesNoHeadline( // PopupYesNoHeadline headline: + _("Start local running CUPS daemon"), + // PopupYesNoHeadline body: + _("A local running CUPS daemon is needed to add a print queue.") ) ) return nil; // Do a restart to be safe: - if( ! Service::Restart("cups") ) - { Report::Error( // Message of a Report::Error. - // Only a simple message because this error does not happen on a normal system - // (i.e. a system which is not totally broken or totally messed up). - _("Failed to start the CUPS daemon.") - ); - return nil; + if( ! Printerlib::GetAndSetCupsdStatus( "restart" ) ) + { return nil; } - Popup::TimedMessage( _("Waiting for the CUPS daemon to become ready to operate..."), 60 ); - } - if( ! Printerlib::ExecuteBashCommand( "/usr/bin/lpstat -h localhost -r" ) ) - { Report::Error( // Message of a Report::Error. - // Only a simple message because this error does not happen on a normal system - // (i.e. a system which is not totally broken or totally messed up). - _("No local running CUPS daemon is accessible.") - ); - return nil; } // To be safe autodetect the queues again. // When there was a switch from "client only" to a local running cupsd Modified: trunk/printer/src/printingvianetwork.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/printer/src/printingvianetwork.ycp?rev=50630&r1=50629&r2=50630&view=diff ============================================================================== --- trunk/printer/src/printingvianetwork.ycp (original) +++ trunk/printer/src/printingvianetwork.ycp Wed Sep 3 17:09:37 2008 @@ -151,27 +151,22 @@ */ boolean something_has_changed = false; -boolean cupsd_restart_required = false; -boolean cupsd_start_required = false; -boolean cupsd_stop_required = false; boolean initial_cupsd_conf_browsing_off_radio_button = false; boolean initial_cupsd_conf_browsing_on_radio_button = false; any initial_cupsd_conf_browse_allow_combo_box_value = nil; -boolean initial_cupsd_conf_browse_allow_all = false; -boolean initial_cupsd_conf_browse_allow_local = false; -boolean initial_cupsd_conf_browse_allow_specific = false; string initial_cupsd_conf_browse_allow_input_value = ""; boolean initial_client_only_radio_button = false; string initial_client_conf_server_name_input_value = ""; boolean ApplyNetworkPrintingSettings() -{ // Get the actual settings and values from the dialog: +{ something_has_changed = false; + // Get the actual settings and values from the dialog: any current_radio_button = UI::QueryWidget( `id(`browsing_or_client_only_check_boxes), `CurrentButton ); any current_browse_allow = UI::QueryWidget( `id(`cupsd_conf_browse_allow_combo_box), `Value ); string current_browse_allow_input_value = (string)UI::QueryWidget( `id(`cupsd_conf_browse_allow_input), `Value ); string current_server_name_input_value = (string)UI::QueryWidget( `id(`client_conf_server_name_input), `Value ); y2milestone( "ApplyNetworkPrintingSettings with\ncurrent_radio_button = '%1'\ncurrent_browse_allow = '%2'\ncurrent_browse_allow_input_value = '%3'\ncurrent_server_name_input_value = '%4'", current_radio_button, current_browse_allow, current_browse_allow_input_value, current_server_name_input_value ); - // Browsing Off: + // Do not accept Browsing information: if( `cupsd_conf_browsing_off_radio_button == current_radio_button ) { if( initial_cupsd_conf_browsing_off_radio_button ) { // Nothing has changed: @@ -193,6 +188,17 @@ ); return false; } + // If a local cupsd is accessible, restart it, otherwise start it: + if( Printerlib::GetAndSetCupsdStatus( "" ) ) + { if( ! Printerlib::GetAndSetCupsdStatus( "restart" ) ) + { return false; + } + } + else + { if( ! Printerlib::GetAndSetCupsdStatus( "start" ) ) + { return false; + } + } return true; } if( initial_client_only_radio_button ) @@ -243,7 +249,7 @@ // The latter case should also leave the current client-only setup as is: return true; } - // Browsing On: + // Accept Browsing information: if( `cupsd_conf_browsing_on_radio_button == current_radio_button ) { if( initial_cupsd_conf_browsing_off_radio_button ) { // It was initially a "No browsing info" config, @@ -258,54 +264,94 @@ ) { something_has_changed = true; } - else - { // Nothing has changed: - return true; - } } if( initial_client_only_radio_button ) { // It was initially a client-only config, // but now the user has activated the "Get browsing info" radio button: something_has_changed = true; } - if( something_has_changed ) - { string browse_allow_value = current_browse_allow_input_value; - if( `browse_allow_all == current_browse_allow ) - { // If browsing info is accepted from all hosts, it is actually useless - // to additionally accept it from specific IPs or networks - // but nevertheless the specific addresses are also set in cupsd.conf - // because I do not want to ignore what the user has entered. - // E.g. the user may like to accept browsing info from some specific addresses - // while he plays around with the predefined settings from the combo box: - browse_allow_value = browse_allow_value + " all"; + if( ! something_has_changed ) + { // Nothing has changed: + return true; + } + string browse_allow_value = current_browse_allow_input_value; + if( `browse_allow_all == current_browse_allow ) + { // If browsing info is accepted from all hosts, it is actually useless + // to additionally accept it from specific IPs or networks + // but nevertheless the specific addresses are also set in cupsd.conf + // because I do not want to ignore what the user has entered. + // E.g. the user may like to accept browsing info from some specific addresses + // while he plays around with the predefined settings from the combo box: + browse_allow_value = browse_allow_value + " all"; + } + if( `browse_allow_local == current_browse_allow ) + { browse_allow_value = browse_allow_value + " @LOCAL"; + } + if( "" == filterchars( browse_allow_value, " " ) + || issubstring( browse_allow_value, "none" ) + ) + { // The browse_allow_value string is empty or it contains "none". + // (The issubstring match is o.k. because only IP-addresses are supported + // so that even for a hostname "none.nowhere" the IP-address would not match.) + // This case happens when browse_allow_specific is selected in the combo box + // but no address or only "none" was entered for cupsd_conf_browse_allow_input. + // This case has the same meaning as a "No browsing info" config. + if( initial_cupsd_conf_browsing_off_radio_button ) + { // It was initially a "No browsing info" config, + // and now the user has activated the "Get browsing info" radio button + // but with effectively an empty or "none" browse_allow_value string + // so that it is still a "No browsing info" config: + something_has_changed = false; + return true; + } + // Set the browse_allow_value explicitely to "none". + // This removes intentionally any additional stuff in this value + // if "none" was only persent as a real substring. + // The reasoning is that "none" should have the highest priority + // because this is the most secure setting. + browse_allow_value = "none"; + } + if( "none" != browse_allow_value ) + { // Only a not-"none" browse_allow_value requires "Browsing On" in cupsd.conf. + // Otherwise leave the "Browsing" entry in cupsd.conf unchanged. + if( ! Printerlib::ExecuteBashCommand( Printerlib::yast_bin_dir + "modify_cupsd_conf Browsing On" ) ) + { Report::Error( // Message of a Report::Error. + // Only a simple message because this error does not happen on a normal system + // (i.e. a system which is not totally broken or totally messed up). + _("Failed to set 'Browsing On' in /etc/cups/cupsd.conf") + ); + return false; } - if( `browse_allow_local == current_browse_allow ) - { browse_allow_value = browse_allow_value + " @LOCAL"; + } + if( ! Printerlib::ExecuteBashCommand( Printerlib::yast_bin_dir + + "modify_cupsd_conf BrowseAllow '" + + browse_allow_value + + "'" + ) + ) + { Report::Error( // Message of a Report::Error + // where %1 will be replaced by the values for BrowseAllow. + // Only a simple message because this error does not happen on a normal system + // (i.e. a system which is not totally broken or totally messed up). + sformat( _("Failed to set BrowseAllow value(s) '%1' in /etc/cups/cupsd.conf"), + browse_allow_value + ) + ); + return false; + } + // If a local cupsd is accessible, restart it, otherwise start it if needed: + if( Printerlib::GetAndSetCupsdStatus( "" ) ) + { if( ! Printerlib::GetAndSetCupsdStatus( "restart" ) ) + { return false; } - if( "" != filterchars( browse_allow_value, " " ) ) - { if( ! Printerlib::ExecuteBashCommand( Printerlib::yast_bin_dir + "modify_cupsd_conf Browsing On" ) ) - { Report::Error( // Message of a Report::Error. - // Only a simple message because this error does not happen on a normal system - // (i.e. a system which is not totally broken or totally messed up). - _("Failed to set 'Browsing On' in /etc/cups/cupsd.conf") - ); - return false; - } - if( ! Printerlib::ExecuteBashCommand( Printerlib::yast_bin_dir - + "modify_cupsd_conf BrowseAllow '" - + browse_allow_value - + "'" - ) - ) - { Report::Error( // Message of a Report::Error - // where %1 will be replaced by the values for BrowseAllow. - // Only a simple message because this error does not happen on a normal system - // (i.e. a system which is not totally broken or totally messed up). - sformat( _("Failed to set BrowseAllow value(s) '%1' in /etc/cups/cupsd.conf"), - browse_allow_value - ) - ); - return false; + } + else + { if( "none" != browse_allow_value ) + { // Only a not-"none" browse_allow_value requires the local cupsd + // to be started when it is not yet running. + // Otherwise leave the cupsd as is. + if( ! Printerlib::GetAndSetCupsdStatus( "start" ) ) + { return false; } } } @@ -341,17 +387,14 @@ // When by accident "all" and "@LOCAL" were set as BrowseAllow values, // the "@LOCAL" entry is preselected in cupsd_conf_browse_allow_combo_box // because this is the more secure setting: - initial_cupsd_conf_browse_allow_specific = true; initial_cupsd_conf_browse_allow_combo_box_value = `browse_allow_specific; UI::ChangeWidget( `id(`cupsd_conf_browse_allow_combo_box), `Value, `id(`browse_allow_specific) ); if( contains( Printerlib::cupsd_conf_browse_allow, "all" ) ) - { initial_cupsd_conf_browse_allow_all = true; - initial_cupsd_conf_browse_allow_combo_box_value = `browse_allow_all; + { initial_cupsd_conf_browse_allow_combo_box_value = `browse_allow_all; UI::ChangeWidget( `id(`cupsd_conf_browse_allow_combo_box), `Value, `id(`browse_allow_all) ); } if( contains( Printerlib::cupsd_conf_browse_allow, "@LOCAL" ) ) - { initial_cupsd_conf_browse_allow_local = true; - initial_cupsd_conf_browse_allow_combo_box_value = `browse_allow_local; + { initial_cupsd_conf_browse_allow_combo_box_value = `browse_allow_local; UI::ChangeWidget( `id(`cupsd_conf_browse_allow_combo_box), `Value, `id(`browse_allow_local) ); } UI::ChangeWidget( `id(`cupsd_conf_browse_allow_input), `Enabled, false ); @@ -391,8 +434,10 @@ UI::ChangeWidget( `id(`test_client_conf_server), `Enabled, true ); } else - { UI::ChangeWidget( `id(`connection_wizard), `Enabled, true ); - // If "none" is present as a BrowseAllow value, no 'Browsing On' widget is enabled: + { // The "Connection Wizard" button is only disabled in casae of "client_only": + UI::ChangeWidget( `id(`connection_wizard), `Enabled, true ); + // If "none" is present as a BrowseAllow value, no 'Browsing On' widget is enabled + // but the 'Browsing Off' widget is enabled instead: if( Printerlib::browsing_on && ! contains( Printerlib::cupsd_conf_browse_allow, "none" ) ) @@ -400,8 +445,12 @@ UI::ChangeWidget( `id(`cupsd_conf_browsing_on_radio_button), `Value, true ); UI::ChangeWidget( `id(`cupsd_conf_browse_allow_label), `Enabled, true ); UI::ChangeWidget( `id(`cupsd_conf_browse_allow_combo_box), `Enabled, true ); - UI::ChangeWidget( `id(`cupsd_conf_browse_allow_input), `Enabled, true ); - UI::ChangeWidget( `id(`cupsd_conf_browse_allow_input_label), `Enabled, true ); + // If browsing info is accepted from all hosts, + // it is useless to additionally accept it from specific IPs or networks: + if( ! contains( Printerlib::cupsd_conf_browse_allow, "all" ) ) + { UI::ChangeWidget( `id(`cupsd_conf_browse_allow_input), `Enabled, true ); + UI::ChangeWidget( `id(`cupsd_conf_browse_allow_input_label), `Enabled, true ); + } } else { initial_cupsd_conf_browsing_off_radio_button = true; Modified: trunk/printer/tools/modify_cupsd_conf URL: http://svn.opensuse.org/viewcvs/yast/trunk/printer/tools/modify_cupsd_conf?rev=50630&r1=50629&r2=50630&view=diff ============================================================================== --- trunk/printer/tools/modify_cupsd_conf (original) +++ trunk/printer/tools/modify_cupsd_conf Wed Sep 3 17:09:37 2008 @@ -100,9 +100,14 @@ then sed -i -e "${LAST_BROWSE_LINE}aBrowseOrder allow,deny" $CUPSDCONF else echo -en "\nBrowseOrder allow,deny\n\n" >>$CUPSDCONF fi - # All existing active BrowseAllow lines are removed (ignore case): + # All existing active BrowseAllow lines are removed (ignore case). + # Those lines can be removed because YaST supports BrowseAllow lines + # (YaST shows the BrowseAllow entries in the "printing via network" dialog) + # so that no BrowseAllow information is silently deleted: sed -i -e '/^BrowseAllow.*/Id' $CUPSDCONF - # All existing active BrowseDeny lines are deactivated (ignore case): + # All existing active BrowseDeny lines are deactivated (ignore case). + # Those lines are not removed because YaST does not support BrowseDeny lines + # so that a remove would silently delete BrowseDeny information: sed -i -e 's/^\(BrowseDeny.*\)$/#\1/i' $CUPSDCONF # Insert BrowseAllow lines before the BrowseOrder line # to have the new BrowseAllow lines at the matching place -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org