3
# Patchwork - automated patch tracking system
4
# Copyright (C) 2005 Jeremy Kerr <jk@ozlabs.org>
6
# This file is part of the Patchwork package.
8
# Patchwork is free software; you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 2 of the License, or
11
# (at your option) any later version.
13
# Patchwork is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with Patchwork; if not, write to the Free Software
20
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28
my $uri = 'urn:SOAPInterface';
29
# this URI has the address of the soap.pl script, followed by the project name
30
my $proxy = 'http://patchwork.ozlabs.org/soap.pl/bazaar-ng';
35
list => 'List all patches (restrict to a state with -s <state>)',
36
view => 'View a patch',
37
get => 'Download a patch and save it locally',
38
apply => 'Apply a patch (in the current dir, using -p1)',
39
search => 'Search for patches (by name)'
49
my @l = split(/\n/, $str);
52
if ($rows && $lines >= $rows) {
53
my $pager = $ENV{PAGER} || 'more';
54
open(FH, "|-", $pager) || die "Couldn't run pager '$pager': $!";
66
return "No patches\n" unless @patches;
67
my $str = list_header();
69
$max = 10 if $max < 10;
70
foreach my $patch (@patches) {
71
my $name = $patch->name();
72
if ($cols && length($name) > $max) {
73
$name = substr($name, 0, $max - 1).'$';
75
$str .= sprintf "%4d %3s %s\n", $patch->id(),
76
substr(states($patch->state()), 0, 3),
86
print STDERR "No id given to retrieve a patch\n";
90
unless ($id =~ m/^[0-9]+$/) {
91
print STDERR "Invalid patch id '$id'\n'";
95
my $res = $soap->get_patch($id);
96
die "SOAP fault: ".$res->faultstring if $res->fault;
97
my $patch = $res->result;
99
print STDERR "Patch not found\n";
109
getopts('s:', \%opts);
111
$res = $soap->get_patches_by_state(state_from_name($opts{s}));
113
$res = $soap->get_patches();
115
die "SOAP fault: ".$res->faultstring if $res->fault;
116
my $patches = $res->result;
117
page(patch_list(@$patches), $#{$patches} + 2);
123
my $query = join(' ', map { '"'.$_.'"' } @ARGV);
124
my $res = $soap->search($query);
125
die "SOAP fault: ".$res->faultstring if $res->fault;
126
my $patches = $res->result;
128
unless ($patches && @{$patches}) {
129
print "No patches found\n";
133
$str .= list_header();
134
page(patch_list(@$patches), $#{$patches});
141
my $patch = _get_patch($id);
142
page($patch->content());
149
my $patch = _get_patch($id);
150
if (-e $patch->filename()) {
151
printf STDERR "Patch file:\n\t%s\nalready exists\n",
155
open(FH, ">", $patch->filename())
156
or die "Couldn't open ".$patch->filename()." for writing: $!";
157
print FH $patch->content;
159
printf "Saved '%s'\n\tto: %s\n", $patch->name, $patch->filename();
166
my $patch = _get_patch($id);
167
open(FH, "|-", "patch", "-p1")
168
or die "Couldn't execute 'patch -p1'";
169
print FH $patch->content;
176
printf STDERR "Usage: %s <action> [options]\n", $0;
177
printf STDERR "Where <action> is one of:\n";
178
printf STDERR "\t%-6s : %s\n", $_, $actions{$_} for sort keys %actions;
183
return sprintf "%4s %3s %s\n", 'ID', 'Sta', 'Name';
189
my $state = @_ ? shift : undef;
191
my $res = $soap->get_states();
192
die "SOAP fault: ".$res->faultstring if $res->fault;
193
my $stateref = $res->result;
194
%_states = %$stateref;
196
return $state ? $_states{$state} : %_states;
199
sub state_from_name($)
203
my %states = states();
204
foreach my $id (keys(%states)) {
205
push(@matches, $id) if ($states{$id} =~ m/^$name/i);
208
print STDERR "No such state '$name'\n";
210
} elsif ($#matches > 0) {
211
printf STDERR "Multiple states match '$name':\n";
212
printf STDERR "\t%s\n", $states{$_} for @matches;
224
if (eval "require Term::Size") {
225
($cols, $rows) = Term::Size::chars(*STDOUT);
227
($cols, $rows) = (0,0);
230
$soap = new SOAP::Lite(uri => $uri, proxy => $proxy);
232
foreach (sort(keys(%actions))) {
234
eval "return &$action()" or die $@;
238
printf STDERR "No such action '%s'\n", $action;
242
# Patchwork - automated patch tracking system
243
# Copyright (C) 2005 Jeremy Kerr <jk@ozlabs.org>
245
# This file is part of the Patchwork package.
247
# Patchwork is free software; you can redistribute it and/or modify
248
# it under the terms of the GNU General Public License as published by
249
# the Free Software Foundation; either version 2 of the License, or
250
# (at your option) any later version.
252
# Patchwork is distributed in the hope that it will be useful,
253
# but WITHOUT ANY WARRANTY; without even the implied warranty of
254
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
255
# GNU General Public License for more details.
257
# You should have received a copy of the GNU General Public License
258
# along with Patchwork; if not, write to the Free Software
259
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
261
package PatchWork::Comment;
284
if (@_) { $obj->{id} = shift }
291
if (@_) { $obj->{submitter} = shift }
292
return $obj->{submitter};
298
if (@_) { $obj->{msgid} = shift }
299
return $obj->{msgid};
305
if (@_) { $obj->{date} = shift }
312
if (@_) { $obj->{content} = shift }
313
return $obj->{content};
319
push(@{$obj->{refs}}, @_) if @_;
325
# Patchwork - automated patch tracking system
326
# Copyright (C) 2005 Jeremy Kerr <jk@ozlabs.org>
328
# This file is part of the Patchwork package.
330
# Patchwork is free software; you can redistribute it and/or modify
331
# it under the terms of the GNU General Public License as published by
332
# the Free Software Foundation; either version 2 of the License, or
333
# (at your option) any later version.
335
# Patchwork is distributed in the hope that it will be useful,
336
# but WITHOUT ANY WARRANTY; without even the implied warranty of
337
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
338
# GNU General Public License for more details.
340
# You should have received a copy of the GNU General Public License
341
# along with Patchwork; if not, write to the Free Software
342
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
344
package PatchWork::Person;
357
$obj->{email} = shift;
358
$obj->{name} = shift;
364
my ($obj, $str) = @_;
366
if ($str =~ m/"?(.*?)"?\s*<([^>]+)>/) {
370
} elsif ($str =~ m/"?(.*?)"?\s*\(([^\)]+)\)/) {
375
$obj->{email} = $str;
382
if (@_) { $obj->{id} = shift }
389
if (@_) { $obj->{email} = shift }
390
return $obj->{email};
396
if (@_) { $obj->{name} = shift }
403
if (@_) { $obj->{username} = shift }
404
return $obj->{username};
409
# Patchwork - automated patch tracking system
410
# Copyright (C) 2005 Jeremy Kerr <jk@ozlabs.org>
412
# This file is part of the Patchwork package.
414
# Patchwork is free software; you can redistribute it and/or modify
415
# it under the terms of the GNU General Public License as published by
416
# the Free Software Foundation; either version 2 of the License, or
417
# (at your option) any later version.
419
# Patchwork is distributed in the hope that it will be useful,
420
# but WITHOUT ANY WARRANTY; without even the implied warranty of
421
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
422
# GNU General Public License for more details.
424
# You should have received a copy of the GNU General Public License
425
# along with Patchwork; if not, write to the Free Software
426
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
428
package PatchWork::Patch;
448
$obj->{comments} = [];
450
$obj->{archived} = 0;
458
if (@_) { $obj->{id} = shift }
465
if (@_) { $obj->{msgid} = shift }
466
return $obj->{msgid};
472
if (@_) { $obj->{date} = shift }
479
if (@_) { $obj->{state} = shift }
480
return $obj->{state};
486
if (@_) { $obj->{name} = shift }
493
if (@_) { $obj->{filename} = shift }
494
return $obj->{filename};
500
if (@_) { $obj->{submitter} = shift }
501
return $obj->{submitter};
507
if (@_) { $obj->{content} = shift }
508
return $obj->{content};
514
if (@_) { $obj->{archived} = shift }
515
return $obj->{archived};
520
my ($obj, $comment) = @_;
521
push(@{$obj->{comments}}, $comment);
527
return $obj->{comments};
533
if (@_) { $obj->{trees} = shift }
534
return $obj->{trees};
539
# Patchwork - automated patch tracking system
540
# Copyright (C) 2005 Jeremy Kerr <jk@ozlabs.org>
542
# This file is part of the Patchwork package.
544
# Patchwork is free software; you can redistribute it and/or modify
545
# it under the terms of the GNU General Public License as published by
546
# the Free Software Foundation; either version 2 of the License, or
547
# (at your option) any later version.
549
# Patchwork is distributed in the hope that it will be useful,
550
# but WITHOUT ANY WARRANTY; without even the implied warranty of
551
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
552
# GNU General Public License for more details.
554
# You should have received a copy of the GNU General Public License
555
# along with Patchwork; if not, write to the Free Software
556
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
558
package PatchWork::Tree;
586
if (@_) { $obj->{name} = shift }
593
if (@_) { $obj->{url} = shift }
599
# Patchwork - automated patch tracking system
600
# Copyright (C) 2005 Jeremy Kerr <jk@ozlabs.org>
602
# This file is part of the Patchwork package.
604
# Patchwork is free software; you can redistribute it and/or modify
605
# it under the terms of the GNU General Public License as published by
606
# the Free Software Foundation; either version 2 of the License, or
607
# (at your option) any later version.
609
# Patchwork is distributed in the hope that it will be useful,
610
# but WITHOUT ANY WARRANTY; without even the implied warranty of
611
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
612
# GNU General Public License for more details.
614
# You should have received a copy of the GNU General Public License
615
# along with Patchwork; if not, write to the Free Software
616
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
618
package PatchWork::User;
619
@PatchWork::User::ISA = ('PatchWork::Person');
638
if (@_) { $obj->{username} = shift }
639
return $obj->{username};