1 package Packages::Page;
12 our @ISA = qw( Exporter );
13 our @EXPORT_OK = qw( split_name_mail parse_deps );
14 our %EXPORT_TAGS = ( all => [ @EXPORT_OK ] );
16 our $ARCHIVE_DEFAULT = '';
17 our $SECTION_DEFAULT = 'main';
18 our $SUBSECTION_DEFAULT = 'unknown';
19 our $PRIORITY_DEFAULT = 'unknown';
20 our $ESSENTIAL_DEFAULT = 'no';
21 our $MAINTAINER_DEFAULT = 'unknown <unknown@email.invalid>';
24 my $classname = shift;
25 my $name = shift || '';
26 my $config = shift || {};
29 bless( $self, $classname );
31 $self->{package} = $name;
32 $self->{config} = $config;
40 if ($string =~ /(.*?)\s*<(.*)>/o) {
43 } elsif ($string =~ /^[\w.-]*@[\w.-]*$/o) {
47 $name = gettext( 'package has bad maintainer field' );
51 return ($name, $email);
55 my ($self, $src, $data) = @_;
57 my %data = split /\00/o, $data;
59 $self->{src}{package} = $src;
60 $self->{src}{version} = $data{version};
62 my @files = split /\01/so, $data{files};
63 $self->{src}{files} = \@files;
65 $self->{src}{directory} = $data{directory};
67 if ($data{maintainer} ||= '') {
68 push @uploaders, [ split_name_mail( $data{maintainer} ) ];
70 if ($data{uploaders}) {
71 my @up_tmp = split( /\s*,\s*/,
73 foreach my $up (@up_tmp) {
74 if ($up ne $data{maintainer}) { # weed out duplicates
75 push @uploaders, [ split_name_mail( $up ) ];
79 $self->{src}{uploaders} = \@uploaders;
85 my ($self, $provided_by) = @_;
87 $self->{provided_by} ||= [];
88 push @{$self->{provided_by}}, @$provided_by;
94 return (exists($self->{provided_by}) && !exists($self->{versions}));
97 our @TAKE_NEWEST = qw( description description-md5 essential priority section subsection tag
98 archive source source-version url homepage );
99 our @STORE_ALL = qw( version source source-version installed-size size
100 filename md5sum sha1 sha256 task
101 origin bugs suite archive section );
102 our @DEP_FIELDS = qw( depends pre-depends recommends suggests enhances
103 provides conflicts );
105 my ($self, $data) = @_;
107 ($data->{package} && $data->{version} && $data->{architecture}) || return;
108 $self->{package} ||= $data->{package};
109 ($self->{package} eq $data->{package}) || return;
110 debug( "merge package $data->{package}/$data->{version}/$data->{architecture} into $self (".($self->{newest}||'').")", 2 ) if DEBUG;
112 (my $version = $data->{version}) =~ s/\+b\d+$//o; # strip binNMU number
113 unless ($self->{newest}) {
114 debug( "package $data->{package}/$data->{version}/$data->{architecture} is first to merge", 3 ) if DEBUG;
115 foreach my $key (@TAKE_NEWEST) {
116 $self->{data}{$key} = $data->{$key};
118 foreach my $key (@STORE_ALL) {
119 $self->{versions}{$data->{architecture}}{$key}
122 foreach my $key (@DEP_FIELDS) {
123 $self->normalize_dependencies($key, $data);
125 $self->{newest} = $version;
130 debug( "package $data->{package}/$data->{version}/$data->{architecture} is subsequent merge", 3 ) if DEBUG;
132 my $cmp = version_cmp( $version, $self->{newest} );
133 # packages from the central archive are preferred over all
134 # others with the same version number but from other archives
135 if ($is_newest = ($cmp > 0)
136 || (!$cmp && ($data->{archive} eq 'us') && ($self->{data}{archive} ne 'us'))) {
137 $self->{newest} = $version;
138 foreach my $key (@TAKE_NEWEST) {
139 $self->{data}{$key} = $data->{$key};
142 debug( "is_newest= ".($is_newest||0), 3 ) if DEBUG;
143 if (!$self->{versions}{$data->{architecture}}
145 || (version_cmp( $data->{version},
146 $self->{versions}{$data->{architecture}}{version} ) > 0)) {
147 foreach my $key (@STORE_ALL) {
148 $self->{versions}{$data->{architecture}}{$key}
151 foreach my $key (@DEP_FIELDS) {
152 $self->normalize_dependencies($key, $data);
159 sub normalize_dependencies {
160 my ($self, $dep_field, $data) = @_;
162 my ($deps_norm, $deps) = parse_deps( $data->{$dep_field}||'' );
163 $self->{dep_fields}{$data->{architecture}}{$dep_field} =
164 [ $deps_norm, $deps ];
170 my (@dep_and_norm, @dep_and);
171 foreach my $dep_and (split( /\s*,\s*/m, $dep_str )) {
172 next if $dep_and =~ /^\s*$/;
173 my (@dep_or_norm, @dep_or);
174 foreach my $dep_or (split( /\s*\|\s*/m, $dep_and )) {
175 my ($pkg, $relation, $version, @arches) = ('','','');
176 $pkg = $1 if $dep_or =~ s/^([a-zA-Z0-9][a-zA-Z0-9+._-]*)\s*//m;
177 ($relation, $version) = ($1, $2)
178 if $dep_or =~ s/^\(\s*(=|<=|>=|<<?|>>?)\s*([^\)]+).*\)\s*//m;
179 @arches = split(/\s+/m, $1) if $dep_or =~ s/^\[([^\]]+)\]\s*//m;
180 push @dep_or_norm, "$pkg($relation$version)[".
181 join(" ",sort(@arches))."]";
182 push @dep_or, [ $pkg, $relation, $version, \@arches ];
184 push @dep_and_norm, join('|',@dep_or_norm);
185 push @dep_and, \@dep_or;
187 return (\@dep_and_norm, \@dep_and);
191 my ($self, $field) = @_;
193 return $self->{data}{$field};
196 my ($self, $field) = @_;
198 return $self->{src}{$field};
201 sub get_architectures {
204 return keys %{$self->{versions}};
208 my ($self, $field) = @_;
211 foreach (sort keys %{$self->{versions}}) {
212 $result{$_} = $self->{versions}{$_}{$field}
213 if $self->{versions}{$_}{$field};
223 foreach (keys %{$self->{versions}}) {
224 my $version = $self->{versions}{$_}{version};
225 $versions{$version} ||= [];
226 push @{$versions{$version}}, $_;
232 sub get_version_string {
235 my $versions = $self->get_versions;
236 my @versions = version_sort keys %$versions;
237 my (@v_str, $v_str, $v_str_arch);
238 if ( scalar @versions == 1 ) {
239 @v_str = ( [ $versions[0], undef ] );
240 $v_str = $versions[0];
241 $v_str_arch = $versions[0];
244 foreach ( @versions ) {
245 push @v_str, [ $_, $versions->{$_} ];
246 push @v_str_arch, "$_ [".join(', ', sort @{$versions->{$_}})."]";
248 $v_str_arch = join( ", ", @v_str_arch );
249 $v_str = join( ", ", @versions );
252 return ($v_str, $v_str_arch, \@v_str);
256 my ($self, $dep_field) = @_;
258 my @architectures = $self->get_architectures;
260 my ( %dep_pkgs, %arch_deps );
261 foreach my $a ( @architectures ) {
262 next unless exists $self->{dep_fields}{$a}{$dep_field};
263 my ($a_deps_norm, $a_deps) = @{$self->{dep_fields}{$a}{$dep_field}};
264 # debug( "get_dep_field: $dep_field/$a: ".Dumper($a_deps_norm,$a_deps), 3 ) if DEBUG;
265 for ( my $i=0; $i < @$a_deps; $i++ ) { # splitted by ,
266 $dep_pkgs{$a_deps_norm->[$i]} = $a_deps->[$i];
267 $arch_deps{$a}{$a_deps_norm->[$i]}++;
270 @architectures = sort keys %arch_deps;
271 # debug( "get_dep_field called:\n ".Dumper( \%dep_pkgs, \%arch_deps ), 3 ) if DEBUG;
277 foreach my $dp ( sort keys %dep_pkgs ) {
278 my @dp_alts = @{$dep_pkgs{$dp}};
280 foreach (@dp_alts) { push @pkgs, $_->[0]; }
283 unless ( $is_old_pkgs = ($pkgs eq $old_pkgs) ) {
287 my ($arch_neg, $arch_str) = _compute_arch_str ( $dp, \%arch_deps,
290 my @res_pkgs; my $pkg_ix = 0;
291 foreach my $p_name ( @pkgs ) {
292 if ( $pkg_ix > 0 ) { $arch_str = ""; }
294 my $pkg_version = "";
295 $pkg_version = "$dep_pkgs{$dp}[$pkg_ix][1] $dep_pkgs{$dp}[$pkg_ix][2]"
296 if $dep_pkgs{$dp}[$pkg_ix][1];
299 push @res_pkgs, [ $p_name, $pkg_version, $arch_neg,
303 push @deps, [ $is_old_pkgs, @res_pkgs ];
309 sub _compute_arch_str {
310 my ( $dp, $arch_deps, $all_archs, $is_src_dep ) = @_;
312 my ( @dependend_archs, @not_dependend_archs );
314 foreach my $a ( @$all_archs ) {
315 if ( exists $arch_deps->{$a}{$dp} ) {
316 push @dependend_archs, $a;
318 push @not_dependend_archs, $a;
322 if ( @dependend_archs == @$all_archs ) {
325 if ( @dependend_archs > (@$all_archs/2) ) {
327 $arch_str = join( ", ", @not_dependend_archs);
329 $arch_str = join( ", ", @dependend_archs);
332 return my @ret = ( $arch_neg, $arch_str );