]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/Config.pm
* Modify Debbugs::Config to work relatively transparently with the
[debbugs.git] / Debbugs / Config.pm
1
2 package Debbugs::Config;
3
4 =head1 NAME
5
6 Debbugs::Config -- Configuration information for debbugs
7
8 =head1 SYNOPSIS
9
10  use Debbugs::Config;
11
12 # to get the compatiblity interface
13
14  use Debbugs::Config qw(:globals);
15
16 =head1 DESCRIPTION
17
18 This module provides configuration variables for all of debbugs.
19
20 =head1 CONFIGURATION FILES
21
22 The default configuration file location is /etc/debbugs/config; this
23 configuration file location can be set by modifying the
24 DEBBUGS_CONFIG_FILE env variable to point at a different location.
25
26 =cut
27
28 use warnings;
29 use strict;
30 use vars qw($VERSION $DEBUG %EXPORT_TAGS @EXPORT_OK @EXPORT $USING_GLOBALS %config);
31 use base qw(Exporter);
32
33 BEGIN {
34      # set the version for version checking
35      $VERSION     = 1.00;
36      $DEBUG = 0 unless defined $DEBUG;
37      $USING_GLOBALS = 0;
38
39      @EXPORT = ();
40      %EXPORT_TAGS = (globals => [qw($gEmailDomain $gListDomain $gWebHost $gWebHostBugDir),
41                                  qw($gWebDomain $gHTMLSuffix $gCGIDomain $gMirrors),
42                                  qw($gPackagePages $gSubscriptionDomain $gProject $gProjectTitle),
43                                  qw($gMaintainer $gMaintainerWebpage $gMaintainerEmail $gUnknownMaintainerEmail),
44                                  qw($gSubmitList $gMaintList $gQuietList $gForwardList),
45                                  qw($gDoneList $gRequestList $gSubmitterList $gControlList),
46                                  qw($gSummaryList $gMirrorList $gMailer $gBug),
47                                  qw($gBugs $gRemoveAge $gSaveOldBugs $gDefaultSeverity),
48                                  qw($gShowSeverities $gBounceFroms $gConfigDir $gSpoolDir),
49                                  qw($gIncomingDir $gWebDir $gDocDir $gMaintainerFile),
50                                  qw($gMaintainerFileOverride $gPseudoDescFile $gPackageSource),
51                                  qw(%gSeverityDisplay @gTags @gSeverityList @gStrongSeverities),
52                                 ],
53                      config   => [qw(%config)],
54                     );
55      @EXPORT_OK = ();
56      Exporter::export_ok_tags(qw(globals config));
57      $EXPORT_TAGS{all} = [@EXPORT_OK];
58 }
59
60 use File::Basename qw(dirname);
61 use IO::File;
62 use Safe;
63
64 =head1 CONFIGURATION VARIABLES
65
66 =head2 General Configuration
67
68 =over
69
70 =cut
71
72 # read in the files;
73 %config = ();
74 read_config(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config');
75
76 =item email_domain
77
78 The email domain of the bts
79
80 =cut
81
82 set_default(\%config,'email_domain','bugs.something');
83
84 =item list_domain
85
86 The list domain of the bts, defaults to the email domain
87
88 =cut
89
90 set_default(\%config,'list_domain',$config{email_domain});
91
92 =item web_host
93
94 The web host of the bts; defaults to the email domain
95
96 =cut
97
98 set_default(\%config,'web_host',$config{email_domain});
99
100 =item web_host_bug_dir
101
102 The directory of the web host on which bugs are kept, defaults to C<''>
103
104 =cut
105
106 set_default(\%config,'web_host_bug_dir','');
107
108 =item web_domain
109
110 Full path of the web domain where bugs are kept, defaults to the
111 concatenation of L</web_host> and L</web_host_bug_dir>
112
113 =cut
114
115 set_default(\%config,'web_domain',$config{web_host}.'/'.$config{web_host_bug_dir});
116
117 =item html_suffix
118
119 Suffix of html pages, defaults to .html
120
121 =cut
122
123 set_default(\%config,'html_suffix','.html');
124
125 =item cgi_domain
126
127 Full path of the web domain where cgi scripts are kept. Defaults to
128 the concatentation of L</web_host> and cgi.
129
130 =cut
131
132 set_default(\%config,'cgi_domain',$config{web_domain}.($config{web_domain}=~m{/$}?'':'/').'cgi');
133
134 =item mirrors
135
136 List of mirrors [What these mirrors are used for, no one knows.]
137
138 =cut
139
140
141 set_default(\%config,'mirrors',[]);
142
143 =item package_pages
144
145 Domain where the package pages are kept; links should work in a
146 package_pages/foopackage manner. Defaults to undef, which means that
147 package links will not be made.
148
149 =cut
150
151
152 set_default(\%config,'package_pages',undef);
153
154 =item subscription_domain
155
156 Domain where subscriptions to package lists happen
157
158 =cut
159
160
161 set_default(\%config,'subscription_domain',undef);
162
163 =back
164
165 =cut
166
167
168 =head2 Project Identification
169
170 =over
171
172 =item project
173
174 Name of the project
175
176 =cut
177
178 set_default(\%config,'project','Something');
179
180 =item project_title
181
182 Name of this install of Debbugs, defaults to "L</project> Debbugs Install"
183
184 =cut
185
186 set_default(\%config,'project_title',"$config{project} Debbugs Install");
187
188 =item maintainer
189
190 Name of the maintainer of this debbugs install
191
192 =cut
193
194 set_default(\%config,'maintainer','Local DebBugs Owner');
195
196 =item maintainer_webpage
197
198 Webpage of the maintainer of this install of debbugs
199
200 =cut
201
202 set_default(\%config,'maintainer_webpage',"$config{web_domain}/~owner");
203
204 =item maintainer_email
205
206 Email address of the maintainer of this Debbugs install
207
208 =cut
209
210 set_default(\%config,'maintainer_email','root@'.$config{email_domain});
211
212 =item unknown_maintainer_email
213
214 Email address where packages with an unknown maintainer will be sent
215
216 =cut
217
218 set_default(\%config,'unknown_maintainer_email',$config{maintainer_email});
219
220 =head2 BTS Mailing Lists
221
222
223 =over
224
225 =item submit_list
226
227 =item maint_list
228
229 =item forward_list
230
231 =item done_list
232
233 =item request_list
234
235 =item submitter_list
236
237 =item control_list
238
239 =item summary_list
240
241 =item mirror_list
242
243 =back
244
245 =cut
246
247 set_default(\%config,   'submit_list',   'bug-submit-list');
248 set_default(\%config,    'maint_list',    'bug-maint-list');
249 set_default(\%config,    'quiet_list',    'bug-quiet-list');
250 set_default(\%config,  'forward_list',  'bug-forward-list');
251 set_default(\%config,     'done_list',     'bug-done-list');
252 set_default(\%config,  'request_list',  'bug-request-list');
253 set_default(\%config,'submitter_list','bug-submitter-list');
254 set_default(\%config,  'control_list',  'bug-control-list');
255 set_default(\%config,  'summary_list',  'bug-summary-list');
256 set_default(\%config,   'mirror_list',   'bug-mirror-list');
257
258 =head2 Misc Options
259
260 =cut
261
262 set_default(\%config,'mailer','exim');
263 set_default(\%config,'bug','bug');
264 set_default(\%config,'bugs','bugs');
265 set_default(\%config,'remove_age',28);
266
267 set_default(\%config,'save_old_bugs',1);
268
269 set_default(\%config,'default_severity','normal');
270 set_default(\%config,'show_severities','critical, grave, normal, minor, wishlist');
271 set_default(\%config,'strong_severities',[qw(critical grave)]);
272 set_default(\%config,'severity_list',[qw(critical grave normal wishlist)]);
273 set_default(\%config,'severity_display',{critical => "Critical $config{bugs}",
274                                          grave    => "Grave $config{bugs}",
275                                          normal   => "Normal $config{bugs}",
276                                          wishlist => "Wishlist $config{bugs}",
277                                         });
278
279 set_default(\%config,'tags',[qw(patch wontfix moreinfo unreproducible fixed stable)]);
280
281 set_default(\%config,'bounce_froms','^mailer|^da?emon|^post.*mast|^root|^wpuser|^mmdf|^smt.*|'.
282             '^mrgate|^vmmail|^mail.*system|^uucp|-maiser-|^mal\@|'.
283             '^mail.*agent|^tcpmail|^bitmail|^mailman');
284
285 set_default(\%config,'config_dir',dirname(exists $ENV{DEBBUGS_CONFIG_FILE}?$ENV{DEBBUGS_CONFIG_FILE}:'/etc/debbugs/config'));
286 set_default(\%config,'spool_dir','/var/lib/debbugs/spool');
287 set_default(\%config,'incoming_dir','incoming');
288 set_default(\%config,'web_dir','/var/lib/debbugs/www');
289 set_default(\%config,'doc_dir','/var/lib/debbugs/www/txt');
290
291 set_default(\%config,'maintainer_file',$config{config_dir}.'/Maintainers');
292 set_default(\%config,'maintainer_file_override',$config{config_dir}.'/Maintainers.override');
293 set_default(\%config,'pseduo_desc_file',$config{config_dir}.'/pseudo-packages.description');
294 set_default(\%config,'package_source',$config{config_dir}.'/indices/sources');
295
296
297 sub read_config{
298      my ($conf_file) = @_;
299      # first, figure out what type of file we're reading in.
300      my $fh = new IO::File $conf_file,'r'
301           or die "Unable to open configuration file $conf_file for reading: $!";
302      # A new version configuration file must have a comment as its first line
303      my $first_line = <$fh>;
304      my ($version) = $first_line =~ /VERSION:\s*(\d+)/i;
305      if (defined $version) {
306           if ($version == 1) {
307                # Do something here;
308                die "Version 1 configuration files not implemented yet";
309           }
310           else {
311                die "Version $version configuration files are not supported";
312           }
313      }
314      else {
315           # Ugh. Old configuration file
316           # What we do here is we create a new Safe compartment
317           # so fucked up crap in the config file doesn't sink us.
318           my $cpt = new Safe or die "Unable to create safe compartment";
319           # perldoc Opcode; for details
320           $cpt->permit('require');
321           $cpt->reval(q($gMaintainerFile = 'FOOOO'));
322           $cpt->reval(qq(require '$conf_file';));
323           die "Error in configuration file: $@" if $@;
324           # Now what we do is check out the contents of %EXPORT_TAGS to see exactly which variables
325           # we want to glob in from the configuration file
326           for my $variable (@{$EXPORT_TAGS{globals}}) {
327                my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
328                my $var_glob = $cpt->varglob($glob_name);
329                my $value; #= $cpt->reval("return $variable");
330                #print STDERR $value,qq(\n);
331                if (defined $var_glob) {{
332                     no strict 'refs';
333                     if ($glob_type eq '%') {
334                          $value = {%{*{$var_glob}}};
335                     }
336                     elsif ($glob_type eq '@') {
337                          $value = [@{*{$var_glob}}];
338                     }
339                     else {
340                          $value = ${*{$var_glob}};
341                     }
342                     # We punt here, because we can't tell if the value was
343                     # defined intentionally, or if it was just left alone;
344                     # this tries to set sane defaults.
345                     set_default(\%config,$hash_name,$value) if defined $value;
346                }}
347           }
348      }
349 }
350
351 sub __convert_name{
352      my ($variable) = @_;
353      my $hash_name = $variable;
354      $hash_name =~ s/^([\$\%\@])g//;
355      my $glob_type = $1;
356      my $glob_name = 'g'.$hash_name;
357      $hash_name =~ s/^([A-Z]+)/lc($1)/e;
358      $hash_name =~ s/([A-Z]+)/'_'.lc($1)/ge;
359      return $hash_name unless wantarray;
360      return ($hash_name,$glob_name,$glob_type);
361 }
362
363 # set_default
364
365 # sets the configuration hash to the default value if it's not set,
366 # otherwise doesn't do anything
367 # If $USING_GLOBALS, then sets an appropriate global.
368
369 sub set_default{
370      my ($config,$option,$value) = @_;
371      # update the configuration value
372      if (not $USING_GLOBALS and not exists $config{$option}) {
373           $config{$option} = $value;
374      }
375      else {
376           # Need to check if a value has already been set in a global
377      }
378      if ($USING_GLOBALS) {{
379           # fix up the variable name
380           my $varname = 'g'.join('',map {ucfirst $_} $option);
381           # Fix stupid HTML names
382           $varname =~ s/Html/HTML/;
383           no strict 'refs';
384           my $ref = ref $config{$option} || 'SCALAR';
385           *{"Debbugs::Config::${varname}"} = $config{$option};
386      }}
387 }
388
389
390 ### import magick
391
392 # All we care about here is whether we've been called with the globals option;
393 # if so, then we need to export some symbols back up; otherwise we call exporter.
394
395 sub import {
396      if (grep $_ eq ':globals', @_) {
397           $USING_GLOBALS=1;
398           for my $variable (@{$EXPORT_TAGS{globals}}) {
399                my $tmp = $variable;
400                no strict 'refs';
401                # Yes, I don't care if these are only used once
402                no warnings 'once';
403                # No, it doesn't bother me that I'm assigning an undefined value to a typeglob
404                no warnings 'misc';
405                my ($hash_name,$glob_name,$glob_type) = __convert_name($variable);
406                $tmp =~ s/^[\%\$\@]//;
407                *{"Debbugs::Config::${tmp}"} = ref($config{$hash_name})?$config{$hash_name}:\$config{$hash_name};
408           }
409      }
410      Debbugs::Config->export_to_level(1,@_);
411 }
412
413
414 1;