Changeset 323:2fb49308319a
- Timestamp:
- 08/21/11 02:44:03 (9 months ago)
- Branch:
- default
- Files:
-
- 1 added
- 3 modified
-
MANIFEST (modified) (1 diff)
-
bin/pl-conf (modified) (7 diffs)
-
lib/Lancelot/ConfigItems.pm (added)
-
lib/Lancelot/DB.pm (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
MANIFEST
r303 r323 36 36 lib/Lancelot/Bounce/tonline.pm 37 37 lib/Lancelot/Bounce/yahoo.pm 38 lib/Lancelot/ConfigItems.pm 38 39 lib/Lancelot/DB.pm 39 40 lib/Lancelot/GetOpt.pm -
bin/pl-conf
r313 r323 7 7 =head1 SYNOPSIS 8 8 9 pl-conf [--query|-q] [--valueonly|-h] list@domain [parameter ...] 9 pl-conf [--query|-q] [--all|-A] [--modified|-M] [--defaults|-D] 10 [--valueonly|-h] list@domain [parameter ...] 10 11 pl-conf [--set|-s] list@domain ["parameter = value" ...] 11 12 pl-conf [--import|-i] [--onlynew|-n] list@domain [file ...] … … 27 28 28 29 With the B<--query> (or B<-q>) option, B<pl-conf> will print either 29 all of the configuration parameters (if no parameter names are given)30 or the specified parameters to standard output, like30 all of the configuration parameters in the database (if no parameter 31 names are given) or the specified parameters to standard output, like 31 32 32 33 list.address = test@example.com … … 42 43 line. This is convenient if the parameter value is to be used, e.g., 43 44 in a shell script. 45 46 With the B<--modified> (or B<-M>) option, B<--query> only lists those 47 parameters whose values differ from their built-in defaults. With the 48 B<--defaults> (or B<-D>) option, the built-in default values of 49 parameters are displayed instead of their actual values. With the 50 B<--all> (or B<-A>) option, all parameters known to Project Lancelot 51 are displayed, not just those that actually occur in the database of 52 the list being considered. 44 53 45 54 The output of B<pl-conf --query> is suitable as input for … … 142 151 Introduces a command-line alias for a mailing list. 143 152 153 =item B<--all>, B<-A> 154 155 With B<--query>, outputs all configuration parameters known to Project 156 Lancelot, not just those that actually occur in the database of the 157 current list. 158 159 =item B<--defaults>, B<-D> 160 161 With B<--query>, causes the program to output the built-in default values 162 of parameters rather than their actual values. 163 144 164 =item B<--delete>, B<-d> 145 165 … … 162 182 this specifies the list that the given list's database should be merged 163 183 into. 184 185 =item B<--modified>, B<-M> 186 187 With B<--query>, outputs only those parameter whose values differ from 188 their built-in default values. 164 189 165 190 =item B<--onlynew>, B<-n> … … 257 282 use Lancelot::Log qw/log/; 258 283 259 my (%opts);284 my %opts = ( all => 0 ); 260 285 261 286 GetOptions(\%opts, -defaults, -argvmin => 1, "no list address specified", 262 287 "query|q?", "set|s?", "import|i?", "delete|d?", "valueonly|h?", 263 288 "merge|m?", "unmerge|u?", "alias|a?", "into=", 289 "defaults|D?", "modified|M?", "all|A?", 264 290 "onlynew|n?", "edit|e?", "user|u="); 265 291 266 pod2usage( -message => "$0: need one of --query, --set, --import, --delete ",267 -exitvalue => 2 )292 pod2usage( -message => "$0: need one of --query, --set, --import, --delete, --merge, --unmerge, --alias", 293 -exitvalue => 2 ) 268 294 if $opts{alias} + $opts{query} + $opts{set} + $opts{import} 269 295 + $opts{delete} + $opts{edit} + $opts{merge} + $opts{unmerge} != 1 270 || ($opts{valueonly} && !$opts{query}) 296 || (($opts{valueonly} || $opts{defaults} || $opts{modified} 297 || $opts{all}) && !$opts{query}) 271 298 || ($opts{onlynew} && !$opts{import}) 272 299 || ($opts{into} && !$opts{merge}); … … 284 311 ($pattern = $ARGV[0]) =~ s/\./\\./g; $pattern =~ s/\*/.*/g; 285 312 } 286 @parameters = grep { /$pattern/o } $db->config_names; 313 @parameters = grep { /$pattern/o } 314 $db->config_names({ all => $opts{all} }); 287 315 $opts{valueonly} = 0; 288 316 } 289 317 foreach my $p (sort @parameters) { 318 my ($v, $status, $default) = $db->get_config_x($p); 319 next if $opts{modified} && $status < 2; 320 $v = $default if $opts{defaults}; 290 321 print "$p = " unless $opts{valueonly}; 291 my ($v) = $db->get_config($p);292 322 if ($v =~ /^\s+/ || $v =~ /\s+$/) { 293 323 $v =~ s/\"/\\\"/g; -
lib/Lancelot/DB.pm
r321 r323 71 71 72 72 use Lancelot::Log qw/log/; 73 use Lancelot::ConfigItems; 73 74 74 75 # Here are the SQL definitions Project Lancelot uses when initialising a … … 383 384 my ($local, $domain) = split /\@/, $listaddr; 384 385 386 Lancelot::ConfigItems::init(); 387 385 388 my $home; 386 389 my $user = $optref->{user}; … … 825 828 sub get_config { 826 829 my ($self, $key) = @_; 827 my $value = ($self->{dbh}->selectrow_array("SELECT value FROM config WHERE list_id=? AND key=?", 828 {}, $self->{list_id}, $key))[0]; 829 return $value; 830 my $config = $self->{dbh}->selectrow_hashref( 831 "SELECT value FROM config WHERE list_id=? AND key=?", 832 {}, $self->{list_id}, $key); 833 if (!$config) { 834 my $cfgvar = Lancelot::ConfigItems->config_item($key); 835 log "warn", "unknown configuration variable $key" unless $cfgvar; 836 return $cfgvar? $cfgvar->{default} : undef; 837 } 838 return $config->{value}; 839 } 840 841 =item C<get_config_x> 842 843 $value = $db->get_config_x($key); 844 845 Returns a tuple (C<$value>, C<$status>, C<$default>, C<$type>, 846 C<$help>) where C<$value> is the current value of the configuration 847 parameter and C<$status> is 0 if the parameter is not set in the 848 database (i.e., C<$value> is the internal hard-coded default), 1 if 849 the parameter is set in the database but equals the internal 850 hard-coded default, 2 if the parameter is set in the database but does 851 not I<have> an internal hard-coded default (because it is used by a 852 processing module that didn't register it with the internal list), and 853 3 if the parameter is set in the database and differs from the 854 hard-coded default. 855 856 C<$type> is one of BOOL, INT, STR, and SEL and gives the type of value 857 that the configuration parameter is supposed to take on. 858 859 This is mostly for the benefit of the Project Guinevere web front end, 860 but also pl-conf(1). 861 862 =cut 863 864 sub get_config_x { 865 my ($self, $key) = @_; 866 my $cfgvar = Lancelot::ConfigItems->config_item($key); 867 my $config = $self->{dbh}->selectrow_hashref( 868 "SELECT value FROM config WHERE list_id=? AND key=?", 869 {}, $self->{list_id}, $key); 870 my @result; 871 if (!$config) { 872 if (!$cfgvar) { 873 @result = (undef, 4, undef, undef, undef); 874 } else { 875 @result = ($cfgvar->{default}, 0, $cfgvar->{default}, 876 $cfgvar->{type}, $cfgvar->{help}); 877 } 878 } elsif (!$cfgvar) { 879 @result = ($config->{value}, 2, undef, undef, undef); 880 } else { 881 if ($config->{value} eq $cfgvar->{default}) { 882 @result = ($config->{value}, 1); 883 } else { 884 @result = ($config->{value}, 3); 885 } 886 push @result, $cfgvar->{default}, $cfgvar->{type}, $cfgvar->{help}; 887 } 888 return @result; 830 889 } 831 890 … … 952 1011 953 1012 sub config_names { 954 my ($self) = @_; 955 my ($ref) = $self->{dbh}->selectcol_arrayref("SELECT key FROM config WHERE list_id=?", 956 {}, $self->{list_id}); 957 return @$ref; 1013 my ($self, $optref) = @_; 1014 my %names = map { $_ => 1 } @{$self->{dbh}->selectcol_arrayref( 1015 "SELECT key FROM config WHERE list_id=?", 1016 {}, $self->{list_id})}; 1017 if ($optref->{all}) { 1018 $names{$_} = 1 foreach Lancelot::ConfigItems->config_item_keys(); 1019 } 1020 return keys %names; 958 1021 } 959 1022
