-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdput-wrap.pl
executable file
·171 lines (153 loc) · 5.16 KB
/
dput-wrap.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/perl -w
use strict;
use Dpkg::Control;
use Dpkg::Version;
my @args;
my $target = "ubuntu";
my $changes;
my $dryrun = 0;
my $versioncheck = 1;
foreach my $arg (@ARGV) {
if ($arg eq '-n') {
$dryrun = 1;
next;
}
if ($arg eq '--no-version-check') {
$versioncheck = 0;
next;
}
push @args, $arg;
if ($arg =~ /^[^-]/) {
if (defined($changes)) {
$target = $changes;
$changes = $arg;
} else {
$changes = $arg;
}
}
}
my $check_sru_bug_py = '
import sys
from launchpadlib.launchpad import Launchpad
bug_number = int(sys.argv[1])
source_package_name = sys.argv[2]
distro_series_name = sys.argv[3]
lp = Launchpad.login_with("sru-scanner", "production", version="devel")
distro_series = lp.distributions["ubuntu"].getSeries(name_or_version=distro_series_name)
try:
bug = lp.bugs[bug_number]
except KeyError:
print("cannot find bug #%s, maybe private?"%bug_number)
sys.exit(1)
found = False
exit_code = 0
if "[regression potential]" not in bug.description.lower() and \
"[where problems could occur]" not in bug.description.lower():
print("bug {} does not appear to follow SRU template".format(bug_number))
exit_code = 1
for task in bug.bug_tasks:
target = task.target
ds = getattr(target, "distroseries", None)
if ds != distro_series:
continue
if target.name != source_package_name:
continue
found = True
if task.status not in ["New", "Confirmed", "Triaged", "In Progress", "Fix Committed"]:
print("bug %s has task for %s/%s with unsuitable status %s"%(bug_number, distro_series_name, source_package_name, task.status))
exit_code = 1
if not found:
print("bug %s has no task for %s/%s"%(bug_number, distro_series_name, source_package_name))
exit_code = 1
sys.exit(exit_code)
';
my $c = Dpkg::Control->new(type=>CTRL_FILE_CHANGES);
$c->load($changes);
my $version = $c->{Version};
my $distribution = $c->{Distribution};
if ($target eq "ubuntu" || $target eq "ppa:ubuntu-mozilla-security/rust-updates") {
if ($version =~ "ppa") {
die("ppa version to ubuntu")
}
my $devel = qx/ubuntu-distro-info --devel/;
chomp($devel);
if ($distribution eq $devel) {
if ($versioncheck && $version =~ /[~+][0-9][0-9]\.[0-9][0-9]/) {
die("do not upload [~+]XX.YY version to devel\n")
}
} else {
my $codename = qx/ubuntu-distro-info --series=$distribution -r/;
die "could not find codename for $distribution (mis-spelled?)\n" unless $codename ne '';
chomp($codename);
$codename = (split /\s+/, $codename)[0];
my $source = $c->{Source};
if ($versioncheck && !($version =~ /[~+.]\Q$codename\E/)) {
open(my $fh, "-|", "chdist", "apt-cache", $distribution, "madison", $source);
my @vers;
while (<$fh>) {
chomp;
/Sources$/ || next;
my $ver = (split /\|/)[1];
$ver =~ s/^\s+|\s+$//g;
push @vers, $ver;
}
my $firstver = (sort version_compare @vers)[0];
$firstver =~ s/(.*)build[0-9]+/$1/;
my $curver = (reverse (sort version_compare @vers))[0];
$curver =~ s/(.*)build[0-9]+/$1/;
my $first = ($firstver eq $curver);
my $ok = 0;
if ($first) {
if ($version eq "$curver.1") {
$ok = 1;
print("good version number for first SRU\n");
}
} else {
my $trailing = $curver;
$trailing =~ s/.*\.([0-9]+)$/$1/;
$trailing++;
if ( $version eq "$firstver.$trailing") {
$ok = 1;
print("good version number for subsequent SRU\n");
}
}
if (!$ok) {
if ($version =~ /([~+.][0-9][0-9]\.[0-9][0-9])/) {
die "no [~+]$codename in version for upload targeting $distribution, found $1 though\n";
} else {
die "no [~+]$codename in version for upload targeting $distribution\n";
}
}
}
if (!defined($c->{"Launchpad-Bugs-Fixed"})) {
die "$changes does not close a bug\n";
}
foreach my $bug (split /\s+/,$c->{"Launchpad-Bugs-Fixed"}) {
open(my $fh, "-|", "python3", "-c", $check_sru_bug_py, $bug, $source, $distribution);
my $msg;
while (<$fh>) {
$msg .= $_;
}
if (!close($fh)) {
print("$msg");
die "sru bug check failed";
}
}
}
} elsif ($target =~ /^ppa:/) {
if (!($version =~ "[+~]ppa")) {
die "no [+~]ppa in version for ppa\n"
}
} else { # must be debian!
if ($version =~ /ubuntu/) {
die("don't upload ubuntu version to debian\n");
}
if ($distribution ne 'unstable' && $distribution ne 'experimental') {
die("bad distribution $distribution for debian\n");
}
}
if ($dryrun) {
exec "/bin/echo", "dput", @args;
} else {
exec "/usr/bin/dput", @args;
}