]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/Config.pm
[project @ 2000-05-02 01:08:57 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 %GTags %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 %GTags %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 %GTags = ();
30 %Globals = (    "debug" => 0,
31                 "verbose" => 0,
32                 "quiet" => 0,
33                 ##### domains
34                 "email-domain" => "bugs.domain.com",
35                 "list-domain" => "lists.domain.com",
36                 "web-domain" => "web.domain.com",
37                 "cgi-domain" => "cgi.domain.com",
38                 ##### identification
39                 "project-short" => "debbugs",
40                 "project-long" => "Debbugs Test Project",
41                 "owner-name" => "Fred Flintstone",
42                 "owner-email" => "owner\@bugs.domain.com",
43                 ##### directories
44                 "work-dir" => "/var/lib/debbugs/spool",
45                 "spool-dir" => "/var/lib/debbugs/spool/incoming",
46                 "www-dir" => "/var/lib/debbugs/www",
47                 "doc-dir" => "/var/lib/debbugs/www/txt",
48                 ##### files
49                 "maintainer-file" => "/etc/debbugs/Maintainers",
50                 "pseudo-description" => "/etc/debbugs/pseudo-packages.description");
51
52 my %ConfigMap = ( 
53                 "Email Domain" => "email-domain",
54                 "List Domain" => "list-domain",
55                 "Web Domain" => "web-domain",
56                 "CGI Domain" => "cgi-domain",
57                 "Short Name" => "project-short",
58                 "Long Name" => "project-long",
59                 "Owner Name" => "owner-name",
60                 "Owner Email" => "owner-email",
61                 "Errors Email" => "errors-email",
62                 "Owner Webpage" => "owner-webpage",
63                 "Spool Dir" => "spool-dir",
64                 "Work Dir" => "work-dir",
65                 "Web Dir" => "www-dir",
66                 "Doc Dir" => "doc-dir",
67                 "Maintainer File" => "maintainer-file",
68                 "Pseudo Description File" => "pseudo-description",
69                 "Submit List" => "submit-list",
70                 "Maint List" => "maint-list",
71                 "Quiet List" => "quiet-list",
72                 "Forwarded List" => "forwarded-list",
73                 "Done List" => "done-list",
74                 "Request List" => "request-list",
75                 "Submitter List" => "submitter-list",
76                 "Control List" => "control-list",
77                 "Summary List" => "summary-list",
78                 "Mirror List" => "mirror-list",
79                 "Mailer" => "mailer",
80                 "Singular Term" => "singluar",
81                 "Plural Term" => "plural",
82                 "Expire Age" => "expire-age",
83                 "Save Expired Bugs" => "save-expired",
84                 "Mirrors" => "mirrors",
85                 "Default Severity" => "default-severity",
86                 "Normal Severity" => "normal-severity",
87         );
88
89 my %GTagsMap = ( 
90                 "email-domain" => "EMAIL_DOMAIN",
91                 "list-domain" => "LIST_DOMAIN",
92                 "web-domain" => "WEB_DOMAIN",
93                 "cgi-domain" => "CGI_DOMAIN",
94                 "project-short" => "SHORT_NAME",
95                 "project-long" => "LONG_NAME",
96                 "owner-name" => "OWNER_NAME",
97                 "owner-email" => "OWNER_EMAIL",
98                 "submit-list" => "SUBMIT_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'" if $Globals{ 'debug' } > 1;
171                     my $gtag = $GTagsMap{ $map };
172                     if(defined($gtag)) {
173                         $GTags{ $gtag } = $value;
174                         print "GTag = '$gtag'" if $Globals{ 'debug' } > 1;
175                     }
176                     print "\n" if $Globals{ 'debug' } > 1;
177                     next;
178                 } else {
179                     print "$key\n";
180                 }
181                     
182             }
183         }
184         print "Unknown line in config!($_)\n";
185         next;
186     }
187     return @config;
188 }
189
190 END { }       # module clean-up code here (global destructor)