]> git.mjollnir.org Git - tks.git/commitdiff
added modular support for the subsystem to communicate with (WRMS
authorPenny Leach <penny@mjollnir.org>
Tue, 7 Apr 2009 14:20:55 +0000 (16:20 +0200)
committerPenny Leach <penny@mjollnir.org>
Tue, 7 Apr 2009 14:20:55 +0000 (16:20 +0200)
default), and some error checking

tks.pl

diff --git a/tks.pl b/tks.pl
index 6ce07a92c7516335e9d9494fe9d5905aca57793d..c16c3b3fe884809d188a537ae1e870df5bfa0b66 100755 (executable)
--- a/tks.pl
+++ b/tks.pl
@@ -43,13 +43,20 @@ my $VERBOSE = $args->{'-v'};
 my $tkdata = load_timesheet_file($args->{'<file>'});
 #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;
     }