1 # BEGIN BPS TAGGED BLOCK {{{
5 # This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
6 # <sales@bestpractical.com>
8 # (Except where explicitly superseded by other copyright notices)
13 # This work is made available to you under the terms of Version 2 of
14 # the GNU General Public License. A copy of that license should have
15 # been provided with this software, but in any event can be snarfed
18 # This work is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 # 02110-1301 or visit their web page on the internet at
27 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 # CONTRIBUTION SUBMISSION POLICY:
32 # (The following paragraph is not intended to limit the rights granted
33 # to you to modify and distribute this software under the terms of
34 # the GNU General Public License and is only of importance to you if
35 # you choose to contribute your changes and enhancements to the
36 # community by submitting them to Best Practical Solutions, LLC.)
38 # By intentionally submitting any modifications, corrections or
39 # derivatives to this work, or any other work intended for use with
40 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 # you are the copyright holder for those contributions and you grant
42 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 # royalty-free, perpetual, license to use, copy, create derivative
44 # works based on those contributions, and sublicense and distribute
45 # those contributions and any derivatives thereof.
47 # END BPS TAGGED BLOCK }}}
60 $s .= int($time/60/60)."hr "
62 $s .= int(($time % (60*60))/60)."min "
64 $s .= int($time % 60)."s"
81 my $fraction = $args{max} ? $args{now} / $args{max} : 0;
83 my $max_width = $args{cols} - 30;
84 my $bar_width = int($max_width * $fraction);
86 return sprintf "%20s |%-" . $max_width . "s| %3d%%\n",
87 $args{label}, $args{char} x $bar_width, $fraction*100;
92 top => sub { print "\n\n" },
95 bars => [qw/Ticket Transaction Attachment User Group/],
102 $max_objects += $_ for values %{ $args{max} };
111 my $now = Time::HiRes::time();
112 return if defined $last_time and $now - $last_time <= $args{every} and not $force;
114 $start = $now unless $start;
117 my $elapsed = $now - $start;
119 # Determine terminal size
121 my ($cols, $rows) = (80, 25);
123 require Term::ReadKey;
124 ($cols, $rows) = Term::ReadKey::GetTerminalSize();
128 $args{top}->($elapsed, $rows, $cols);
130 my %counts = $args{counts}->();
131 for my $class (map {"RT::$_"} @{$args{bars}}) {
132 my $display = $class;
133 $display =~ s/^RT::(.*)/@{[$1]}s:/;
136 now => $counts{$class},
137 max => $args{max}{$class},
143 $total += $_ for map {$counts{$_}} grep {exists $args{max}{$_}} keys %counts;
144 $offset = $total unless defined $offset;
145 print "\n", progress_bar(
154 my $fraction = $max_objects
155 ? ($total - $offset)/($max_objects - $offset)
157 if ($fraction > 0.03) {
160 + 0.25 * ($elapsed / $fraction - $elapsed);
162 $left = ($elapsed / $fraction - $elapsed);
166 printf "%20s %s\n", "Elapsed time:",
167 format_time($elapsed);
168 printf "%20s %s\n", "Estimated left:",
169 (defined $left) ? format_time($left) : "-";
171 $args{bottom}->($elapsed, $rows, $cols);
177 my ($dir, $file) = @_;
180 RT->Config->Set(LogToSTDERR => 'warning');
181 RT->Config->Set(LogToFile => 'warning');
182 RT->Config->Set(LogDir => $dir);
183 RT->Config->Set(LogToFileNamed => $file);
184 RT->Config->Set(LogStackTraces => 'error');
189 my $logger = $RT::Logger->output('file') || $RT::Logger->output("rtlog");
190 return $logger ? $logger->{filename} : undef;