]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/Config.pm
[project @ 2000-05-01 15:24:03 by gecko]
[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                 "Errors Email" => "errors-email",
61                 "Owner Webpage" => "owner-webpage",
62                 "Spool Dir" => "spool-dir",
63                 "Work Dir" => "work-dir",
64                 "Web Dir" => "www-dir",
65                 "Doc Dir" => "doc-dir",
66                 "Maintainer File" => "maintainer-file",
67                 "Pseudo Description File" => "pseudo-description",
68                 "Submit List" => "submit-list",
69                 "Maint List" => "maint-list",
70                 "Quiet List" => "quiet-list",
71                 "Forwarded List" => "forwarded-list",
72                 "Done List" => "done-list",
73                 "Request List" => "request-list",
74                 "Submitter List" => "submitter-list",
75                 "Control List" => "control-list",
76                 "Summary List" => "summary-list",
77                 "Mirror List" => "mirror-list",
78                 "Mailer" => "mailer",
79                 "Singular Term" => "singluar",
80                 "Plural Term" => "plural",
81                 "Expire Age" => "expire-age",
82                 "Save Expired Bugs" => "save-expired",
83                 "Mirrors" => "mirrors",
84                 "Default Severity" => "default-severity",
85                 "Normal Severity" => "normal-severity",
86         );
87 sub strip
88 {   my $string = $_[0];
89     chop $string while $string =~ /\s$/; 
90     return $string;
91 }
92
93 #############################################################################
94 #  Read Config File and parse
95 #############################################################################
96 sub ParseConfigFile
97 {   my $configfile = $_[0];
98     my @config;
99     my $votetitle = '';
100     my $ballottype = '';
101
102     #load config file
103     print "V: Loading Config File\n" if $Globals{ "verbose" };
104     open(CONFIG,$configfile) or &fail( "E: Unable to open `$configfile'" );
105     @config = <CONFIG>;
106     close CONFIG;
107
108     #parse config file
109     print "V: Parsing Config File\n" if $Globals{ "verbose" };
110     print "D3: Parse Config:\n@config\n" if $Globals{ 'debug' } > 2;
111     print "D1: Configuration\n" if $Globals{ 'debug' };
112
113     for( my $i=0; $i<=$#config; $i++)
114     {   $_ = $config[$i];
115         chop $_;
116         next unless length $_;
117         next if /^#/;
118
119         if ( /^([^:=]*)\s*[:=]\s*([^#]*)/i ) {
120             my $key = strip( $1 );
121             my $value = strip( $2 );
122             $value = "" if(!defined($value)); 
123             if ( $key =~ /Severity\s+#*(\d+)\s*(.*)/ ) {
124                 my $options = $2;
125                 my $severity = $1;
126                 if( $options =~ /\btext\b/ ) {
127                     $Severity{ 'Text' }{ $severity } = $value;
128                     print "D2: (config) Severity $severity text = $value\n" if $Globals{ 'debug' } > 1;
129                 } else {
130                     $Severity{ $1 } = $value;
131                     print "D2: (config) Severity $severity = $value" if $Globals{ 'debug' } > 1;
132                     if( $options =~ /\bdefault\b/ ) {
133                         $Globals{ "default-severity" } = $severity;
134                         print ", default" if $Globals{ 'debug' } > 1;
135                     }
136                     if( $options =~ /\bstrong\b/ ) {
137                         $Strong{ $severity } = 1;
138                         print ", strong" if $Globals{ 'debug' } > 1;
139                     }
140                     print "\n" if $Globals{ 'debug' } > 1;
141                 }
142                 next;
143             } else {
144                 my $map = $ConfigMap{$key};
145                 if(defined($map)) {
146                     $Globals{ $map } = $value;
147                     print "$key = '$value'\n" if $Globals{ 'debug' } > 1;
148                     next;
149                 } else {
150                     print "$key\n";
151                 }
152             }
153         }
154         print "Unknown line in config!($_)\n";
155         next;
156     }
157     return @config;
158 }
159
160 END { }       # module clean-up code here (global destructor)