line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OTRS::OPM::Maker::Command::index; |
2
|
|
|
|
|
|
|
$OTRS::OPM::Maker::Command::index::VERSION = '0.18'; |
3
|
15
|
|
|
15
|
|
11957
|
use strict; |
|
15
|
|
|
|
|
35
|
|
|
15
|
|
|
|
|
553
|
|
4
|
15
|
|
|
15
|
|
96
|
use warnings; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
441
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Build index for an OPM repository |
7
|
|
|
|
|
|
|
|
8
|
15
|
|
|
15
|
|
85
|
use File::Basename; |
|
15
|
|
|
|
|
41
|
|
|
15
|
|
|
|
|
1123
|
|
9
|
15
|
|
|
15
|
|
2864
|
use File::Find::Rule; |
|
15
|
|
|
|
|
42489
|
|
|
15
|
|
|
|
|
133
|
|
10
|
15
|
|
|
15
|
|
4024
|
use MIME::Base64 (); |
|
15
|
|
|
|
|
3411
|
|
|
15
|
|
|
|
|
350
|
|
11
|
15
|
|
|
15
|
|
2475
|
use Sys::Hostname; |
|
15
|
|
|
|
|
5391
|
|
|
15
|
|
|
|
|
830
|
|
12
|
15
|
|
|
15
|
|
2453
|
use Path::Class (); |
|
15
|
|
|
|
|
155204
|
|
|
15
|
|
|
|
|
362
|
|
13
|
15
|
|
|
15
|
|
3727
|
use XML::LibXML; |
|
15
|
|
|
|
|
256193
|
|
|
15
|
|
|
|
|
110
|
|
14
|
15
|
|
|
15
|
|
11146
|
use XML::LibXML::PrettyPrint; |
|
15
|
|
|
|
|
119872
|
|
|
15
|
|
|
|
|
2716
|
|
15
|
|
|
|
|
|
|
|
16
|
15
|
|
|
15
|
|
3961
|
use OTRS::OPM::Maker -command; |
|
15
|
|
|
|
|
41
|
|
|
15
|
|
|
|
|
140
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub abstract { |
19
|
1
|
|
|
1
|
1
|
3828
|
return "build index for an OPM repository"; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub usage_desc { |
23
|
1
|
|
|
1
|
1
|
1044
|
return "opmbuild index "; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub validate_args { |
27
|
7
|
|
|
7
|
1
|
7741
|
my ($self, $opt, $args) = @_; |
28
|
|
|
|
|
|
|
|
29
|
7
|
100
|
100
|
|
|
106
|
$self->usage_error( 'need path to directory that contains opm files' ) if |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
30
|
|
|
|
|
|
|
!$args || |
31
|
|
|
|
|
|
|
'ARRAY' ne ref $args || |
32
|
|
|
|
|
|
|
!$args->[0] || |
33
|
|
|
|
|
|
|
!-d $args->[0]; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub execute { |
37
|
3
|
|
|
3
|
1
|
6346
|
my ($self, $opt, $args) = @_; |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
7
|
my $dir = $args->[0]; |
40
|
|
|
|
|
|
|
|
41
|
3
|
|
|
|
|
112
|
my @opm_files = File::Find::Rule->file->name( '*.opm' )->in( $dir ); |
42
|
|
|
|
|
|
|
|
43
|
3
|
|
|
|
|
3036
|
my @packages; |
44
|
3
|
|
|
|
|
40
|
my $pp = XML::LibXML::PrettyPrint->new( |
45
|
|
|
|
|
|
|
indent_string => ' ', |
46
|
|
|
|
|
|
|
element => { |
47
|
|
|
|
|
|
|
compact => [qw( |
48
|
|
|
|
|
|
|
Vendor Name Description Version Framework |
49
|
|
|
|
|
|
|
ModuleRequired PackageRequired URL License |
50
|
|
|
|
|
|
|
File |
51
|
|
|
|
|
|
|
)], |
52
|
|
|
|
|
|
|
}, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
3
|
|
|
|
|
125
|
for my $opm_file ( sort @opm_files ) { |
56
|
3
|
|
|
|
|
68
|
my $parser = XML::LibXML->new; |
57
|
3
|
|
|
|
|
1120
|
my $tree = $parser->parse_file( $opm_file ); |
58
|
|
|
|
|
|
|
|
59
|
3
|
|
|
|
|
1500
|
$tree->setStandalone( 0 ); |
60
|
|
|
|
|
|
|
|
61
|
3
|
|
|
|
|
16
|
my $root_elem = $tree->getDocumentElement; |
62
|
3
|
|
|
|
|
32
|
$root_elem->setNodeName( 'Package' ); |
63
|
3
|
|
|
|
|
19
|
$root_elem->removeAttribute( 'version' ); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# retrieve file information |
66
|
3
|
|
|
|
|
14
|
my @files = $root_elem->findnodes( 'Filelist/File' ); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
FILE: |
69
|
3
|
|
|
|
|
159
|
for my $file ( @files ) { |
70
|
6
|
|
|
|
|
42
|
my $location = $file->findvalue( '@Location' ); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# keep only documentation in file list |
73
|
6
|
100
|
|
|
|
586
|
if ( $location !~ m{\A doc/}x ) { |
74
|
4
|
|
|
|
|
40
|
$file->parentNode->removeChild( $file ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
else { |
77
|
2
|
|
|
|
|
14
|
my @child_nodes = $file->childNodes; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# clean nodes |
80
|
2
|
|
|
|
|
52
|
$file->removeChild( $_ ) for @child_nodes; |
81
|
2
|
|
|
|
|
11
|
$file->removeAttribute( 'Encode' ); |
82
|
2
|
|
|
|
|
11
|
$file->setNodeName( 'FileDoc' ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# remove unnecessary nodes |
87
|
3
|
|
|
|
|
158
|
for my $node_name ( qw(Code Intro Database)) { |
88
|
9
|
|
|
|
|
16
|
for my $phase ( qw(Install Upgrade Reinstall Uninstall) ) { |
89
|
36
|
|
|
|
|
187
|
my @nodes = $root_elem->findnodes( $node_name . $phase ); |
90
|
36
|
|
|
|
|
905
|
$_->parentNode->removeChild( $_ ) for @nodes; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
3
|
|
|
|
|
5
|
for my $node_name ( qw(BuildHost BuildDate)) { |
95
|
6
|
|
|
|
|
93
|
my @nodes = $root_elem->findnodes( $node_name ); |
96
|
6
|
|
|
|
|
166
|
$_->parentNode->removeChild( $_ ) for @nodes; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
3
|
|
|
|
|
85
|
my $file_node = XML::LibXML::Element->new( 'File' ); |
100
|
3
|
|
|
|
|
7
|
my $file_path = $opm_file; |
101
|
|
|
|
|
|
|
|
102
|
3
|
100
|
|
|
|
31
|
$file_path =~ s/\Q$dir// if $dir ne '.'; |
103
|
3
|
100
|
|
|
|
14
|
$file_path = '/' . $file_path if '/' ne substr $file_path, 0, 1; |
104
|
|
|
|
|
|
|
|
105
|
3
|
|
|
|
|
15
|
$file_node->appendText( $file_path ); |
106
|
3
|
|
|
|
|
21
|
$root_elem->addChild( $file_node ); |
107
|
|
|
|
|
|
|
|
108
|
3
|
|
|
|
|
8
|
$pp->pretty_print( $tree ); |
109
|
|
|
|
|
|
|
|
110
|
3
|
|
|
|
|
19968
|
my $xml = $tree->toString; |
111
|
3
|
|
|
|
|
159
|
$xml =~ s{<\?xml .*? \?> \s+}{}x; |
112
|
|
|
|
|
|
|
|
113
|
3
|
|
|
|
|
14
|
push @packages, $xml; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
3
|
|
|
|
|
281
|
print sprintf qq~ |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
%s |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
~, join "", @packages; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |