[7908f1]: lib / WineTestBot / PendingPatchSets.pm Maximize Restore History

Download this file

PendingPatchSets.pm    270 lines (223 with data), 6.2 kB

  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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# Incomplete patch series collection and items
#
# Copyright 2009 Ge van Geldorp
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
use strict;
=head1 NAME
WineTestBot::PendingPatchSets - PendingPatchSet collection
=cut
package WineTestBot::PendingPatchSet;
use WineTestBot::Config;
use WineTestBot::Patches;
use WineTestBot::Utils;
use WineTestBot::WineTestBotObjects;
use vars qw(@ISA @EXPORT);
require Exporter;
@ISA = qw(WineTestBot::WineTestBotItem Exporter);
sub CheckSubsetComplete
{
my $self = shift;
my $MaxPart = $_[0];
my $Parts = $self->Parts;
my $MissingPart = !1;
for (my $PartNo = 1; $PartNo <= $MaxPart && ! $MissingPart;
$PartNo++)
{
$MissingPart = ! defined($Parts->GetItem($PartNo));
}
return ! $MissingPart;
}
sub CheckComplete
{
my $self = shift;
return $self->CheckSubsetComplete($self->TotalParts)
}
sub SubmitSubset
{
my $self = shift;
my ($MaxPart, $FinalPatch) = @_;
my $CombinedFileName = "$DataDir/staging/" . GenerateRandomString(32) .
"_patch";
while (-e $CombinedFileName)
{
$CombinedFileName = "$DataDir/staging/" . GenerateRandomString(32) .
"_patch";
}
if (! open(COMBINED, ">$CombinedFileName"))
{
return "Can't create combined patch file";
}
my $Parts = $self->Parts;
for (my $PartNo = 1; $PartNo <= $MaxPart; $PartNo++)
{
my $Part = $Parts->GetItem($PartNo);
if (defined($Part))
{
if (open(PART, "<$DataDir/patches/" . $Part->Patch->Id))
{
print COMBINED <PART>;
close(PART);
}
}
}
close(COMBINED);
my $ErrMessage = $FinalPatch->Submit($CombinedFileName, 1);
unlink($CombinedFileName);
return $ErrMessage;
}
sub Submit
{
my $self = shift;
my $FinalPatch = $_[0];
return $self->SubmitSubset($self->TotalParts, $FinalPatch);
}
package WineTestBot::PendingPatchSets;
use ObjectModel::BasicPropertyDescriptor;
use ObjectModel::DetailrefPropertyDescriptor;
use WineTestBot::Config;
use WineTestBot::PendingPatches;
use WineTestBot::Patches;
use WineTestBot::Utils;
use WineTestBot::WineTestBotObjects;
use vars qw(@ISA @EXPORT @PropertyDescriptors);
require Exporter;
@ISA = qw(WineTestBot::WineTestBotCollection Exporter);
@EXPORT = qw(&CreatePendingPatchSets);
my @PropertyDescriptors;
BEGIN
{
$PropertyDescriptors[0] =
CreateBasicPropertyDescriptor("EMail", "EMail of series author", 1, 1, "A", 40);
$PropertyDescriptors[1] =
CreateBasicPropertyDescriptor("TotalParts", "Expected number of parts in series", 1, 1, "N", 2);
$PropertyDescriptors[2] =
CreateDetailrefPropertyDescriptor("Parts", "Parts received so far", !1, !1, \&CreatePendingPatches);
}
sub CreateItem
{
my $self = shift;
return WineTestBot::PendingPatchSet->new($self);
}
sub NewSubmission
{
my $self = shift;
my $Patch = $_[0];
if (! defined($Patch->FromEMail))
{
$Patch->Disposition("Unable to determine series author");
return undef;
}
my $Subject = $Patch->Subject;
$Subject =~ s/32\/64//;
$Subject =~ s/64\/32//;
$Subject =~ m/(\d+)\/(\d+)/;
my $PartNo = int($1);
my $MaxPartNo = int($2);
my $DummySet = CreatePendingPatchSets()->Add();
$DummySet->EMail($Patch->FromEMail);
$DummySet->TotalParts($MaxPartNo);
my $SetKey = $DummySet->GetKey();
$DummySet = undef;
my $Set = $self->GetItem($SetKey);
if (! defined($Set))
{
$Set = $self->Add();
$Set->EMail($Patch->FromEMail);
$Set->TotalParts($MaxPartNo);
}
my $Parts = $Set->Parts;
my $Part = $Parts->GetItem($PartNo);
if (! defined($Part))
{
$Part = $Parts->Add();
$Part->No($PartNo);
}
$Part->Patch($Patch);
my ($ErrKey, $ErrProperty, $ErrMessage) = $self->Save();
if (defined($ErrMessage))
{
$Patch->Disposition("Error occurred during series processing");
}
if (! $Set->CheckSubsetComplete($PartNo))
{
$Patch->Disposition($Patch->AffectsTests ? "Set not complete yet" :
"Patch doesn't affect tests");
}
else
{
my $AllPartsAvailable = 1;
while ($PartNo <= $Set->TotalParts && $AllPartsAvailable &&
! defined($ErrMessage))
{
my $Part = $Parts->GetItem($PartNo);
if (defined($Part))
{
if ($Part->Patch->AffectsTests)
{
$ErrMessage = $Set->SubmitSubset($PartNo, $Part->Patch);
}
else
{
$Part->Patch->Disposition("Patch doesn't affect tests");
}
my $ErrProperty;
($ErrProperty, $ErrMessage) = $Part->Patch->Save();
}
else
{
$AllPartsAvailable = !1;
}
$PartNo++;
}
if ($AllPartsAvailable && ! defined($ErrMessage))
{
$self->DeleteItem($Set);
}
}
return $ErrMessage;
}
sub CheckForCompleteSet
{
my $self = shift;
my $ErrMessage;
foreach my $SetKey (@{$self->GetKeys()})
{
my $Set = $self->GetItem($SetKey);
if ($Set->CheckComplete())
{
my $Patch = $Set->Parts->GetItem($Set->TotalParts)->Patch;
my $SetErrMessage = $Set->Submit($Patch);
if (defined($SetErrMessage))
{
if (! defined($ErrMessage))
{
$ErrMessage = $SetErrMessage;
}
}
else
{
$Patch->Save();
}
$self->DeleteItem($Set);
}
}
return $ErrMessage;
}
sub CreatePendingPatchSets
{
return WineTestBot::PendingPatchSets->new("PendingPatchSets", "PendingPatchSets", "PendingPatchSet", \@PropertyDescriptors);
}
1;