-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask-gantt
More file actions
executable file
·90 lines (64 loc) · 1.84 KB
/
task-gantt
File metadata and controls
executable file
·90 lines (64 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#! /usr/bin/env perl
use strict;
use warnings;
use feature 'say';
use Getopt::Long;
use JSON::PP;
use Project::Gantt;
use Project::Gantt::Skin;
use Time::Piece;
my $DEFAULT_DURATION = 1;
my $DEFAULT_FILENAME = 'gantt.png';
my $DEFAULT_DESCRIPTION = 'Gantt Chart for Taskwarrior';
my $filename = $DEFAULT_FILENAME;
my $description = $DEFAULT_DESCRIPTION;
GetOptions(
'stdout' => sub { $filename = 'png:-' },
'o|output=s' => \$filename,
'd|description=s' => \$description,
);
my @filters = @ARGV;
my @tasks = get_tasks(@filters);
my @task_hierarchy = resolve_dependencies(@tasks);
my $gc = Project::Gantt->new(
file => $filename,
description => $description,
mode => 'days',
);
for my $task (@task_hierarchy) {
unless (defined $task->{due}) {
warn "No due date specified. Skipping task...\n";
next;
}
unless (defined $task->{duration}) {
warn "No duration specified. Assuming 1 day...\n";
}
my $due_date = Time::Piece->strptime($task->{due}, "%Y%m%dT%H%M%SZ");
# The default duration also applies to durations set to 0
my $duration = $task->{duration} || $DEFAULT_DURATION;
my $start = $due_date - 24*60*60 * $duration;
my $end = $due_date;
my $id = $task->{id} || $task->{uuid};
my $resource = $gc->addResource(name => $id);
$gc->addTask(
description => $task->{description},
resource => $resource,
start => $start->strftime('%Y-%m-%d 00:00:00'),
end => $end->strftime('%Y-%m-%d 00:00:00')
);
}
# Save/output gantt chart
$gc->display();
sub get_tasks {
my @filters = @_;
my @command = ('task', 'export', @filters);
open my $pipe, '-|', @command or die "Could not execute @command: $!\n";
my $json = join "\n", <$pipe>;
close $pipe or warn "Could not close pipe: $!\n";
my $tasks = decode_json($json);
return @{$tasks};
}
sub resolve_dependencies {
my @tasks = @_;
return @tasks;
}