]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/Config.pm
[project @ 2000-05-01 05:16:26 by doogie]
[debbugs.git] / Debbugs / Config.pm
1 package Debbugs::Config;  # assumes Some/Module.pm
2
3 use strict;
4
5 BEGIN 
6 {       use Exporter   ();
7         use vars       qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
8         
9     # set the version for version checking
10     $VERSION     = 1.00;
11
12     @ISA         = qw(Exporter);
13     @EXPORT      = qw(%Globals %Strong %Severity );
14     %EXPORT_TAGS = ( );     # eg: TAG => [ qw!name1 name2! ],
15
16     # your exported package globals go here,
17     # as well as any optionally exported functions
18     @EXPORT_OK   = qw(%Globals %Severity %Strong &ParseConfigFile &ParseXMLConfigFile);
19 }
20
21 use vars      @EXPORT_OK;
22 use Debbugs::Common;
23 use Debbugs::Email;
24
25 # initialize package globals, first exported ones
26 %Severity = ();
27 %Strong = ();
28 $Severity{ 'Text' } = ();
29 %Globals = (    "debug" => 0,
30                 "verbose" => 0,
31                 "quiet" => 0,
32                 ##### domains
33                 "email-domain" => "bugs.domain.com",
34                 "list-domain" => "lists.domain.com",
35                 "web-domain" => "web.domain.com",
36                 "cgi-domain" => "cgi.domain.com",
37                 ##### identification
38                 "project-short" => "debbugs",
39                 "project-long" => "Debbugs Test Project",
40                 "owner-name" => "Fred Flintstone",
41                 "owner-email" => "owner\@bugs.domain.com",
42                 ##### directories
43                 "work-dir" => "/var/lib/debbugs/spool",
44                 "spool-dir" => "/var/lib/debbugs/spool/incoming",
45                 "www-dir" => "/var/lib/debbugs/www",
46                 "doc-dir" => "/var/lib/debbugs/www/txt",
47                 ##### files
48                 "maintainer-file" => "/etc/debbugs/Maintainers",
49                 "pseudo-description" => "/etc/debbugs/pseudo-packages.description");
50
51 my %ConfigMap = ( 
52                 "Email Domain" => "email-domain",
53                 "List Domain" => "list-domain",
54                 "Web Domain" => "web-domain",
55                 "CGI Domain" => "cgi-domain",
56                 "Short Name" => "project-short",
57                 "Long Name" => "project-long",
58                 "Owner Name" => "owner-name",
59                 "Owner Email" => "owner-email",
60                 "Owner Webpage" => "owner-webpage",
61                 "Spool Dir" => "spool-dir",
62                 "Work Dir" => "work-dir",
63                 "Web Dir" => "www-dir",
64                 "Doc Dir" => "doc-dir",
65                 "Maintainer File" => "maintainer-file",
66                 "Pseudo Description File" => "pseudo-description",
67                 "Submit List" => "submit-list",
68                 "Maint List" => "maint-list",
69                 "Quiet List" => "quiet-list",
70                 "Forwarded List" => "forwarded-list",
71                 "Done List" => "done-list",
72                 "Request List" => "request-list",
73                 "Submitter List" => "submitter-list",
74                 "Control List" => "control-list",
75                 "Summary List" => "summary-list",
76                 "Mirror List" => "mirror-list",
77                 "Mailer" => "mailer",
78                 "Singular Term" => "singluar",
79                 "Plural Term" => "plural",
80                 "Expire Age" => "expire-age",
81                 "Save Expired Bugs" => "save-expired",
82                 "Mirrors" => "mirrors",
83                 "Default Severity" => "default-severity",
84                 "Normal Severity" => "normal-severity",
85         );
86 sub strip
87 {   my $string = $_[0];
88     chop $string while $string =~ /\s$/; 
89     return $string;
90 }
91
92 #############################################################################
93 #  Read Config File and parse
94 #############################################################################
95 sub ParseConfigFile
96 {   my $configfile = $_[0];
97     my @config;
98     my $votetitle = '';
99     my $ballottype = '';
100
101     #load config file
102     print "V: Loading Config File\n" if $Globals{ "verbose" };
103     open(CONFIG,$configfile) or &fail( "E: Unable to open `$configfile'" );
104     @config = <CONFIG>;
105     close CONFIG;
106
107     #parse config file
108     print "V: Parsing Config File\n" if $Globals{ "verbose" };
109     print "D3: Parse Config:\n@config\n" if $Globals{ 'debug' } > 2;
110     print "D1: Configuration\n" if $Globals{ 'debug' };
111
112     for( my $i=0; $i<=$#config; $i++)
113     {   $_ = $config[$i];
114         chop $_;
115         next unless length $_;
116         next if /^#/;
117
118         if ( /^([^:=]*)\s*[:=]\s*([^#]*)/i ) {
119             my $key = strip( $1 );
120             my $value = strip( $2 );
121             $value = "" if(!defined($value)); 
122             if ( $key =~ /Severity\s+#*(\d+)\s*(.*)/ ) {
123                 my $options = $2;
124                 my $severity = $1;
125                 if( $options =~ /\btext\b/ ) {
126                     $Severity{ 'Text' }{ $severity } = $value;
127                     print "D2: (config) Severity $severity text = $value\n" if $Globals{ 'debug' } > 1;
128                 } else {
129                     $Severity{ $1 } = $value;
130                     print "D2: (config) Severity $severity = $value" if $Globals{ 'debug' } > 1;
131                     if( $options =~ /\bdefault\b/ ) {
132                         $Globals{ "default-severity" } = $severity;
133                         print ", default" if $Globals{ 'debug' } > 1;
134                     }
135                     if( $options =~ /\bstrong\b/ ) {
136                         $Strong{ $severity } = 1;
137                         print ", strong" if $Globals{ 'debug' } > 1;
138                     }
139                     print "\n" if $Globals{ 'debug' } > 1;
140                 }
141                 next;
142             } else {
143                 my $map = $ConfigMap{$key};
144                 if(defined($map)) {
145                     $Globals{ $map } = $value;
146                     print "$key = '$value'\n" if $Globals{ 'debug' } > 1;
147                     next;
148                 } else {
149                     print "$key\n";
150                 }
151             }
152         }
153         print "Unknown line in config!($_)\n";
154         next;
155     }
156     return @config;
157 }
158
159 END { }       # module clean-up code here (global destructor)