1 | #!/usr/bin/perl -w
|
---|
2 | #
|
---|
3 | # Project Builder Distribution Parameter extractor
|
---|
4 | #
|
---|
5 | # $Id$
|
---|
6 | #
|
---|
7 | # Copyright B. Cornec 2007-2013
|
---|
8 | # Provided under the GPL v2
|
---|
9 |
|
---|
10 | use strict 'vars';
|
---|
11 | use Getopt::Long qw(:config auto_abbrev no_ignore_case);
|
---|
12 | use Data::Dumper;
|
---|
13 | use lib qw (lib);
|
---|
14 | #use lib '/usr/share/perl5'; # mandatory for opensuse
|
---|
15 | use ProjectBuilder::Base;
|
---|
16 | use ProjectBuilder::Env;
|
---|
17 | use ProjectBuilder::Distribution;
|
---|
18 | use ProjectBuilder::Conf;
|
---|
19 |
|
---|
20 | =pod
|
---|
21 |
|
---|
22 | =head1 NAME
|
---|
23 |
|
---|
24 | pb, aka project-builder.org - builds packages for your projects
|
---|
25 |
|
---|
26 | =head1 DESCRIPTION
|
---|
27 |
|
---|
28 | pb helps you build various packages directly from your project sources.
|
---|
29 | pbdistrogetparam is a command from the pb project providing the value of the parameter for the running distribution based on the most precise tuple
|
---|
30 | It is a CLI version of the pb_distro_get_param function
|
---|
31 |
|
---|
32 | =head1 SYNOPSIS
|
---|
33 |
|
---|
34 | pbdistrogetparam [-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 |
|
---|
42 | Prints this help
|
---|
43 |
|
---|
44 | =item B<-v|--verbose>
|
---|
45 |
|
---|
46 | Print a brief help message and exits.
|
---|
47 |
|
---|
48 | =item B<-d|--distribution>
|
---|
49 |
|
---|
50 | The tuple for which to print the parameter value considered (by default current distribution)
|
---|
51 |
|
---|
52 | =item B<-p|--project project_name>
|
---|
53 |
|
---|
54 | Name of the project you're working on (or use the env variable PBPROJ)
|
---|
55 |
|
---|
56 | =item B<-a|--all>
|
---|
57 |
|
---|
58 | Process all configuration parameters
|
---|
59 |
|
---|
60 | =back
|
---|
61 |
|
---|
62 | =head1 ARGUMENTS
|
---|
63 |
|
---|
64 | Arguments is mandatory and corresponds to the parameter whose value is requested for the related distribution tuple.
|
---|
65 |
|
---|
66 | =head1 WEB SITES
|
---|
67 |
|
---|
68 | The 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 |
|
---|
72 | Cf: 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 |
|
---|
76 | Uses 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 |
|
---|
80 | The 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 |
|
---|
84 | Project-Builder.org is distributed under the GPL v2.0 license
|
---|
85 | described in the file C<COPYING> included with the distribution.
|
---|
86 |
|
---|
87 | =cut
|
---|
88 |
|
---|
89 | my %opts; # CLI Options
|
---|
90 |
|
---|
91 | GetOptions(
|
---|
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 | );
|
---|
98 | if (defined $opts{'h'}) {
|
---|
99 | pb_syntax(0,$opts{'h'}-1);
|
---|
100 | }
|
---|
101 | if (defined $opts{'man'}) {
|
---|
102 | pb_syntax(0,2);
|
---|
103 | }
|
---|
104 | if (defined $opts{'v'}) {
|
---|
105 | $pbdebug = $opts{'v'};
|
---|
106 | }
|
---|
107 | pb_log_init($pbdebug, \*STDOUT);
|
---|
108 |
|
---|
109 | my $dist = $opts{'d'};
|
---|
110 | pb_env_init($opts{'p'},0,"none",0);
|
---|
111 | my $pbos = pb_distro_get_context($dist);
|
---|
112 |
|
---|
113 | my @tab = @ARGV;
|
---|
114 | @tab = pb_conf_get_all() if (defined $opts{'a'});
|
---|
115 |
|
---|
116 | my %rep;
|
---|
117 | my $i = 0;
|
---|
118 | # Index on prj
|
---|
119 | foreach 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;
|
---|
126 | foreach my $r (pb_distro_get_param($pbos,pb_conf_get(@tab))) {
|
---|
127 | $rep{$tab[$i]} = $r if (defined $tab[$i]);
|
---|
128 | $i++;
|
---|
129 | }
|
---|
130 | foreach my $r (keys %rep) {
|
---|
131 | print "$r => " if ((defined $opts{'v'}) || (defined $opts{'a'}));
|
---|
132 | print "$rep{$r}\n";
|
---|
133 | }
|
---|