source: ProjectBuilder/devel/pb-modules/bin/pbgetparam @ 2032

Last change on this file since 2032 was 2032, checked in by Bruno Cornec, 5 years ago
  • Copyright update for 2016
File size: 3.3 KB
Line 
1#!/usr/bin/perl -w
2#
3# Project Builder Distribution Parameter extractor
4#
5# $Id$
6#
7# Copyright B. Cornec 2007-2016
8# Provided under the GPL v2
9
10use strict 'vars';
11use Getopt::Long qw(:config auto_abbrev no_ignore_case);
12use Data::Dumper;
13use lib qw (lib);
14#use lib '/usr/share/perl5'; # mandatory for opensuse
15use ProjectBuilder::Base;
16use ProjectBuilder::Env;
17use ProjectBuilder::Distribution;
18use ProjectBuilder::Conf;
19
20=pod
21
22=head1 NAME
23
24pb, aka project-builder.org - builds packages for your projects
25
26=head1 DESCRIPTION
27
28pb helps you build various packages directly from your project sources.
29pbdistrogetparam is a command from the pb project providing the value of the parameter for the running distribution based on the most precise tuple
30It is a CLI version of the pb_distro_get_param function
31
32=head1 SYNOPSIS
33
34pbdistrogetparam [-h][-v][-p project][-d distro-ver-arch] [param|-a]
35
36=head1 OPTIONS
37
38=over 4
39
40=item B<-h|--help>
41
42Prints this help
43
44=item B<-v|--verbose>
45
46Print a brief help message and exits.
47
48=item B<-d|--distribution>
49
50The tuple for which to print the parameter value considered (by default current distribution)
51
52=item B<-p|--project project_name>
53
54Name of the project you're working on (or use the env variable PBPROJ)
55
56=item B<-a|--all>
57
58Process all configuration parameters
59
60=back
61
62=head1 ARGUMENTS
63
64Arguments is mandatory and corresponds to the parameter whose value is requested for the related distribution tuple.
65
66=head1 WEB SITES
67
68The main Web site of the project is available at L<http://www.project-builder.org/>. Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
69
70=head1 USER MAILING LIST
71
72Cf: L<http://www.mondorescue.org/sympa/info/pb-announce> for announces and L<http://www.mondorescue.org/sympa/info/pb-devel> for the development of the pb project.
73
74=head1 CONFIGURATION FILES
75
76Uses the main /etc/pb/pb.conf (or /usr/local/etc/pb/pb.conf if installed from files) configuration file to give its answers.
77
78=head1 AUTHORS
79
80The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
81
82=head1 COPYRIGHT
83
84Project-Builder.org is distributed under the GPL v2.0 license
85described in the file C<COPYING> included with the distribution.
86
87=cut
88
89my %opts;                   # CLI Options
90
91GetOptions(
92        "verbose|v+" => \$opts{'v'},
93        "help|h" => \$opts{'h'},
94        "all|a" => \$opts{'a'},
95        "project|p=s" => \$opts{'p'},
96        "distribution|d=s" => \$opts{'d'},
97);
98if (defined $opts{'h'}) {
99    pb_syntax(0,$opts{'h'}-1);
100}
101if (defined $opts{'man'}) {
102    pb_syntax(0,2);
103}
104if (defined $opts{'v'}) {
105    $pbdebug = $opts{'v'};
106}
107pb_log_init($pbdebug, \*STDOUT);
108
109my $dist = $opts{'d'};
110pb_env_init($opts{'p'},0,"none",0);
111my $pbos = pb_distro_get_context($dist);
112
113my @tab = @ARGV;
114@tab = pb_conf_get_all() if (defined $opts{'a'});
115
116my %rep;
117my $i = 0;
118# Index on prj
119foreach my $r (pb_conf_get(@tab)) {
120    $rep{$tab[$i]} = $r->{'default'} if (defined  $r->{'default'});
121    $rep{$tab[$i]} = $r->{$ENV{'PBPROJ'}} if (defined  $r->{$ENV{'PBPROJ'}});
122    $i++;
123}
124# Index on distro
125$i = 0;
126foreach my $r (pb_distro_get_param($pbos,pb_conf_get(@tab))) {
127    $rep{$tab[$i]} = $r if (defined $tab[$i]);
128    $i++;
129}
130foreach my $r (keys %rep) {
131    print "$r => " if ((defined $opts{'v'}) || (defined $opts{'a'}));
132    print "$rep{$r}\n";
133}
Note: See TracBrowser for help on using the repository browser.