From: Penny Leach Date: Tue, 7 Apr 2009 14:20:55 +0000 (+0200) Subject: added modular support for the subsystem to communicate with (WRMS X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=9b98054259007b7f770429d707c9f45fa21363ef;p=tks.git added modular support for the subsystem to communicate with (WRMS default), and some error checking --- diff --git a/tks.pl b/tks.pl index 6ce07a9..c16c3b3 100755 --- a/tks.pl +++ b/tks.pl @@ -43,13 +43,20 @@ my $VERBOSE = $args->{'-v'}; my $tkdata = load_timesheet_file($args->{''}); #print Dumper($tkdata); -# connect to wrms -my $wrms = WRMS->new({ +my $wrmsargs = { username => $config{default}{username}, password => $config{default}{password}, site => $config{default}{site}, login => 1, -}) if $args->{'-c'}; +}; + +$config{default}{system} ||= 'WRMS'; +my $module = $config{default}{system}; + +eval "use $module"; +if ( $@ ) { print "Something went wrong: $@"; die "GAH!"; } +my $wrms = eval { $module->new($wrmsargs) }; +if ( $@ ) { print "Something went wrong: $@"; die "GAH!"; } # map of textual representations for WRs my $wrmap = $config{'wrmap'}; @@ -84,7 +91,7 @@ foreach my $date ( sort keys %{$tkdata} ) { $entry->{time} = int($entry->{time} * 100 + .5) / 100; # add the time to wrms - $wrms->add_time( + my $win = $wrms->add_time( $entry->{wr}, $date, $entry->{comment}, @@ -93,7 +100,12 @@ foreach my $date ( sort keys %{$tkdata} ) { ); # comment it out in the file - @lines[$entry->{linenumber} - 1] = '# ' . @lines[$entry->{linenumber} - 1]; + if ($win == 1) { + @lines[$entry->{linenumber} - 1] = '# ' . @lines[$entry->{linenumber} - 1]; + } else { + warn "Communicating timesheet data failed for the following entry. You will have to add it later. Not commenting out\n"; + warn Dumper($entry); + } $file_needs_write = 1; }