#!/usr/bin/env perl #-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- # /* Functions for on-the-fly commentary on a tool's work. */ # # Copyright (C) 2000-2001 Ximian, Inc. # # Authors: Hans Petter Jansson # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Library General Public License as published # by the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU Library General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. $SCRIPTSDIR = "___scriptsdir___"; if ($SCRIPTSDIR =~ /^___scriptsdir__[_]/) { $SCRIPTSDIR = "."; $DOTIN = ".in"; } require "$SCRIPTSDIR/general.pl$DOTIN"; require "$SCRIPTSDIR/gettext.pl$DOTIN"; # --- Progress printing --- # $xst_progress_current = 0; # Compat with old $progress_max use. $xst_progress_last_percentage = 0; sub xst_progress { my $prc = $_[0]; # /* Don't go backwards. */ $prc = $xst_progress_last_percentage if ($prc < $xst_progress_last_percentage); # /* Don't go above 99%. */ $prc = 99 if ($prc >= 100); if ($xst_progress && (int $prc > int $xst_progress_last_percentage)) { &xst_report ("progress", $prc); $xst_progress_last_percentage = $prc; } } sub xst_progress_begin { &xst_progress (0); } sub xst_progress_end { &xst_progress (99); } sub xst_print_progress # Compat with old $progress_max use. { my $prc; $xst_progress_current++; &xst_progress (($xst_progress_current * 100) / $progress_max); } # --- Report printing --- # sub xst_report_begin { my ($tool) = @_; &xst_report ("begin"); &xst_report_enter (); &xst_progress_begin (); } sub xst_report_end { &xst_progress_end (); &xst_report_leave (); &xst_report ("end"); } sub xst_report_set_threshold { $xst_report_threshold = $_[0]; } sub xst_report_enter { # This has been trivialized because it is not working # correctly at the moment and is causing some trouble. # /* We'll probably replace this with something smarter */ # (like a detail-level value in the report hash) # when the report strings are used at the gui-level again. # $xst_report_level ++; $xst_report_level = 0; } sub xst_report_leave { # $xst_report_level --; $xst_report_level = 0; } # Escapes a report using the report line format. sub xst_report_escape { my ($args) = @_; my ($arg); foreach $arg (@$args) { $arg =~ s/\\/\\\\/g; $arg =~ s/::/\\::/g; } } $xst_report_level = 0; $xst_report_started = 0; # Just to trap these errors with the debugger easily. sub xst_report_stderr { my ($major, $key, $res) = @_; print STDERR "$xst_name - $major::${key}::$res"; } sub xst_report { my (@args) = @_; my ($key, $major, $minor, $str, $format, $res); my $report_message = &xst_report_table (); &xst_report_escape (\@args); $key = shift @args; if (! (exists $$report_message{$key})) { &xst_report ("report_minor_unk", $key); return; } ($major, $str) = @{$$report_message{$key}}; if (! (exists $xst_report_valid_majors{$major})) { &xst_report ("report_major_unk", $major, join ("::", $key, @args)); return; } $xst_report_started = 1 if !$xst_report_started && $key eq "begin" && $major eq "sys"; # Verbose (--verbose) output is human-readable only. $format = "$str\n"; $res = sprintf ($format, @args); if ($xst_do_verbose || $major eq "error" || $major eq "debug") { &xst_report_stderr ($major, $key, $res); } if ($key ne "progress") { return if ($xst_report_level >= $xst_report_threshold || !$xst_report_started); } # Report (--report) output is machine-readable. if ($xst_do_report) { print STDOUT join ("::", $major, $key, $str, @args) . "\n"; } &xst_debug_print_indented_string ($xst_report_level, "report $major:$key: $res"); } # Internal { my $report_table = \%xst_report_message; sub xst_report_table { my $table = shift @_; if ($table) # Add { foreach my $key (keys %$table) { $$report_table{$key} = $$table{$key} unless exists $$report_table{$key}; } } else # Get { return $report_table; } } } # This disables reporting. &xst_report_set_threshold (0); &textdomain ("ximian-setup-tools"); %xst_report_valid_majors = ( "sys" => 1, "error" => 1, "warn" => 1, "info" => 1, "debug" => 1 ); %xst_report_message = ( "begin" => ["sys", _("Start of work report.")], "end" => ["sys", _("End of work report.")], "progress" => ["sys", _("%d")], "compat" => ["info", _("%s.")], "report_major_unk" => ["error", _("Unknown major [%s] in report [%s].")], "report_minor_unk" => ["error", _("Unknown minor [%s].")], "directive_run" => ["info", _("Running directive [%s] with args [%s].")], "directive_unsup" => ["error", _("Directive [%s] not supported.")], "directive_invalid" => ["error", _("Directive [%s] structure has wrong format.")], "directive_badargs" => ["error", _("Directive [%s] requires exactly [%s] args in [%s].")], "directive_lowargs" => ["error", _("Directive [%s] requires at least [%s] args in [%s].")], "platform_unsup" => ["error", _("Your platform [%s] is not supported.")], "platform_undet" => ["error", _("Unable to determine host platform.")], "platform_success" => ["sys", _("Configuring for platform [%s] (%s).")], "platform_no_table" => ["error", _("No parse/replace table for platform [%s].")], "xml_unexp_tag" => ["error", _("Unexpected tag [%s].")], "xml_unexp_arg" => ["error", _("Unexpected argument [%s] to tag [%s].")], "file_copy_failed" => ["debug", _("Could not copy file [%s] to [%s].")], "file_open_read_failed" => ["warn", _("Could not open [%s] for reading.")], "file_open_read_success" => ["info", _("Reading options from [%s].")], "file_open_write_failed" => ["error", _("Failed to write to [%s].")], "file_open_write_create" => ["warn", _("Could not find [%s] for writing. Creating [%s].")], "file_open_write_success" => ["info", _("Writing to [%s].")], "file_run_pipe_failed" => ["warn", _("Failed to pipe command [%s] for reading.")], "file_run_pipe_success" => ["info", _("Piping command [%s] for reading.")], "file_run" => ["info", _("Running command [%s].")], "file_create_path" => ["info", _("Directory [%s] created.")], "file_backup_rotate" => ["info", _("Backup directory [%s] was rotated.")], "file_backup_success" => ["info", _("Saved backup for [%s].")], "file_open_filter_failed" => ["warn", _("No file to patch: [%s].")], "file_open_filter_create" => ["warn", _("Could not find [%s] for patching. Creating [%s].")], "file_open_filter_success" => ["info", _("Found [%s]. Patching [%s].")], "file_buffer_load" => ["info", _("Loading file [%s] to buffer.")], "file_buffer_save" => ["info", _("Saving buffer to file [%s].")], "file_remove" => ["info", _("Removing file [%s].")], "file_locate_tool_success" => ["info", _("Found tool [%s].")], "file_locate_tool_failed" => ["warn", _("Couldn't find tool [%s].")], "parse_table" => ["info", _("Parsing option [%s].")], "parse_trivial" => ["info", _("Trivialy passing [%s].")], "parse_split" => ["info", _("Getting option [%s] from [%s].")], "parse_split_hash" => ["info", _("Getting configuration from [%s].")], "parse_split_hash_cont" => ["info", _("Getting configuration from [%s].")], "parse_sh" => ["info", _("Getting shell option [%s] from [%s].")], "parse_kw" => ["info", _("Getting keyword [%s] from [%s].")], "parse_line_first" => ["info", _("Getting information from [%s].")], "parse_chat" => ["info", _("Getting chat information from [%s].")], "parse_ini" => ["info", _("Getting option [%s] from [%s], section [%s].")], "parse_ifaces_str" => ["info", _("Getting option [%s] from interface [%s].")], "parse_ifaces_kw" => ["info", _("Getting keyword [%s] from interface [%s].")], "parse_ifaces_kw_strange" => ["warn", _("Keyword for interface [%s] in [%s] had unexpected value.")], "replace_split" => ["info", _("Replacing key [%s] in [%s].")], "replace_sh" => ["info", _("Replacing shell var [%s] in [%s].")], "replace_kw" => ["info", _("Replacing keyword [%s] in [%s].")], "replace_line_first" => ["info", _("Replacing contents of file [%s].")], "replace_chat" => ["info", _("Replacing values in [%s].")], "replace_ini" => ["info", _("Replacing variable [%s] in section [%s] of [%s].")], "replace_del_ini_sect" => ["info", _("Removing section [%s] from [%s].")], "replace_ifaces_str" => ["info", _("Replacing option [%s] from interface [%s].")], "replace_ifaces_kw" => ["info", _("Replacing keyword [%s] from interface [%s].")], "service_status_running" => ["info", _("Service [%s] is running.")], "service_status_stopped" => ["info", _("Service [%s] is stopped.")], "service_sysv_unsupported" => ["error", _("No SystemV support for platform [%s].")], "service_sysv_not_found" => ["warn", _("Could not find SystemV scripts for service [%s].")], "service_sysv_no_runlevel" => ["warn", _("Could not find SystemV runlevel [%s] directory [%s].")], "service_sysv_remove_link" => ["info", _("Removed SystemV link [%s].")], "service_sysv_add_link" => ["info", _("Created SystemV link [%s].")], "service_sysv_op_unk" => ["error", _("Unknown initd operation [%s].")], "service_sysv_op_success" => ["info", _("Service [%s] %s.")], "service_sysv_op_failed" => ["warn", _("Service [%s] could not be %s.")], "network_dialing_get" => ["info", _("Loading ISP configurations.")], "network_iface_active_get" => ["info", _("Finding active interfaces.")], "network_iface_is_active" => ["info", _("Checking if interface [%s] is active.")], "network_hostname_set" => ["info", _("Setting hostname to [%s].")], "network_dialing_set" => ["info", _("Saving ISP configurations.")], "network_remove_pap" => ["info", _("Removing entry [%s] from [%s].")], "network_iface_set" => ["info", _("Configuring interface [%s].")], "network_iface_activate" => ["info", _("Activating interface [%s].")], "network_iface_deactivate" => ["info", _("Deactivating interface [%s].")], "network_ifaces_set" => ["info", _("Setting up interfaces.")], "network_get_pap_passwd" => ["info", _("Getting PAP/CHAP password for [%s] from [%s].")], "network_get_ppp_option" => ["info", _("Getting option [%s] from [%s].")], "network_set_ppp_option" => ["info", _("Setting option [%s] in [%s].")], "network_set_ppp_connect" => ["info", _("Setting connect option in [%s].")], "network_get_ppp_unsup" => ["info", _("Getting additional options from [%s].")], "network_set_ppp_unsup" => ["info", _("Setting additional options in [%s].")], "network_bootproto_unsup" => ["warn", _("Boot method [%s] for interface [%s] not supported.")], "network_get_remote" => ["info", _("Getting remote address for interface [%s].")], "network_set_remote" => ["info", _("Setting remote address for interface [%s].")], "network_ensure_lo" => ["info", _("Ensuring loopback interface configuration.")], "filesys_mount" => ["info", _("Mounting [%s] on [%s].")], "filesys_mount_failed" => ["warn", _("Failed to mount [%s] on [%s].")], "filesys_unmount" => ["info", _("Unmounting [%s] from [%s].")], "filesys_unmount_failed" => ["warn", _("Failed to unmount [%s] from [%s].")], "boot_lilo_failed" => ["warn", _("Failed to run lilo.")], "boot_lilo_success" => ["info", _("Succesfully executed lilo.")], "boot_conf_read_failed" => ["error", _("Failed to open boot configuration file [%s].")], "boot_grub_convert_failed" => ["error", _("Conversion of [%s] failed.")], "sfdisk_failed" => ["error", _("Could not run sfdisk.")], "disks_fstab_add" => ["info", _("Adding [%s] to fstab.")], "disks_partition_probe" => ["info", _("Looking for partitions on [%s].")], "disks_size_query" => ["info", _("Querying size of [%s].")], "disks_mount" => ["info", _("Mounting [%s].")], "disks_umount" => ["info", _("Unmounting [%s].")], "disks_mount_error" => ["error", _("Could not find mount tools. No mounting done.")], "memory_swap_found" => ["info", _("Found swap entry [%s].")], "memory_swap_probe" => ["info", _("Looking for swap entries.")], "print_no_printtool" => ["warn", _("No printtool setup in directory [%s].")], "time_timezone_scan" => ["info", _("Scanning timezones.")], "time_timezone_cmp" => ["info", _("Scanning timezones: [%s].")], "time_timezone_set" => ["info", _("Setting timezone as [%s].")], "time_localtime_set" => ["info", _("Setting local time as [%s].")] ); 1;