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