]> git.donarmstrong.com Git - debbugs.git/blob - bin/local-debbugs
install local-debbugs and add_bug_to_estraier; add local-debbugs
[debbugs.git] / bin / local-debbugs
1 #! /usr/bin/perl
2 # local-debbugs is part of debbugs, and is released
3 # under the terms of the GPL version 2, or any later version, at your
4 # option. See the file README and COPYING for more information.
5 # Copyright 2008 by Don Armstrong <don@donarmstrong.com>.
6
7
8 use warnings;
9 use strict;
10
11 use Getopt::Long;
12 use Pod::Usage;
13
14 =head1 NAME
15
16 local-debbugs - use a local mirror of debbugs
17
18 =head1 SYNOPSIS
19
20  [options]
21
22  Options:
23   --mirror, -M update local mirror
24   --daemon, -D start the daemon
25   --search, -S run a search
26   --show, -s show a bug
27   --debug, -d debugging level (Default 0)
28   --help, -h display this help
29   --man, -m display manual
30
31 =head1 OPTIONS
32
33 =over
34
35 =item B<--mirror, -M>
36
37 Update the local mirror of debbugs bugs
38
39 =item B<--daemon, -D>
40
41 Start up the daemon on the configured local port to serve bugs which
42 have been previously retried
43
44 =item B<--search, -S>
45
46 Cause the running daemon to show the pkgreport.cgi page corresponding
47 to the search by invoking sensible-browser and an appropriate url
48
49 =item B<--show, -s>
50
51 Cause the running daemon to show the bugreport.cgi page corresponding
52 to the bug by invoking sensible-browser and an appropriate url
53
54 =item B<--port,-p>
55
56 The port that the daemon is running on (or will be running on.)
57
58 Defaults to the value of the currently running daemon, the value in
59 the configuration file, or 8080 if nothing is set.
60
61 =item B<--bugs-to-get>
62
63 File which contains the set of bugs to get.
64 Defaults to ~/.debbugs/bugs_to_get
65
66 =item B<--debug, -d>
67
68 Debug verbosity. (Default 0)
69
70 =item B<--help, -h>
71
72 Display brief useage information.
73
74 =item B<--man, -m>
75
76 Display this manual.
77
78 =back
79
80 =head1 EXAMPLES
81
82
83 =cut
84
85
86 use vars qw($DEBUG);
87
88 use User;
89 use Config::Simple;
90 use File::Temp qw(tempdir);
91
92 my %options = (debug           => 0,
93                help            => 0,
94                man             => 0,
95                );
96
97 my %option_defaults = (port => 8080,
98                        debbugs_config => User->Home.'/.debbugs/debbugs_config',
99                        mirror_location => User->Home.'/.debbugs/mirror/',
100                        bugs_to_get => User->Home.'/.debbugs/bugs_to_get',
101                       );
102
103 GetOptions(\%options,
104            'daemon|D','show|s','search|select|S','mirror|M',
105            'debug|d+','help|h|?','man|m');
106
107 pod2usage() if $options{help};
108 pod2usage({verbose=>2}) if $options{man};
109
110 $DEBUG = $options{debug};
111
112 my @USAGE_ERRORS;
113 if (1 != scalar @options{qw(daemon show search mirror)}) {
114      push @USAGE_ERRORS,"You must pass one (and only one) of --daemon --show --search or --mirror";
115 }
116
117 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
118
119
120 # munge in local configuration
121
122 local_config(\%options);
123
124 if ($options{daemon}) {
125      # daemonize, do stuff
126 }
127 elsif ($options{mirror}) {
128      # run the mirror jobies
129      # figure out which bugs we need
130      my @bugs = select_bugs();
131      # get them
132      my $tempdir = tempdir(CLEANUP => 1);
133      my $mirror_log = IO::File->new($options{mirror_location}.'/mirror.log') or
134           die "Unable to open $options{mirror_location}/mirror.log for writing: $!";
135      my $inc_fh = IO::File->new("$tempdir/include_list",'w') or
136           die "Unable to open $tempdir/include_list for writing: $!";
137      foreach my $bug (@bugs) {
138           print {$inc_fh} "*/${bugs}.*\n" or
139                die "Unable to write to $tempdir/include_list: $!";
140      }
141      close $inc_fh or
142           die "Unable to close $tempdir/include_list: $!";
143      my ($wrf,$rfh);
144      run_rsync(log => $mirror_log,
145                ($options{debug}?(debug => \*STDERR):()),
146                options => ['-avz','--partial',
147                            '--delete',
148                            '--include-from',"$tempdir/include_list",
149                            # skip things not specifically included
150                            '--exclude','*/*',
151                            # skip the -1,-2,-3.log files
152                            '--exclude','*.log',
153                            'rsync://'.$options{bug_mirror}.'/bts-spool-db/',
154                            $options{mirror_location}.'/db-h/']
155               );
156           
157      
158      
159
160 }
161 elsif ($options{show}) {
162
163 }
164 elsif ($options{search}) {
165 }
166 else {
167      # you get here, you were an idiot in checking for @USAGE_ERRORS
168      # above
169      die "No option that we understand was passed (the first check for this is now buggy, so shoot your maintainer)"
170 }
171
172
173 # determine the local configuration
174 sub local_config{
175      my ($options) = @_;
176      my $config = {};
177      if (-e '/etc/debbugs/local_debbugs.conf') {
178           Config::Simple->import_from('/etc/debbugs/local_debbugs.conf', $config) or
179                     die "Unable to read configuration from /etc/debbugs/local_debbugs.conf: $!";
180      }
181      if (-e User->Home.'/.debbugs/local_debbugs.conf') {
182           Config::Simple->import_from(User->Home.'/.debbugs/local_debbugs.conf', $config) or
183                     die "Unable to read configuration from ".User->Home.'/.debbugs/local_debbugs.conf: '.$!;
184      }
185      for (keys %default_options) {
186           if (exists $config->{$_} and not defined $options->{$_}) {
187                $options->{$_} = $config->{$_};
188           }
189           if (not defined $options->{$_}) {
190                $options->{$_} = $default_options{$_};
191           }
192      }
193 }
194
195 sub run_rsync{
196      my ($output_fh,@rsync_options) = @_;
197      my ($wfh,$rfh);
198      my $pid = open3($wfh,$rfh,
199                      'rsync',
200                      @rsync_options,
201                     ) or die "Unable to start rsync: $!";
202      close $wfh or die "Unable to close the writer filehandle $?";
203      print {$output_fh}
204
205
206 }
207
208
209 __END__