line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tapper::CLI::API::Command::download; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TAPPER'; |
3
|
|
|
|
|
|
|
$Tapper::CLI::API::Command::download::VERSION = '5.0.6'; |
4
|
1
|
|
|
1
|
|
1417
|
use 5.010; |
|
1
|
|
|
|
|
4
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use parent 'App::Cmd::Command'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
2373
|
use IO::Socket; |
|
1
|
|
|
|
|
12955
|
|
|
1
|
|
|
|
|
5
|
|
12
|
1
|
|
|
1
|
|
469
|
use Tapper::Config; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
13
|
1
|
|
|
1
|
|
6
|
use File::Slurp 'slurp'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
14
|
1
|
|
|
1
|
|
7
|
use Data::Dumper; |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
54
|
|
15
|
1
|
|
|
1
|
|
556
|
use Moose; |
|
1
|
|
|
|
|
439989
|
|
|
1
|
|
|
|
|
7
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub abstract { |
18
|
0
|
|
|
0
|
1
|
|
'Download a file from a report' |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub opt_spec { |
22
|
|
|
|
|
|
|
return ( |
23
|
0
|
|
|
0
|
1
|
|
[ "verbose", "some more informational output" ], |
24
|
|
|
|
|
|
|
[ "reportid=s", "INT; the testrun id where the file is attached" ], |
25
|
|
|
|
|
|
|
[ "file=s", "STRING; the filename to download" ], |
26
|
|
|
|
|
|
|
[ "nth=s", "INT; the n-th file if there is more than one with same name; default 0" ], |
27
|
|
|
|
|
|
|
[ "saveas=s", "STRING; where to write result; default print to STDOUT" ], |
28
|
|
|
|
|
|
|
[ "reportserver=s", "STRING; use this host for upload" ], |
29
|
|
|
|
|
|
|
[ "reportport=s", "STRING; use this port for upload" ], |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub usage_desc |
34
|
|
|
|
|
|
|
{ |
35
|
0
|
|
|
0
|
1
|
|
my $allowed_opts = join ' ', map { '--'.$_ } _allowed_opts(); |
|
0
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
"tapper-api dowload --reportid=s --file=s [ --saveas=s ] [ --nth=s ]"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _allowed_opts |
40
|
|
|
|
|
|
|
{ |
41
|
0
|
|
|
0
|
|
|
my @allowed_opts = map { $_->[0] } opt_spec(); |
|
0
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub validate_args |
45
|
|
|
|
|
|
|
{ |
46
|
0
|
|
|
0
|
1
|
|
my ($self, $opt, $args) = @_; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# -- file constraints -- |
49
|
0
|
|
|
|
|
|
my $file = $opt->{file}; |
50
|
0
|
0
|
|
|
|
|
say "Missing argument --file" unless $file; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# -- report constraints -- |
53
|
0
|
|
|
|
|
|
my $reportid = $opt->{reportid}; |
54
|
0
|
|
0
|
|
|
|
my $report_ok = $reportid && $reportid =~ /^\d+$/; |
55
|
0
|
0
|
|
|
|
|
say "Missing argument --reportid" unless $reportid; |
56
|
0
|
0
|
0
|
|
|
|
say "Error: Strange target report (id '".($reportid//"")."')." unless $report_ok; |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
0
|
|
|
|
return 1 if $opt->{reportid} && $report_ok; |
59
|
0
|
|
|
|
|
|
die $self->usage->text; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub execute |
63
|
|
|
|
|
|
|
{ |
64
|
0
|
|
|
0
|
1
|
|
my ($self, $opt, $args) = @_; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$self->download ($opt, $args); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub download |
70
|
|
|
|
|
|
|
{ |
71
|
0
|
|
|
0
|
0
|
|
my ($self, $opt, $args) = @_; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
0
|
|
|
|
my $host = $opt->{reportserver} || Tapper::Config->subconfig->{report_server}; |
74
|
0
|
|
0
|
|
|
|
my $port = $opt->{reportport} || Tapper::Config->subconfig->{report_api_port}; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $reportid = $opt->{reportid}; |
77
|
0
|
|
|
|
|
|
my $file = $opt->{file}; |
78
|
0
|
|
|
|
|
|
my $saveas = $opt->{saveas}; |
79
|
0
|
|
0
|
|
|
|
my $nth = $opt->{nth} || 0; |
80
|
0
|
|
|
|
|
|
my $content; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $cmdline = "#! download $reportid $file $nth\n"; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $REMOTEAPI = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port); |
85
|
0
|
0
|
|
|
|
|
if ($REMOTEAPI) { |
86
|
0
|
|
|
|
|
|
print $REMOTEAPI $cmdline; |
87
|
|
|
|
|
|
|
{ |
88
|
0
|
|
|
|
|
|
local $/; |
|
0
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
$content = <$REMOTEAPI>; |
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
|
close ($REMOTEAPI); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# write to file or STDOUT |
94
|
0
|
0
|
|
|
|
|
if ($saveas) { |
95
|
0
|
0
|
|
|
|
|
open my $SAVEAS, ">", $saveas or die "Can not write to file '$saveas'"; |
96
|
0
|
|
|
|
|
|
print $SAVEAS $content; |
97
|
0
|
|
|
|
|
|
close $SAVEAS; |
98
|
|
|
|
|
|
|
} else { |
99
|
0
|
|
|
|
|
|
print $content; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
else { |
103
|
0
|
|
|
|
|
|
say "Cannot open remote receiver $host:$port."; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
# perl -Ilib bin/tapper-api download --reportid=552 --file ~/xyz --saveas=/tmp/myxyz |
108
|
|
|
|
|
|
|
# perl -Ilib bin/tapper-api download --reportid=552 --file ~/xyz --nth=1 --saveas=/tmp/myxyz |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=pod |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=encoding UTF-8 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 NAME |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Tapper::CLI::API::Command::download |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 AUTHOR |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
AMD OSRC Tapper Team <tapper@amd64.org> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This software is Copyright (c) 2020 by Advanced Micro Devices, Inc.. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This is free software, licensed under: |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
The (two-clause) FreeBSD License |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |