]> git.donarmstrong.com Git - wannabuild.git/blob - lib/WB/QD.pm
add state auto-not-for-us:
[wannabuild.git] / lib / WB / QD.pm
1 package WB::QD;
2
3 use strict;
4 use IO::Uncompress::AnyInflate qw(anyinflate);
5 use Dpkg::Version qw(vercmp);
6 use Dpkg::Arch qw(debarch_is);
7 use Data::Dumper;
8
9 sub readsourcebins {
10     my $arch = shift;
11     my $pasfile = shift;
12     my $SRC = shift;
13     my $BIN = shift;
14     my $binary = {};
15
16     my $pas = {};
17     local($/) = "\n";
18     open(PAS, '<', $pasfile);
19     while(<PAS>) {
20         chomp;
21         s,\s*#.*,,;
22         next unless $_;
23         my ($p, $c) = split(/:\s*/);
24         $pas->{$p} = { arch => [ split(/\s+/, $c) ], mode => substr($c, 0, 1) ne '!' };
25     }
26     close PAS;
27
28     my $srcs = {};
29     local($/) = ""; # read in paragraph mode
30
31     foreach my $s (@$SRC) {
32         my $S = new IO::Uncompress::AnyInflate($s) || return "WB::QD::SRC can't open $s";
33         while(<$S>) {
34             my $p={};
35             /^Package:\s*(\S+)$/mi and $p->{'name'} = $1;
36             /^Version:\s*(\S+)$/mi and $p->{'version'} = $1;
37             /^Binary:\s*(.*)$/mi and $p->{'binary'} = $1;
38             /^Architecture:\s*(.+)$/mi and $p->{'arch'} = $1;
39             /^Priority:\s*(\S+)$/mi and $p->{'priority'} = $1;
40             /^Section:\s*(\S+)$/mi and $p->{'section'} = $1;
41             /^Build-Depends:\s*(.*)$/mi and $p->{'depends'} = $1;
42             /^Build-Conflicts:\s*(.*)$/mi and $p->{'conflicts'} = $1;
43
44             next unless $p->{'name'} and $p->{'version'};
45             next if $p->{'arch'} eq 'all';
46             foreach my $tarch (split(/\s+/, $p->{'arch'})) {
47                 $p->{'for-us'} = 1 if debarch_is($arch, $tarch);
48             }
49             delete $p->{'arch'};
50
51             # ignore if package already exists with higher version
52             if ($srcs->{$p->{'name'}}) {
53                 next if (vercmp($srcs->{$p->{'name'}}->{'version'}, $p->{'version'}) > 0);
54             }
55             my @a = split(/,? /, $p->{'binary'}) if $p->{'binary'};
56             $p->{'binary'} = \@a;
57             $srcs->{$p->{'name'}} = $p;
58         }
59         close $S;
60     }
61
62     foreach my $p (@$BIN) {
63         my $P = new IO::Uncompress::AnyInflate($p) || return "WB::QD::PKGS can't open $p";
64         while(<$P>) {
65             my $p;
66             /^Version:\s*(\S+)$/mi and $p->{'version'} = $1;
67             /^Version:\s*(\S+)\+b([0-9]+)$/mi and $p->{'version'} = $1 and $p->{'binnmu'} = $2;
68             /^Architecture:\s*(\S+)$/mi and $p->{'arch'} = $1;
69             /^Package:\s*(\S+)$/mi and $p->{'binary'} = $1;
70             /^Package:\s*(\S+)$/mi and $p->{'source'} = $1;
71             /^Source:\s*(\S+)$/mi and $p->{'source'} = $1;
72             /^Source:\s*(\S+)\s+\((\S+)\)$/mi and $p->{'source'} = $1 and $p->{'version'} = $2;
73
74             next unless $p->{'arch'} eq 'all' || $p->{'arch'} eq ${arch};
75             $binary->{$p->{'binary'}} = { 'version' => $p->{'version'}, 'arch' => $p->{'arch'}} unless $binary->{$p->{'binary'}} and vercmp($binary->{$p->{'binary'}}->{'version'}, $p->{'version'}) < 0;
76
77             #next if $pas->{$p->{'binary'}} && pasignore($pas->{$p->{'binary'}}, $arch);
78             next if $p->{'arch'} eq 'all';
79             next unless $srcs->{$p->{'source'}};
80             $srcs->{$p->{'source'}}->{'compiled'} = 1;
81             next unless $srcs->{$p->{'source'}}->{'version'} eq $p->{'version'};
82             $srcs->{$p->{'source'}}->{'installed'} = 1;
83             next unless $p->{'binnmu'};
84             next if ($srcs->{$p->{'source'}}->{'binnmu'}) && ($srcs->{$p->{'source'}}->{'binnmu'} > $p->{'binnmu'});
85             $srcs->{$p->{'source'}}->{'binnmu'} = $p->{'binnmu'};
86         }
87         close $P;
88     }
89
90     SRCS:
91     for my $k (keys %$srcs) {
92         if ($srcs->{$k}->{'installed'}) {
93             $srcs->{$k}->{'status'} = 'installed';
94             delete $srcs->{$k}->{'installed'};
95         } elsif ($srcs->{$k}->{'compiled'}) {
96             $srcs->{$k}->{'status'} = 'out-of-date';
97         } else {
98             $srcs->{$k}->{'status'} = 'uncompiled';
99         }
100         delete $srcs->{$k}->{'compiled'};
101         $srcs->{$k}->{'status'} = 'installed' if $srcs->{$k}->{'arch'} && $srcs->{$k}->{'arch'} eq 'all';
102         
103         if (!$srcs->{$k}->{'for-us'} && $srcs->{$k}->{'status'} ne 'installed') {
104             $srcs->{$k}->{'status'} = 'auto-not-for-us';
105         }
106         delete $srcs->{$k}->{'for-us'};
107
108         #my $p = $pas->{$k};
109         #$p ||= $pas->{'%'.$k};
110         #$srcs->{$k}->{'status'} = 'not-for-us' if pasignore($p, $arch);
111         if (pasignore($pas->{'%'.$k}, $arch)) {
112             $srcs->{$k}->{'status'} = 'not-for-us';
113             next;
114         }
115         for my $bin (@{$srcs->{$k}->{'binary'}}) {
116             next if pasignore($pas->{$bin}, $arch);
117             next if $binary->{$bin} and $binary->{$bin}->{'arch'} eq 'all';
118             next SRCS;
119         }
120         $srcs->{$k}->{'status'} = 'not-for-us';
121     }
122     $srcs->{'_binary'} = $binary;
123     local($/) = "\n";
124
125     return \$srcs;
126 }
127
128 sub pasignore {
129     my $p = shift;
130     my $arch = shift;
131     if ($p && $p->{'mode'}) {
132         return 1 unless grep { $_ eq $arch } @{$p->{'arch'}};
133     }
134     if ($p && not $p->{'mode'}) {
135         return 1 if grep /^!$arch$/, @{$p->{'arch'}};
136     }
137     return 0;
138 }
139
140 1;