]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/Config.pm
[project @ 2000-05-03 16:27:26 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 %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                 "Template Dir" => "template-dir",
68                 "Maintainer File" => "maintainer-file",
69                 "Pseudo Description File" => "pseudo-description",
70                 "Submit List" => "submit-list",
71                 "Maint List" => "maint-list",
72                 "Quiet List" => "quiet-list",
73                 "Forwarded List" => "forwarded-list",
74                 "Done List" => "done-list",
75                 "Request List" => "request-list",
76                 "Submitter List" => "submitter-list",
77                 "Control List" => "control-list",
78                 "Summary List" => "summary-list",
79                 "Mirror List" => "mirror-list",
80                 "Mailer" => "mailer",
81                 "Singular Term" => "singluar",
82                 "Plural Term" => "plural",
83                 "Expire Age" => "expire-age",
84                 "Save Expired Bugs" => "save-expired",
85                 "Mirrors" => "mirrors",
86                 "Default Severity" => "default-severity",
87                 "Normal Severity" => "normal-severity",
88         );
89
90 my %GTagsMap = ( 
91                 "email-domain" => "EMAIL_DOMAIN",
92                 "list-domain" => "LIST_DOMAIN",
93                 "web-domain" => "WEB_DOMAIN",
94                 "cgi-domain" => "CGI_DOMAIN",
95                 "project-short" => "SHORT_NAME",
96                 "project-long" => "LONG_NAME",
97                 "owner-name" => "OWNER_NAME",
98                 "owner-email" => "OWNER_EMAIL",
99                 "submit-list" => "SUBMIT_LIST",
100                 "quiet-list" => "QUIET_LIST",
101                 "forwarded-list" => "FORWARDED_LIST",
102                 "done-list" => "DONE_LIST",
103                 "request-list" => "REQUEST_LIST",
104                 "submitter-list" => "SUBMITTER_LIST",
105                 "control-list" => "CONTROL_LIST",
106                 "summary-list" => "SUMMARY_LIST",
107                 "mirror-list" => "MIRROR_LIST",
108                 "mirrors" => "MIRRORS"
109         );
110
111 sub strip
112 {   my $string = $_[0];
113     chop $string while $string =~ /\s$/; 
114     return $string;
115 }
116
117 #############################################################################
118 #  Read Config File and parse
119 #############################################################################
120 sub ParseConfigFile
121 {   my $configfile = $_[0];
122     my @config;
123     my $votetitle = '';
124     my $ballottype = '';
125
126     #load config file
127     print "V: Loading Config File\n" if $Globals{ "verbose" };
128     open(CONFIG,$configfile) or &fail( "E: Unable to open `$configfile'" );
129     @config = <CONFIG>;
130     close CONFIG;
131
132     #parse config file
133     print "V: Parsing Config File\n" if $Globals{ "verbose" };
134     print "D3: Parse Config:\n@config\n" if $Globals{ 'debug' } > 2;
135     print "D1: Configuration\n" if $Globals{ 'debug' };
136
137     for( my $i=0; $i<=$#config; $i++)
138     {   $_ = $config[$i];
139         chop $_;
140         next unless length $_;
141         next if /^#/;
142
143         if ( /^([^:=]*)\s*[:=]\s*([^#]*)/i ) {
144             my $key = strip( $1 );
145             my $value = strip( $2 );
146             $value = "" if(!defined($value)); 
147             if ( $key =~ /Severity\s+#*(\d+)\s*(.*)/ ) {
148                 my $options = $2;
149                 my $severity = $1;
150                 if( $options =~ /\btext\b/ ) {
151                     $Severity{ 'Text' }{ $severity } = $value;
152                     print "D2: (config) Severity $severity text = $value\n" if $Globals{ 'debug' } > 1;
153                 } else {
154                     $Severity{ $1 } = $value;
155                     print "D2: (config) Severity $severity = $value" if $Globals{ 'debug' } > 1;
156                     if( $options =~ /\bdefault\b/ ) {
157                         $Globals{ "default-severity" } = $severity;
158                         print ", default" if $Globals{ 'debug' } > 1;
159                     }
160                     if( $options =~ /\bstrong\b/ ) {
161                         $Strong{ $severity } = 1;
162                         print ", strong" if $Globals{ 'debug' } > 1;
163                     }
164                     print "\n" if $Globals{ 'debug' } > 1;
165                 }
166                 next;
167             } else {
168                 my $map = $ConfigMap{$key};
169                 if(defined($map)) {
170                     $Globals{ $map } = $value;
171                     print "$key = '$value'" if $Globals{ 'debug' } > 1;
172                     my $gtag = $GTagsMap{ $map };
173                     if(defined($gtag)) {
174                         $GTags{ $gtag } = $value;
175                         print "GTag = '$gtag'" if $Globals{ 'debug' } > 1;
176                     }
177                     print "\n" if $Globals{ 'debug' } > 1;
178                     next;
179                 } else {
180                     print "$key\n";
181                 }
182                     
183             }
184         }
185         print "Unknown line in config!($_)\n";
186         next;
187     }
188     return @config;
189 }
190
191 END { }       # module clean-up code here (global destructor)