forked from vit-project/vit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
read.pl
220 lines (200 loc) · 6.04 KB
/
read.pl
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# Copyright 2012 - 2013, Steve Rader
# Copyright 2013 - 2016, Scott Kostyshak
sub read_report {
my ($mode) = @_;
&inner_read_report($mode);
if ( $prev_ch eq 'd' && $error_msg =~ /Error: task .*: no matches/ ) {
# take care of marking last done...
&inner_read_report('init');
}
if ( $current_command eq 'summary' ) {
&get_num_tasks();
}
}
#------------------------------------------------------------------
sub inner_read_report {
my ($mode) = @_;
my $report_header_idx = 0;
my $args;
my @prev_num_tasks = $num_tasks;
my @prev_report2taskid = @report2taskid;
my @prev_report_tokens = @report_tokens;
my @prev_report_lines = @report_lines;
my @prev_report_colors_fg = @report_colors_fg;
my @prev_report_colors_bg = @report_colors_bg;
my @prev_report_attrs = @report_attrs;
my @prev_report_header_tokens = @report_header_tokens;
my @prev_report_header_attrs = @report_header_attrs;
$prev_convergence = $convergence;
$prev_display_start_idx = $display_start_idx;
$prev_task_selected_idx = $task_selected_idx;
@report2taskid = ();
@report_tokens = ();
@report_lines = ();
@report_colors_fg = ();
@report_colors_bg = ();
@report_attrs = ();
@report_header_tokens = ();
@report_header_attrs = ();
@project_types = ();
if ( $mode eq 'init' ) {
$task_selected_idx = 0;
$display_start_idx = 0;
}
&audit("EXEC $task stat 2>&1");
open(IN,"$task stat 2>&1 |");
while(<IN>) {
chop;
if ( $_ =~ /^\s*$/ ) { next; }
$_ =~ s/\x1b.*?m//g;
if ( $_ =~ /Pending\s+(\d+)/ ) {
$tasks_pending = $1;
next;
}
if ( $_ =~ /Completed\s+(\d+)/ ) {
$tasks_completed = $1;
next;
}
}
close(IN);
if ( $burndown eq "yes" ) {
$args = "rc.defaultwidth=$REPORT_COLS rc.defaultheight=$REPORT_LINES burndown";
&audit("EXEC $task $args 2>&1");
open(IN,"$task $args 2>&1 |");
while(<IN>) {
if ( $_ =~ /Estimated completion: No convergence/ ) {
$convergence = "no convergence";
last;
}
if ( $_ =~ /Estimated completion: .* \((.*)\)/ ) {
$convergence = "convergence in $1";
last;
}
}
close(IN);
if ( $convergence ne $prev_convergence && $prev_convergence ne '' ) {
$flash_convergence = 1;
} else {
$flash_convergence = 0;
}
}
&audit("EXEC $task projects 2>&1");
open(IN,"$task projects 2>&1 |");
while(<IN>) {
chop;
if ( $_ =~ /^\s*$/ ) { next; }
$_ =~ s/\x1b.*?m//g;
if ( $_ =~ /^\w+ override/ ) { next; }
if ( $_ =~ /^Project/ ) { next; }
if ( $_ =~ /^\d+ project/ ) { next; }
my $p = (split(/\s+/,$_))[0];
if ( $p eq '(none)' ) { next; }
push(@project_types, $p);
}
close(IN);
{
&audit("EXEC $task tags 2>&1");
@tag_types=();
open(IN,"$task tags 2>&1 |");
my $_started = undef;
while (my $line=<IN>) {
# list of tasks starts after a line containing "--- -----"
if ($line =~ /^-+ -+$/) {
$_started = 1;
next;
}
next unless $_started;
# save tag in first field of line
chomp $line;
last if $line eq '';
my $t = ( split(/\s+/,$line) )[0];
push(@tag_types, $t);
}
close(IN);
}
$args = "rc.defaultwidth=$REPORT_COLS rc.defaultheight=0 rc._forcecolor=on $current_command";
&audit("EXEC $task $args 2> /dev/null");
open(IN,"$task $args 2> /dev/null |");
my $i = 0;
my $prev_id;
while(<IN>) {
chop;
$_ = &decode_utf8($_);
if ( $_ =~ /^\s*$/ ) { next; }
if ( $_ =~ /^(\d+) tasks?$/ ||
$_ =~ /^\x1b.*?m(\d+) tasks?\x1b\[0m$/ ||
$_ =~ /^\d+ tasks?, (\d+) shown$/ ||
$_ =~ /^\x1b.*?m\d+ tasks?, (\d+) shown\x1b\[0m$/ ) {
$num_tasks = $1;
next;
}
&parse_report_line($i,$_);
$_ =~ s/\x1b.*?m//g;
$report_lines[$i] = $_;
# check if this is the header line
if ( $_ =~ /^ID / ) {
$report_header_idx = $i;
$i++;
next;
}
if ( $_ =~ /^\s{0,5}(\d+) / ) {
$report2taskid[$i] = $1;
$taskid2report[$1] = $i;
&audit("inner_read_report: report2taskid[$i]=$1, taskid2report[$1]=$i")
} else {
$report2taskid[$i] = $prev_id;
audit("inner_read_report: report2taskid[$i]=$prev_id")
}
$prev_id = $report2taskid[$i];
$i++;
}
close(IN);
if ( $#report_tokens > -1 ) {
# TODO: this code is quite hard to understand; should probably be rewritten
# or at least needs explanation of what is happening here. [BaZo]
@report_header_tokens = @{ $report_tokens[$report_header_idx] };
@report_header_attrs = @{ $report_attrs[$report_header_idx] };
splice(@report_tokens,$report_header_idx,1);
splice(@report_lines,$report_header_idx,1);
splice(@report_colors_fg,$report_header_idx,1);
splice(@report_colors_bg,$report_header_idx,1);
splice(@report_attrs,$report_header_idx,1);
splice(@report2taskid,$report_header_idx,1);
for (0..$#taskid2report) {
$taskid2report[$_]-- if ($_>=$report_header_idx)
}
if ( $task_selected_idx > $#report_tokens ) {
$task_selected_idx = $#report_tokens;
}
} else {
$error_msg = "Error: task $current_command: no matches";
$current_command = $prev_command;
$display_start_idx = $prev_display_start_idx;
$task_selected_idx = $prev_task_selected_idx;
@report_header_tokens = @prev_report_header_tokens;
@report_header_attrs = @prev_report_header_attrs;
@report_tokens = @prev_report_tokens;
@report_lines = @prev_report_lines;
@report_colors_fg = @prev_report_colors_fg;
@report_colors_bg = @prev_report_colors_bg;
@report_attrs = @prev_report_attrs;
@report2taskid = @prev_report2taskid;
$convergence = $prev_convergence;
return;
}
}
#------------------------------------------------------------------
sub get_num_tasks {
$num_tasks = 0;
&audit("EXEC $task projects 2> /dev/null");
open(IN,"$task projects 2> /dev/null |");
while(<IN>) {
if ( $_ =~ /(\d+) task/ ) {
$num_tasks = $1;
last;
}
}
close(IN);
}
#------------------------------------------------------------------
return 1;