]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/Config.pm
[project @ 2000-03-18 01:40:03 by gecko]
[debbugs.git] / Debbugs / Config.pm
1 package Debvote::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( );
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 &ParseConfigFile);
19 }
20
21 use vars      @EXPORT_OK;
22
23 # initialize package globals, first exported ones
24 %Globals = (    "debug" => 0,
25                 "verbose" => 0,
26                 "quiet" => 0,
27                 ##### domains
28                 "email-domain" => "bugs.domain.com",
29                 "list-domain" => "lists.domain.com",
30                 "web-domain" => "web.domain.com",
31                 "cgi-domain" => "cgi.domain.com",
32                 ##### identification
33                 "project-short" => "debbugs",
34                 "project-long" => "Debbugs Test Project",
35                 "owner-name" => "Fred Flintstone",
36                 "owner-email" => "owner@bugs.domain.com",
37                 ##### directories
38                 "data-dir" => "/var/lib/debbugs/spool",
39                 "spool-dir" => "/var/lib/debbugs/spool/incoming",
40                 "www-dir" => "/var/lib/debbugs/www",
41                 "doc-dir" => "/var/lib/debbugs/www/txt",
42                 "maintainer-file" => "/etc/debbugs/Maintainers",
43                 "database" => "debvote.db" );
44
45 #############################################################################
46 #  Read Config File and parse
47 #############################################################################
48 sub ParseConfigFile
49 {   my $configfile = $_[0];
50     my @config;
51     my $votetitle = '';
52     my $ballottype = '';
53
54     #load config file
55     print "V: Loading Config File\n" if $Globals{ "verbose" };
56     open(CONFIG,$configfile) or &::fail( "E: Unable to open `$configfile'" );
57     @config = <CONFIG>;
58     close CONFIG;
59
60     #parse config file
61     print "V: Parsing Config File\n" if $Globals{ "verbose" };
62     print "D3: Parse Config:\n@config\n" if $Globals{ 'debug' } > 2;
63     for( my $i=0; $i<=$#config; $i++)
64     {   $_ = $config[$i];
65         chop $_;
66         next unless length $_;
67         next if /^#/;
68         if ( /^Ballot Type\s*[:=]\s*([^#]*)\s*(#.*)?/i )
69         {   my $ballottype = $1;
70             chop $ballottype while $ballottype =~ /\s$/;
71             $ballottype =~ y/A-Z/a-z/;
72             $Globals{ 'ballottype' } = $ballottype;
73         }
74         elsif ( /^Database\s*[:=]\s*(\S+)/i )
75         { $Globals{ 'database' } = $1; }
76         elsif( /^Ballot Ack\s*[:=]\s*([^#]*)/i )
77         { $Globals{ "response" } = $1; }
78         elsif( /^Ballot Template\s*[:=]\s*([^#]*)/i )
79         { $Globals{ "ballot" } = $1; }
80         elsif( /^No Ballot Letter\s*[:=]\s*([^#]*)/i )
81         { $Globals{ "noballot" } = $1; }
82         elsif ( /^Title\s*[:=]\s*([^#]*)/i )
83         { $Globals{ 'title' } = $1; }
84     }
85     if( $Globals{ "debug" } )
86     {
87         print "D1: Configuration\n";
88         print "\tBallot Type = $Globals{ 'ballottype' }\n";
89         print "\tDatabase = $Globals{ 'database' }\n";
90         print "\tBallot Ack = $Globals{ 'response' }\n";
91         print "\tBallot Template = $Globals{ 'ballot' }\n";
92         print "\tTitle = $Globals{ 'title' }\n";
93     }
94     return @config;
95 }
96
97 END { }       # module clean-up code here (global destructor)