home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / system-tools-backends-2.0 / scripts / Utils / Report.pm < prev    next >
Encoding:
Perl POD Document  |  2006-08-14  |  12.0 KB  |  297 lines

  1. #!/usr/bin/env perl
  2. #-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  3.  
  4. # /* Functions for on-the-fly commentary on a tool's work. */
  5. #
  6. # Copyright (C) 2000-2001 Ximian, Inc.
  7. #
  8. # Authors: Hans Petter Jansson <hpj@ximian.com>
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU Library General Public License as published
  12. # by the Free Software Foundation; either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. # GNU Library General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Library General Public License
  21. # along with this program; if not, write to the Free Software
  22. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  23.  
  24. # --- Report printing --- #
  25.  
  26. package Utils::Report;
  27.  
  28.  
  29. my $report_threshold = 0;
  30. my $report_table = \%gst_report_message;
  31.  
  32. sub begin
  33. {
  34.   my ($tool) = @_;
  35.   
  36.   &do_report ("begin");
  37.   &enter ();
  38. }
  39.  
  40.  
  41. sub end
  42. {
  43.   &leave ();
  44.   &do_report ("end");
  45. }
  46.  
  47.  
  48. sub set_threshold
  49. {
  50.   $report_threshold = $_[0];
  51. }
  52.  
  53.  
  54. sub enter
  55. {
  56.   # This has been trivialized because it is not working
  57.   # correctly at the moment and is causing some trouble.
  58.   # /* We'll probably replace this with something smarter */
  59.   # (like a detail-level value in the report hash)
  60.   # when the report strings are used at the gui-level again.
  61. #  $gst_report_level ++;
  62.   $gst_report_level = 0;
  63. }
  64.  
  65.  
  66. sub leave
  67. {
  68. #  $gst_report_level --;
  69.   $gst_report_level = 0;
  70. }
  71.  
  72.  
  73. # Escapes a report using the report line format.
  74. sub escape_report
  75. {
  76.   my ($args) = @_;
  77.   my ($arg);
  78.  
  79.   foreach $arg (@$args)
  80.   {
  81.     $arg =~ s/\\/\\\\/g;
  82.     $arg =~ s/::/\\::/g;
  83.   }
  84. }
  85.  
  86.  
  87. $gst_report_level = 0;
  88. $gst_report_started = 0;
  89.  
  90. # Just to trap these errors with the debugger easily.
  91. sub do_report_stderr
  92. {
  93.   my ($major, $key, $res) = @_;
  94.   
  95.   print STDERR "$major::${key}::$res";
  96. }
  97.  
  98. sub do_report
  99. {
  100.   my (@args) = @_;
  101.   my ($key, $major, $minor, $str, $format, $res);
  102.   my $report_message = $report_table;
  103.  
  104.   &escape_report (\@args);
  105.  
  106.   $key = shift @args;
  107.  
  108.   if (! (exists $$report_message{$key}))
  109.   {
  110.       &do_report ("report_minor_unk", $key);
  111.       return;
  112.   }
  113.  
  114.   ($major, $str) = @{$$report_message{$key}};
  115.  
  116.   if (! (exists $gst_report_valid_majors{$major}))
  117.   {
  118.       &do_report ("report_major_unk", $major, join ("::", $key, @args));
  119.       return;
  120.   }
  121.  
  122.   $gst_report_started = 1 if !$gst_report_started && $key eq "begin" && $major eq "sys";
  123.  
  124.   # Verbose (--verbose) output is human-readable only.
  125.   $format = "$str\n";
  126.   $res = sprintf ($format, @args);
  127.  
  128.   if ($Utils::Backend::do_verbose   ||
  129.       $major eq "error" ||
  130.       $major eq "debug")
  131.   {
  132.     &do_report_stderr ($major, $key, $res);
  133.   }
  134.  
  135.   # Report (--report) output is machine-readable.
  136.   if ($Utils::Backend::do_report)
  137.   {
  138.     print STDOUT join ("::", $major, $key, $str, @args) . "\n";
  139.   }
  140. }
  141.  
  142. sub add
  143. {
  144.   my $table = shift @_;
  145.  
  146.   if ($table) # Add
  147.   {
  148.     foreach my $key (keys %$table)
  149.     {
  150.       $$report_table{$key} = $$table{$key} unless exists $$report_table{$key};
  151.     }
  152.   }
  153. }
  154.  
  155. # This disables reporting.
  156. &set_threshold (0);
  157.  
  158. %gst_report_valid_majors = (
  159.     "sys"   => 1,
  160.     "error" => 1,
  161.     "warn"  => 1,
  162.     "info"  => 1,
  163.     "debug" => 1
  164.     );
  165.  
  166. %gst_report_message =
  167.     (
  168.      "begin"    => ["sys", "Start of work report."],
  169.      "end"      => ["sys", "End of work report."],
  170.      "compat"   => ["info", "%s."],
  171.  
  172.      "report_major_unk"         => ["error", "Unknown major [%s] in report [%s]."],
  173.      "report_minor_unk"         => ["error", "Unknown minor [%s]."],
  174.  
  175.      "directive_run"            => ["info",  "Running directive [%s] with args [%s]."],
  176.      "directive_unsup"          => ["error", "Directive [%s] not supported."],
  177.      "directive_invalid"        => ["error", "Directive [%s] structure has wrong format."],
  178.      "directive_badargs"        => ["error", "Directive [%s] requires exactly [%s] args in [%s]."],
  179.      "directive_lowargs"        => ["error", "Directive [%s] requires at least [%s] args in [%s]."],
  180.  
  181.      "platform_unsup"           => ["error", "Your platform [%s] is not supported."],
  182.      "platform_undet"           => ["error", "Unable to determine host platform."],
  183.      "platform_success"         => ["sys",   "Configuring for platform [%s] (%s)."],
  184.      "platform_no_table"        => ["error", "No parse/replace table for platform [%s]."],
  185.  
  186.      "xml_unexp_tag"            => ["error", "Unexpected tag [%s]."],
  187.      "xml_unexp_arg"            => ["error", "Unexpected argument [%s] to tag [%s]."],
  188.  
  189.      "file_copy_failed"         => ["debug", "Could not copy file [%s] to [%s]."],
  190.      "file_open_read_failed"    => ["warn",  "Could not open [%s] for reading."],
  191.      "file_open_read_success"   => ["info",  "Reading options from [%s]."],
  192.      "file_open_write_failed"   => ["error", "Failed to write to [%s]."],
  193.      "file_open_write_create"   => ["warn",  "Could not find [%s] for writing. Creating [%s]."],
  194.      "file_open_write_success"  => ["info",  "Writing to [%s]."],
  195.      "file_run_pipe_failed"     => ["warn",  "Failed to pipe command [%s] for reading."],
  196.      "file_run_pipe_success"    => ["info",  "Piping command [%s] for reading."],
  197.      "file_run"                 => ["info",  "Running command [%s]."],
  198.      "file_create_path"         => ["info",  "Directory [%s] created."],
  199.      "file_backup_rotate"       => ["info",  "Backup directory [%s] was rotated."],
  200.      "file_backup_success"      => ["info",  "Saved backup for [%s]."],
  201.      "file_open_filter_failed"  => ["warn",  "No file to patch: [%s]."],
  202.      "file_open_filter_create"  => ["warn",  "Could not find [%s] for patching. Creating [%s]."],
  203.      "file_open_filter_success" => ["info",  "Found [%s]. Patching [%s]."],
  204.      "file_buffer_load"         => ["info",  "Loading file [%s] to buffer."],
  205.      "file_buffer_save"         => ["info",  "Saving buffer to file [%s]."],
  206.      "file_remove"              => ["info",  "Removing file [%s]."],
  207.      "file_locate_tool_success" => ["info",  "Found tool [%s]."],
  208.      "file_locate_tool_failed"  => ["warn",  "Couldn't find tool [%s]."],
  209.      
  210.      "parse_table"              => ["info",  "Parsing option [%s]."],
  211.      "parse_trivial"            => ["info",  "Trivialy passing [%s]."],
  212.      "parse_split"              => ["info",  "Getting option [%s] from [%s]."],
  213.      "parse_split_hash"         => ["info",  "Getting configuration from [%s]."],
  214.      "parse_split_hash_cont"    => ["info",  "Getting configuration from [%s]."],
  215.      "parse_sh"                 => ["info",  "Getting shell option [%s] from [%s]."],
  216.      "parse_kw"                 => ["info",  "Getting keyword [%s] from [%s]."],
  217.      "parse_line_first"         => ["info",  "Getting information from [%s]."],
  218.      "parse_chat"               => ["info",  "Getting chat information from [%s]."],
  219.      "parse_ini"                => ["info",  "Getting option [%s] from [%s], section [%s]."],
  220.      "parse_ifaces_str"         => ["info",  "Getting option [%s] from interface [%s]."],
  221.      "parse_ifaces_kw"          => ["info",  "Getting keyword [%s] from interface [%s]."],
  222.      "parse_ifaces_kw_strange"  => ["warn",  "Keyword for interface [%s] in [%s] had unexpected value."],
  223.  
  224.      "replace_split"            => ["info",  "Replacing key [%s] in [%s]."],
  225.      "replace_sh"               => ["info",  "Replacing shell var [%s] in [%s]."],
  226.      "replace_kw"               => ["info",  "Replacing keyword [%s] in [%s]."],
  227.      "replace_line_first"       => ["info",  "Replacing contents of file [%s]."],
  228.      "replace_chat"             => ["info",  "Replacing values in [%s]."],
  229.      "replace_ini"              => ["info",  "Replacing variable [%s] in section [%s] of [%s]."],
  230.      "replace_del_ini_sect"     => ["info",  "Removing section [%s] from [%s]."],
  231.      "replace_ifaces_str"       => ["info",  "Replacing option [%s] from interface [%s]."],
  232.      "replace_ifaces_kw"        => ["info",  "Replacing keyword [%s] from interface [%s]."],
  233.      
  234.      "service_status_running"   => ["info",  "Service [%s] is running."],
  235.      "service_status_stopped"   => ["info",  "Service [%s] is stopped."],
  236.      "service_sysv_unsupported" => ["info",  "No SystemV support for platform [%s]."],
  237.      "service_sysv_not_found"   => ["warn",  "Could not find SystemV scripts for service [%s]."],
  238.      "service_sysv_no_runlevel" => ["warn",  "Could not find SystemV runlevel [%s] directory [%s]."],
  239.      "service_sysv_remove_link" => ["info",  "Removed SystemV link [%s]."],
  240.      "service_sysv_add_link"    => ["info",  "Created SystemV link [%s]."],
  241.      "service_sysv_op_unk"      => ["error", "Unknown initd operation [%s]."],
  242.      "service_sysv_op_success"  => ["info",  "Service [%s] %s."],
  243.      "service_sysv_op_failed"   => ["warn",  "Service [%s] could not be %s."],
  244.  
  245.      "network_dialing_get"      => ["info",  "Loading ISP configurations."],
  246.      "network_iface_active_get" => ["info",  "Finding active interfaces."],
  247.      "network_iface_is_active"  => ["info",  "Checking if interface [%s] is active."],
  248.      "network_hostname_set"     => ["info",  "Setting hostname to [%s]."],
  249.      "network_dialing_set"      => ["info",  "Saving ISP configurations."],
  250.      "network_remove_pap"       => ["info",  "Removing entry [%s] from [%s]."],
  251.      "network_iface_set"        => ["info",  "Configuring interface [%s]."],
  252.      "network_iface_activate"   => ["info",  "Activating interface [%s]."],
  253.      "network_iface_deactivate" => ["info",  "Deactivating interface [%s]."],
  254.      "network_ifaces_set"       => ["info",  "Setting up interfaces."],
  255.      "network_get_pap_passwd"   => ["info",  "Getting PAP/CHAP password for [%s] from [%s]."],
  256.      "network_get_ppp_option"   => ["info",  "Getting option [%s] from [%s]."],
  257.      "network_set_ppp_option"   => ["info",  "Setting option [%s] in [%s]."],
  258.      "network_set_ppp_connect"  => ["info",  "Setting connect option in [%s]."],
  259.      "network_get_ppp_unsup"    => ["info",  "Getting additional options from [%s]."],
  260.      "network_set_ppp_unsup"    => ["info",  "Setting additional options in [%s]."],
  261.      "network_bootproto_unsup"  => ["warn",  "Boot method [%s] for interface [%s] not supported."],
  262.      "network_get_remote"       => ["info",  "Getting remote address for interface [%s]."],
  263.      "network_set_remote"       => ["info",  "Setting remote address for interface [%s]."],
  264.      "network_ensure_lo"        => ["info",  "Ensuring loopback interface configuration."],
  265.  
  266.      "filesys_mount"            => ["info",  "Mounting [%s] on [%s]."],
  267.      "filesys_mount_failed"     => ["warn",  "Failed to mount [%s] on [%s]."],
  268.      "filesys_unmount"          => ["info",  "Unmounting [%s] from [%s]."],
  269.      "filesys_unmount_failed"   => ["warn",  "Failed to unmount [%s] from [%s]."],
  270.  
  271.      "boot_lilo_failed"         => ["warn",  "Failed to run lilo."],
  272.      "boot_lilo_success"        => ["info",  "Succesfully executed lilo."],
  273.      "boot_conf_read_failed"    => ["error", "Failed to open boot configuration file [%s]."],
  274.      "boot_grub_convert_failed" => ["error", "Conversion of [%s] failed."],
  275.  
  276.      "sfdisk_failed"            => ["error", "Could not run sfdisk."],
  277.  
  278.      "disks_fstab_add"          => ["info",  "Adding [%s] to fstab."],
  279.      "disks_partition_probe"    => ["info",  "Looking for partitions on [%s]."],
  280.      "disks_size_query"         => ["info",  "Querying size of [%s]."],
  281.      "disks_mount"              => ["info",  "Mounting [%s]."],
  282.      "disks_umount"             => ["info",  "Unmounting [%s]."],
  283.      "disks_mount_error"        => ["error", "Could not find mount tools. No mounting done."],
  284.      
  285.      "memory_swap_found"        => ["info",  "Found swap entry [%s]."],
  286.      "memory_swap_probe"        => ["info",  "Looking for swap entries."],
  287.      
  288.      "print_no_printtool"       => ["warn",  "No printtool setup in directory [%s]."],
  289.  
  290.      "time_timezone_scan"       => ["info",  "Scanning timezones."],
  291.      "time_timezone_cmp"        => ["info",  "Scanning timezones: [%s]."],
  292.      "time_timezone_set"        => ["info",  "Setting timezone as [%s]."],
  293.      "time_localtime_set"       => ["info",  "Setting local time as [%s]."]
  294.     );
  295.  
  296. 1;
  297.