| 6 |
use Packages::Pkg; |
use Packages::Pkg; |
| 7 |
use Deb::Versions; |
use Deb::Versions; |
| 8 |
|
|
| 9 |
|
sub dep_item { |
| 10 |
|
my ( $link, $name, $info, $desc ) = @_; |
| 11 |
|
my $post_link = ''; |
| 12 |
|
if ($link) { |
| 13 |
|
$link = "<a href=\"$link\">"; |
| 14 |
|
$post_link = '</a>'; |
| 15 |
|
} else { |
| 16 |
|
$link = ''; |
| 17 |
|
} |
| 18 |
|
if ($info) { |
| 19 |
|
$info = " $info"; |
| 20 |
|
} else { |
| 21 |
|
$info = ''; |
| 22 |
|
} |
| 23 |
|
if ($desc) { |
| 24 |
|
$desc = "<br>$desc"; |
| 25 |
|
} else { |
| 26 |
|
$desc = ''; |
| 27 |
|
} |
| 28 |
|
|
| 29 |
|
return "$link$name$post_link$info$desc"; |
| 30 |
|
} |
| 31 |
|
|
| 32 |
sub print_deps { |
sub print_deps { |
| 33 |
my ( $env, $pkg, $versions, $type) = @_; |
my ( $env, $lang, $pkg, $relations, $type) = @_; |
| 34 |
my %dep_type = ('depends' => 'dep', 'recommends' => 'rec', |
my %dep_type = ('depends' => 'dep', 'recommends' => 'rec', |
| 35 |
'suggests' => 'sug'); |
'suggests' => 'sug'); |
| 36 |
my $res = "<ul class=\"ul$dep_type{$type}\">\n"; |
my $res = "<ul class=\"ul$dep_type{$type}\">\n"; |
|
my $found = 0; |
|
|
my @all_archs = ( @{$env->{archs}}, 'all' ); |
|
|
my ( %dep_pkgs, %arch_deps ); |
|
|
foreach my $a ( @all_archs ) { |
|
|
next unless ( exists $versions->{a2v}->{$a} |
|
|
&& exists $pkg->{versions}->{$versions->{a2v}->{$a}}->{$a}->{$type} ); |
|
|
my @a_deps = @{$pkg->{versions}->{$versions->{a2v}->{$a}}->{$a}->{$type}}; |
|
|
foreach my $d ( @a_deps ) { |
|
|
my ( @dep_str, $dep_str ); |
|
|
foreach ( @$d ) { |
|
|
$_->[1] ||= ""; $_->[2] ||= ""; |
|
|
push @dep_str, "$_->[0]($_->[1]$_->[2])"; |
|
|
} |
|
|
$dep_str = join( "|", @dep_str ); |
|
|
$dep_pkgs{$dep_str}++; |
|
|
$arch_deps{$a}->{$dep_str} = $d; |
|
|
} |
|
|
} |
|
|
@all_archs = sort keys %arch_deps; |
|
|
# print Dumper( \%dep_pkgs, \%arch_deps ); |
|
|
|
|
|
if ( %dep_pkgs ) { |
|
|
$found = 1; |
|
|
# $res .= "<h4>$type</h4>\n"; |
|
| 37 |
my $first = 1; |
my $first = 1; |
|
my $old_dp = ""; |
|
|
my $is_old_dp = 0; |
|
|
foreach my $dp ( sort keys %dep_pkgs ) { |
|
|
my $dp_v = $dp; |
|
|
$dp_v =~ s/\(.*?\)//g; |
|
|
my @pkgs = split /\|/, $dp; |
|
| 38 |
|
|
| 39 |
if ( $dp_v eq $old_dp ) { |
# use Data::Dumper; |
| 40 |
|
# warn Dumper( \$lang, $pkg->get_name, \$type, $relations ); |
| 41 |
|
|
| 42 |
|
foreach my $rel (@$relations) { |
| 43 |
|
my $is_old_pkgs = $rel->[0]; |
| 44 |
|
my @res_pkgs = (); |
| 45 |
|
|
| 46 |
|
if ($is_old_pkgs) { |
| 47 |
$res .= "<br>"; |
$res .= "<br>"; |
|
$is_old_dp = 1; |
|
|
foreach ( @pkgs ) { |
|
|
s/\(.*\)$//o; |
|
|
} |
|
| 48 |
} else { |
} else { |
|
$old_dp = $dp_v; |
|
|
$is_old_dp = 0; |
|
| 49 |
if ($first) { |
if ($first) { |
| 50 |
$res .= "<li>"; |
$res .= "<li>"; |
| 51 |
$first = 0; |
$first = 0; |
| 55 |
$res .= "<span class=\"hidecss\">[$dep_type{$type}] </span>"; |
$res .= "<span class=\"hidecss\">[$dep_type{$type}] </span>"; |
| 56 |
} |
} |
| 57 |
|
|
| 58 |
my $arch_str = compute_arch_str ( $dp, $versions, \%arch_deps, |
foreach my $rel_alt ( @$rel ) { |
| 59 |
\@all_archs ); |
next unless ref($rel_alt); |
| 60 |
|
my ( $p_name, $pkg_version, $arch_neg, |
| 61 |
my @res_pkgs; my $pkg_ix = 0; |
$arch_str, $subsection, $available ) = @$rel_alt; |
|
foreach my $p_name ( @pkgs ) { |
|
|
# warn "before: $p_name\n"; |
|
|
$p_name =~ s/\(.*\)$//o; |
|
|
# warn "after: $p_name\n"; |
|
|
|
|
|
if ( $pkg_ix > 0 ) { $arch_str = ""; } |
|
| 62 |
|
|
| 63 |
my $p = $env->{db}->get_pkg( $p_name ); |
if ($arch_str) { |
| 64 |
|
if ($arch_neg) { |
| 65 |
my $pkg_version = ""; |
$arch_str = " [".gettext("not")." $arch_str]"; |
| 66 |
foreach my $a ( @all_archs ) { |
} else { |
| 67 |
if ( exists( $arch_deps{$a}->{$dp} ) |
$arch_str = " [$arch_str]"; |
|
&& $arch_deps{$a}->{$dp}->[$pkg_ix]->[1] ) { |
|
|
$pkg_version = "(".encode_entities( $arch_deps{$a}->{$dp}->[$pkg_ix]->[1] ). |
|
|
" $arch_deps{$a}->{$dp}->[$pkg_ix]->[2])"; |
|
|
last; |
|
| 68 |
} |
} |
| 69 |
} |
} |
| 70 |
|
$pkg_version = "($pkg_version)" if $pkg_version; |
| 71 |
|
|
| 72 |
|
my $p = $env->{db}->get_pkg( $p_name ); |
| 73 |
if ( $p ) { |
if ( $p ) { |
| 74 |
if ( $is_old_dp ) { |
if ( $is_old_pkgs ) { |
| 75 |
my $section; |
push @res_pkgs, dep_item( "../$subsection/$p_name", $p_name, "$pkg_version$arch_str" ); |
| 76 |
if ($p->is_virtual) { |
} elsif ( $subsection eq 'virtual' ) { |
|
$section = "virtual"; |
|
|
} else { |
|
|
my %sections = $p->get_arch_fields( 'section', |
|
|
$env->{archs} ); |
|
|
$section = $sections{max_unique} or warn "W: no section found for package ".$p->get_name()."\n"; |
|
|
} |
|
|
#DEBUG |
|
|
unless(defined($section)&& defined($p_name)&& defined($pkg_version) && defined($arch_str)) { |
|
|
print STDERR "E: $section&&$p_name&&$pkg_version&&$arch_str&&".$pkg->get_name()."\n"; |
|
|
} |
|
|
push @res_pkgs, "<a href=\"../$section/$p_name\">$p_name</a> $pkg_version$arch_str"; |
|
|
} elsif ( $p->is_virtual ) { |
|
| 77 |
my $short_desc = gettext( "Virtual package" ); |
my $short_desc = gettext( "Virtual package" ); |
| 78 |
push @res_pkgs, "<a href=\"../virtual/$p_name\">$p_name</a> $pkg_version$arch_str<br>\n $short_desc"; |
push @res_pkgs, dep_item( "../virtual/$p_name", $p_name, "$pkg_version$arch_str", $short_desc ); |
| 79 |
} else { |
} else { |
|
my %sections = $p->get_arch_fields( 'section', |
|
|
$env->{archs} ); |
|
|
my $section = $sections{max_unique}; |
|
| 80 |
my %desc_md5s = $p->get_arch_fields( 'description-md5', |
my %desc_md5s = $p->get_arch_fields( 'description-md5', |
| 81 |
$env->{archs} ); |
$env->{archs} ); |
| 82 |
my $short_desc = conv_desc( $env->{lang}, encode_entities( $env->{db}->get_short_desc( $desc_md5s{max_unique}, $env->{lang} ), "<>&\"" ) ); |
my $short_desc = conv_desc( $env->{lang}, encode_entities( $env->{db}->get_short_desc( $desc_md5s{max_unique}, $lang ), "<>&\"" ) ); |
| 83 |
push @res_pkgs, "<a href=\"../$section/$p_name\">$p_name</a> $pkg_version$arch_str<br>\n $short_desc"; |
push @res_pkgs, dep_item( "../$subsection/$p_name", $p_name, "$pkg_version$arch_str", $short_desc ); |
| 84 |
} |
} |
| 85 |
} elsif ( $is_old_dp ) { |
} elsif ( $is_old_pkgs ) { |
| 86 |
push @res_pkgs, "$p_name $pkg_version$arch_str"; |
push @res_pkgs, dep_item( undef, $p_name, "$pkg_version$arch_str" ); |
| 87 |
} else { |
} else { |
| 88 |
my $short_desc = gettext( "Package not available" ); |
my $short_desc = gettext( "Package not available" ); |
| 89 |
push @res_pkgs, "$p_name $pkg_version$arch_str<br>\n $short_desc"; |
push @res_pkgs, dep_item( undef, $p_name, "$pkg_version$arch_str", $short_desc ); |
| 90 |
} |
} |
| 91 |
$pkg_ix++; |
|
|
# warn "$short_desc\n"; |
|
| 92 |
} |
} |
| 93 |
|
|
| 94 |
$res .= "\n".join( "<br> ".gettext( " or " )." ", @res_pkgs )."\n"; |
$res .= "\n".join( "<br> ".gettext( " or " )." ", @res_pkgs )."\n"; |
| 95 |
$res .= "\n"; |
$res .= "\n"; |
|
|
|
|
} |
|
| 96 |
$res .= "</li>\n"; |
$res .= "</li>\n"; |
| 97 |
} |
} |
| 98 |
if ($found) { |
if (@$relations) { |
| 99 |
$res .= "</ul>\n"; |
$res .= "</ul>\n"; |
| 100 |
} else { |
} else { |
| 101 |
$res = ""; |
$res = ""; |
| 104 |
} |
} |
| 105 |
|
|
| 106 |
sub print_src_deps { |
sub print_src_deps { |
| 107 |
my ( $env, $pkg, $version, $type) = @_; |
my ( $env, $lang, $pkg, $version, $type) = @_; |
| 108 |
my %dep_type = ('build-depends' => 'adep', 'build-depends-indep' => 'idep' ); |
my %dep_type = ('build-depends' => 'adep', 'build-depends-indep' => 'idep' ); |
| 109 |
my $found = 0; |
my $found = 0; |
| 110 |
my $res = "<ul class=\"ul$dep_type{$type}\">\n"; |
my $res = "<ul class=\"ul$dep_type{$type}\">\n"; |
| 129 |
if ( $p ) { |
if ( $p ) { |
| 130 |
if ( $p->is_virtual ) { |
if ( $p->is_virtual ) { |
| 131 |
my $short_desc = gettext( "Virtual package" ); |
my $short_desc = gettext( "Virtual package" ); |
| 132 |
push @res_pkgs, "<a href=\"../virtual/$p_name\">$p_name</a> $p_version$arch_str<br>\n $short_desc"; |
push @res_pkgs, dep_item( "../virtual/$p_name", $p_name, "$p_version$arch_str", $short_desc ); |
| 133 |
} else { |
} else { |
| 134 |
my %sections = $p->get_arch_fields( 'section', |
my %sections = $p->get_arch_fields( 'section', |
| 135 |
$env->{archs} ); |
$env->{archs} ); |
| 136 |
my $section = $sections{max_unique}; |
my $section = $sections{max_unique}; |
| 137 |
my %desc_md5s = $p->get_arch_fields( 'description-md5', |
my %desc_md5s = $p->get_arch_fields( 'description-md5', |
| 138 |
$env->{archs} ); |
$env->{archs} ); |
| 139 |
my $short_desc = conv_desc( $env->{lang}, encode_entities( $env->{db}->get_short_desc( $desc_md5s{max_unique}, $env->{lang} ), "<>&\"" ) ); |
my $short_desc = conv_desc( $lang, encode_entities( $env->{db}->get_short_desc( $desc_md5s{max_unique}, $lang ), "<>&\"" ) ); |
| 140 |
push @res_pkgs, "<a href=\"../$section/$p_name\">$p_name</a> $p_version$arch_str<br>\n $short_desc"; |
push @res_pkgs, dep_item( "../$section/$p_name", $p_name, "$p_version$arch_str", $short_desc ); |
| 141 |
} |
} |
| 142 |
} else { |
} else { |
| 143 |
my $short_desc = gettext( "Package not available" ); |
my $short_desc = gettext( "Package not available" ); |
| 144 |
push @res_pkgs, "$p_name $p_version$arch_str<br>\n $short_desc"; |
push @res_pkgs, dep_item( undef, $p_name, "$p_version$arch_str", $short_desc ); |
| 145 |
} |
} |
| 146 |
} |
} |
| 147 |
$res .= "\n".join( "\n ".gettext( " or " )." ", @res_pkgs )."</li>\n"; |
$res .= "\n".join( "<br>\n".gettext( " or " )." ", @res_pkgs )."</li>\n"; |
| 148 |
} |
} |
| 149 |
if ($found) { |
if ($found) { |
| 150 |
$res .= "\n</ul>"; |
$res .= "\n</ul>"; |
| 155 |
} |
} |
| 156 |
|
|
| 157 |
sub print_deps_ds { |
sub print_deps_ds { |
| 158 |
my ( $env, $pkg, $versions, $type) = @_; |
my ( $env, $pkg, $relations, $type) = @_; |
| 159 |
my $res = ""; |
my $res = ""; |
| 160 |
my @all_archs = ( @{$env->{archs}}, 'all' ); |
|
| 161 |
my ( %dep_pkgs, %arch_deps ); |
use Data::Dumper; |
| 162 |
foreach my $a ( @all_archs ) { |
# warn Dumper( $type, $relations ); |
|
next unless ( exists $versions->{a2v}{$a} |
|
|
&& exists $pkg->{versions}{$versions->{a2v}{$a}}{$a}{lc $type} ); |
|
|
my @a_deps = @{$pkg->{versions}{$versions->{a2v}{$a}}{$a}{lc $type}}; |
|
|
foreach my $d ( @a_deps ) { |
|
|
my ( @dep_str, $dep_str ); |
|
|
foreach ( @$d ) { |
|
|
$_->[1] ||= ""; $_->[2] ||= ""; |
|
|
push @dep_str, "$_->[0]($_->[1]$_->[2])"; |
|
|
} |
|
|
$dep_str = join( "|", @dep_str ); |
|
|
$dep_pkgs{$dep_str}++; |
|
|
$arch_deps{$a}->{$dep_str} = $d; |
|
|
} |
|
|
} |
|
|
@all_archs = sort keys %arch_deps; |
|
|
# print Dumper( \%dep_pkgs, \%arch_deps ); |
|
| 163 |
|
|
| 164 |
my @res; |
my @res; |
| 165 |
if ( %dep_pkgs ) { |
foreach my $rel (@$relations) { |
| 166 |
foreach my $dp ( sort keys %dep_pkgs ) { |
my @res_pkgs = (); |
| 167 |
my $dp_v = $dp; |
foreach my $rel_alt ( @$rel ) { |
| 168 |
$dp_v =~ s/\(.*?\)//g; |
next unless ref($rel_alt); |
| 169 |
my @pkgs = split /\|/, $dp; |
my ( $p_name, $pkg_version, $arch_neg, |
| 170 |
|
$arch_str, $subsection, $available ) = @$rel_alt; |
| 171 |
my $arch_str = compute_arch_str ( $dp, $versions, \%arch_deps, |
|
| 172 |
\@all_archs ); |
if ($arch_str) { |
| 173 |
|
if ($arch_neg) { |
| 174 |
my @res_pkgs; my $pkg_ix = 0; |
$arch_str = " [".gettext("not")." $arch_str]"; |
| 175 |
foreach my $p_name ( @pkgs ) { |
} else { |
| 176 |
$p_name =~ s/\(.*\)$//o; |
$arch_str = " [$arch_str]"; |
|
|
|
|
if ( $pkg_ix > 0 ) { $arch_str = ""; } |
|
|
|
|
|
my $pkg_version = ""; |
|
|
foreach my $a ( @all_archs ) { |
|
|
if ( exists( $arch_deps{$a}->{$dp} ) |
|
|
&& $arch_deps{$a}->{$dp}->[$pkg_ix]->[1] ) { |
|
|
$pkg_version = "(".encode_entities( $arch_deps{$a}->{$dp}->[$pkg_ix]->[1] ). |
|
|
" $arch_deps{$a}->{$dp}->[$pkg_ix]->[2])"; |
|
|
last; |
|
| 177 |
} |
} |
| 178 |
} |
} |
| 179 |
|
$pkg_version = "($pkg_version)" if $pkg_version; |
| 180 |
|
|
| 181 |
push @res_pkgs, compute_link( $env, $p_name ) |
if ($available) { |
| 182 |
." $pkg_version$arch_str"; |
push @res_pkgs, dep_item( "../$subsection/$p_name", |
| 183 |
$pkg_ix++; |
$p_name, "$pkg_version$arch_str" ); |
| 184 |
|
} else { |
| 185 |
|
push @res_pkgs, dep_item( undef, |
| 186 |
|
$p_name, "$pkg_version$arch_str" ); |
| 187 |
} |
} |
| 188 |
push @res, join( gettext( " or " ), @res_pkgs ); |
|
| 189 |
} |
} |
| 190 |
|
push @res, join( gettext( " or " ), @res_pkgs ); |
| 191 |
} |
} |
| 192 |
|
|
| 193 |
if (@res) { |
if (@res) { |
| 194 |
$res .= "<ul>\n"; |
$res .= ds_item($type, join( ", ", @res)); |
|
$res = "<li>$type: ".join( ", ", @res)."</li>\n"; |
|
|
$res .= "</ul>\n"; |
|
| 195 |
} |
} |
| 196 |
return $res; |
return $res; |
| 197 |
} |
} |
| 198 |
|
|
| 199 |
|
#FIXME |
| 200 |
sub print_reverse_rel_ds { |
sub print_reverse_rel_ds { |
| 201 |
my ( $env, $pkg, $versions, $type, $is_src_dep) = @_; |
my ( $env, $pkg, $versions, $type, $is_src_dep) = @_; |
| 202 |
my $res = ""; |
my $res = ""; |
| 248 |
return $res; |
return $res; |
| 249 |
} |
} |
| 250 |
|
|
|
sub compute_arch_str { |
|
|
my ( $dp, $versions, $arch_deps, $all_archs, $is_src_dep ) = @_; |
|
|
|
|
|
if ($is_src_dep) { |
|
|
return compute_src_arch_str( @_ ); |
|
|
} |
|
|
|
|
|
my ( @dependend_archs, @not_dependend_archs ); |
|
|
my $arch_str; |
|
|
foreach my $a ( @$all_archs ) { |
|
|
if ( exists( $versions->{a2v}{$a} ) |
|
|
&& exists( $arch_deps->{$a} ) ) { |
|
|
if ( exists $arch_deps->{$a}{$dp} ) { |
|
|
push @dependend_archs, $a; |
|
|
} else { |
|
|
push @not_dependend_archs, $a; |
|
|
} |
|
|
} |
|
|
} |
|
|
if ( @dependend_archs == @$all_archs ) { |
|
|
$arch_str = ""; |
|
|
} else { |
|
|
if ( @dependend_archs > (@$all_archs/2) ) { |
|
|
$arch_str = " [".gettext( "not" )." ".join( ", ", @not_dependend_archs)."]"; |
|
|
} else { |
|
|
$arch_str = " [".join( ", ", @dependend_archs)."]"; |
|
|
} |
|
|
} |
|
|
return $arch_str; |
|
|
} |
|
| 251 |
|
|
| 252 |
sub compute_src_arch_str { |
sub compute_src_arch_str { |
| 253 |
my ( $dp, $versions, $arch_deps, $all_archs ) = @_; |
my ( $dp, $versions, $arch_deps, $all_archs ) = @_; |
| 294 |
return $arch_str; |
return $arch_str; |
| 295 |
} |
} |
| 296 |
|
|
|
|
|
|
sub compute_link { |
|
|
my ( $env, $p_name ) = @_; |
|
|
|
|
|
my $p = $env->{db}->get_pkg( $p_name ); |
|
|
if ($p) { |
|
|
my $section; |
|
|
if ($p->is_virtual) { |
|
|
$section = "virtual"; |
|
|
} else { |
|
|
my %sections = $p->get_arch_fields( 'section', |
|
|
$env->{archs} ); |
|
|
$section = $sections{max_unique} |
|
|
or warn "W: no section found for package ". |
|
|
$p_name."\n"; |
|
|
} |
|
|
$p_name = "<a href=\"../$section/$p_name\">$p_name</a>"; |
|
|
} |
|
|
|
|
|
return $p_name; |
|
|
} |
|
|
|
|
| 297 |
1; |
1; |