devi@23: package l3config; devi@23: devi@23: use Exporter; devi@23: use Getopt::Long; devi@23: devi@23: @ISA = ('Exporter'); devi@23: @EXPORT = qw(%Config &init_config); devi@23: devi@23: our $Config_File = "labmaker.conf"; devi@23: our %Config = ( devi@23: "skip_empty" => "yes", devi@23: "skip_interrupted" => "no", devi@23: "skip_wrong" => "no", devi@28: "editors" => ["vi", "pico", "ee", "vim", "nano"], devi@23: "pagers" => ["more", "less", "zmore", "zless", "info", devi@23: "man", "mc", "trafshow", "screen", "cfdisk", devi@23: "trafshow-bsd", "yes", "lynx", "links", "centericq" devi@23: ], devi@23: "terminal" => ["mc"], devi@23: "suppress_editors" => "yes", devi@23: "suppress_pagers" => "yes", devi@23: "suppress_terminal" => "yes", devi@23: devi@23: "terminal_width" => 100, devi@23: "terminal_height" => 100, devi@23: "verbose" => "yes", devi@23: devi@23: "head_lines" => 5, devi@23: "tail_lines" => 5, devi@23: "cache_head_lines" => 5, devi@23: "cache_tail_lines" => 5, devi@23: "skip_text" => "...", devi@23: "show_time" => "yes", devi@23: "show_diffs" => "yes", devi@23: "show_comments" => "yes", devi@23: devi@23: "input" => "/root/.labmaker", devi@23: "diffs" => "", devi@23: "input_mask" => "*.script", devi@23: "encoding" => "utf-8", devi@23: devi@23: "cache" => "/tmp/report.xml", devi@25: "cache_stat" => "/tmp/.report.dat", devi@23: devi@23: "output" => "/tmp/report.html", devi@23: #"output" => "report.xml", devi@23: "output_mask" => "INDEX", devi@23: "output_format" => "html", devi@27: "frontend_css" => "/l3/l3.css", devi@27: "frontend_google_ico" => "/l3/google.ico", devi@27: "frontend_linux_ico" => "/l3/linux.ico", devi@27: "frontend_freebsd_ico" => "/l3/freebsd.ico", devi@27: "frontend_opennet_ico" => "/l3/opennet.ico", devi@27: "frontend_local_ico" => "/l3/freebsd.ico", devi@23: devi@23: "signature" => "#lm:", devi@23: "from" => "", devi@23: "to" => "", devi@23: "lab" => "", devi@23: "keywords" => "linux command", devi@23: "files_keywords" => "linux file", devi@23: devi@23: comment_width => "300", devi@23: time_width => "60", devi@25: devi@25: "mode" => "daemon", # daemon | normal devi@25: "daemon_sleep_interval" => "1", devi@25: "detach" => "yes", devi@25: "agent_pidfile" => "$ENV{HOME}/.labmaker/l3-agent.pid", devi@23: devi@27: "backend_address" => "127.0.0.1", devi@27: "backend_port" => "18030", devi@27: "backend_pidfile" => "/tmp/l3-backend.pid", devi@27: "backend_datafile" => "/tmp/backend.xml", devi@27: devi@25: "l3-agent" => "l3-agent", devi@27: "l3-backend" => "l3-backend", devi@25: devi@23: "course-name" => "", devi@23: "course-code" => "", devi@23: "course-date" => "", devi@23: "course-center" => "", devi@23: "course-trainer" => "", devi@23: "course-student" => "", devi@23: ); devi@23: devi@23: sub read_config_file devi@23: { devi@23: my $config = $_[0]; devi@23: my $filename = $_[1]; devi@23: open(CONFIG, "$filename") devi@23: or return; devi@23: while () { devi@23: s/#.*//; devi@23: next if /^\s*$/; devi@23: my ($var, $val) = split /\s*=\s*/, $_, 2; devi@23: $var =~ s/\s*//; devi@23: $config->{$var} = $val; devi@23: } devi@23: close(CONFIG); devi@23: } devi@23: devi@23: devi@23: sub init_config devi@23: { devi@23: my %argv_config; devi@23: my %file_config; devi@23: read_config_file(\%file_config, $Config_File); devi@23: GetOptions(\%argv_config, map "$_=s", keys %Config); devi@23: %Config = (%Config, %file_config, %argv_config); devi@23: } devi@23: