return $id;
}
+sub start_project ($$)
+{
+ my $start_time = shift;
+ my $title = shift;
+
+
+ my $current = get_current_project();
+ if ( not $current )
+ {
+ if ( not $title )
+ {
+ $current = get_last( );
+ }
+ else
+ {
+ $current = get_project_id( $title );
+ if ( not $current )
+ {
+ printf("No project by that name! Creating a new one.\n");
+ $current = create_project($title);
+ }
+ }
+
+ # Break off here if we haven't gotten an ID yet.
+ return undef if not $current;
+
+ set_current_project($current);
+
+ # First iteration is VERY naive: simply add the start time to the bottom of the tracking file
+ # Will have to do more logic: if the start point is before one of the times already in the track,
+ # the file will have to be manipulated to get coherent tracking!
+ open (TRACK, ">>" . $trk_dir . "/" . $current . "/tracking" ) or die ("Unable to open file, $!");
+ printf(TRACK "[%s]", time2str($start_time));
+ close (TRACK);
+
+ return $current;
+ }
+
+ return undef;
+}
+
+sub close_project ($)
+{
+
+ my $stop_time = shift;
+
+ my $current = get_current_project();
+
+ die ("Project exists, but tracking file does not!") if ( not -f $trk_dir . "/" . $current . "/tracking" );
+
+ # First iteration is VERY naive: simply add the stop time to the bottom line of the tracking file
+ # Will have to do more logic: if the start point is before one of the times already in the track,
+ # the file will have to be manipulated to get coherent tracking!
+ # In addtion to this: actually do some file sanity checking!
+ open (TRACK, ">>" . $trk_dir . "/" . $current . "/tracking" ) or die ("Unable to open file, $!");
+ printf(TRACK " to [%s]\n", time2str($stop_time));
+ close (TRACK);
+
+ unlink ( $trk_dir . "/current" );
+}
+
############################################################
if ( ! -d $trk_dir )
my $current = get_current_project();
if ( not $current )
{
- $current = get_project_id( $title );
+ $current = start_project( $start_time, $title );
+
if ( not $current )
{
- printf("No project by that name! Creating a new one.\n");
- $current = create_project($title);
+ printf("Something weird happened.\n");
+ exit(1);
}
- else
- {
- printf("Continuing tracking for existing project.\n");
- }
- set_current_project($current);
}
else
{
printf("A project is being tracked: %s\n", get_project_name( $current ) );
- printf("Stop current tracking before starting a new one\n");
- exit(0);
+ close_project($start_time);
+ $current = start_project( $start_time, $title );
}
- # First iteration is VERY naive: simply add the start time to the bottom of the tracking file
- # Will have to do more logic: if the start point is before one of the times already in the track,
- # the file will have to be manipulated to get coherent tracking!
- open (TRACK, ">>" . $trk_dir . "/" . $current . "/tracking" ) or die ("Unable to open file, $!");
- printf(TRACK "[%s]", time2str($start_time));
- close (TRACK);
-
printf("Started tracking of '%s' at %s\n\n", $title, scalar localtime $start_time);
}
elsif ( ( $command eq "stop") || ($command eq "off" ) )
}
my $title = get_project_name( $current );
- die ("Project exists, but tracking file does not!") if ( not -f $trk_dir . "/" . $current . "/tracking" );
-
- # First iteration is VERY naive: simply add the stop time to the bottom line of the tracking file
- # Will have to do more logic: if the start point is before one of the times already in the track,
- # the file will have to be manipulated to get coherent tracking!
- # In addtion to this: actually do some file sanity checking!
- open (TRACK, ">>" . $trk_dir . "/" . $current . "/tracking" ) or die ("Unable to open file, $!");
- printf(TRACK " to [%s]\n", time2str($stop_time));
- close (TRACK);
-
- unlink ( $trk_dir . "/current" );
+ close_project($stop_time);
printf("Stopped tracking of '%s' at %s\n\n", $title, scalar localtime $stop_time);
}