]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/Config.pm
[project @ 2000-05-02 00:04:51 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
88 my %GTagMap = (
89                 "Owner Email" => "OWNER_EMAIL",
90                 "Owner Name" => "OWNER_NAME",
91                 "Long Name" => "LONG_NAME",
92                 "Short Name" => "SHORT_NAME",
93                 "Email Domain" => "EMAIL_DOMAIN",
94                 "List Domain" => "LIST_DOMAIN",
95                 "Web Domain" => "WEB_DOMAIN",
96                 "CGI Domain" => "CGI_DOMAIN",
97                 "Submit List" => "SUBMIT_LIST",
98                 "Maint List" => "MAINT_LIST",
99                 "Quiet List" => "QUIET_LIST",
100                 "Forwarded List" => "FORWARDED_LIST",
101                 "Done List" => "DONE_LIST",
102                 "Request List" => "REQUEST_LIST",
103                 "Submitter List" => "SUBMITTER_LIST",
104                 "Control List" => "CONTROL_LIST",
105                 "Summary List" => "SUMMARY_LIST",
106                 "Mirror List" => "MIRROR_LIST",
107                 "Mirrors" => "MIRRORS",
108 );
109
110 sub strip
111 {   my $string = $_[0];
112     chop $string while $string =~ /\s$/; 
113     return $string;
114 }
115
116 #############################################################################
117 #  Read Config File and parse
118 #############################################################################
119 sub ParseConfigFile
120 {   my $configfile = $_[0];
121     my @config;
122     my $votetitle = '';
123     my $ballottype = '';
124
125     #load config file
126     print "V: Loading Config File\n" if $Globals{ "verbose" };
127     open(CONFIG,$configfile) or &fail( "E: Unable to open `$configfile'" );
128     @config = <CONFIG>;
129     close CONFIG;
130
131     #parse config file
132     print "V: Parsing Config File\n" if $Globals{ "verbose" };
133     print "D3: Parse Config:\n@config\n" if $Globals{ 'debug' } > 2;
134     print "D1: Configuration\n" if $Globals{ 'debug' };
135
136     for( my $i=0; $i<=$#config; $i++)
137     {   $_ = $config[$i];
138         chop $_;
139         next unless length $_;
140         next if /^#/;
141
142         if ( /^([^:=]*)\s*[:=]\s*([^#]*)/i ) {
143             my $key = strip( $1 );
144             my $value = strip( $2 );
145             $value = "" if(!defined($value)); 
146             if ( $key =~ /Severity\s+#*(\d+)\s*(.*)/ ) {
147                 my $options = $2;
148                 my $severity = $1;
149                 if( $options =~ /\btext\b/ ) {
150                     $Severity{ 'Text' }{ $severity } = $value;
151                     print "D2: (config) Severity $severity text = $value\n" if $Globals{ 'debug' } > 1;
152                 } else {
153                     $Severity{ $1 } = $value;
154                     print "D2: (config) Severity $severity = $value" if $Globals{ 'debug' } > 1;
155                     if( $options =~ /\bdefault\b/ ) {
156                         $Globals{ "default-severity" } = $severity;
157                         print ", default" if $Globals{ 'debug' } > 1;
158                     }
159                     if( $options =~ /\bstrong\b/ ) {
160                         $Strong{ $severity } = 1;
161                         print ", strong" if $Globals{ 'debug' } > 1;
162                     }
163                     print "\n" if $Globals{ 'debug' } > 1;
164                 }
165                 next;
166             } else {
167                 my $map = $ConfigMap{$key};
168                 if(defined($map)) {
169                     $Globals{ $map } = $value;
170                     print "$key = '$value'\n" if $Globals{ 'debug' } > 1;
171                     my $tagmap = $GTagMap{$key};
172                     if(defined($tagmap)) {
173                         $GTags{ $tagmap } = $value;
174                         print "GTAG_$tagmap = $value from $key\n" if $Globals{ 'debug' } > 1;
175                     }
176                     next;
177                 } else {
178                     print "$key\n";
179                 }
180                     
181             }
182         }
183         print "Unknown line in config!($_)\n";
184         next;
185     }
186     return @config;
187 }
188
189 END { }       # module clean-up code here (global destructor)