source: trunk/LATMOS-Accounts/bin/la-attributes @ 2380

Last change on this file since 2380 was 1399, checked in by nanardon, 9 years ago

Fix: add an error message if otype is completly unsupported

  • Property svn:executable set to *
  • Property svn:keywords set to Id Rev
File size: 2.9 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use Getopt::Long;
7use Pod::Usage;
8
9=head1 NAME
10
11    la-attributes - Show summary of supported objects and attributes of config bases
12
13=head1 SYNOPSIS
14
15List supported objects and attributes
16
17    la-attributes [option]
18    la-attributes [option] object
19
20=cut
21
22GetOptions(
23    'c|config=s' => \my $config,
24    'b|base=s'   => \my @qbases,
25    'help'       => sub { pod2usage(0) },
26) or pod2usage();
27
28=head1 OPTIONS
29
30=over 4
31
32=item -c|--config configdir
33
34Use this configuration directory instead of thr default one.
35
36=item -b|--base basename
37
38Perform query on this base(s) (can be set multiple times).
39
40=back
41
42=cut
43
44my $LA = LATMOS::Accounts->new($config, noacl => 1);
45
46if (!@qbases) { @qbases = $LA->list_bases }
47
48if (my ($otype) = @ARGV) {
49    my %supported;
50    my @bases;
51    my %unsupported;
52    foreach my $basename (@qbases) {
53       
54        my $labase = $LA->base($basename) or next;
55        push(@bases, $basename);
56        $labase->is_supported_object($otype) or do {
57            $unsupported{$basename} = 1;
58            next;
59        };
60        foreach($labase->list_canonical_fields($otype, 'a')) {
61            my $attr = $labase->attribute($otype, $_);
62            $supported{$_}{$basename} = sprintf('%s',
63                $attr ? ($attr->ro ? 'r ' : 'rw') : '  '
64            );
65        }
66    }
67
68    if (! keys %supported) {
69        die "No base support this object type $otype\n";
70    }
71
72    my ($objlen) = sort { $b <=> $a } map { length($_) } keys %supported;
73    $objlen+=1;
74    my $header = '|' . (' ' x $objlen) . ' | ' . join(' | ', @bases) . ' |';
75    print '-' x length($header) . "\n";
76    print $header . "\n";
77    print '-' x length($header) . "\n";
78    foreach my $obj (sort keys %supported) {
79        printf("|%${objlen}s |", $obj);
80        foreach (@bases) {
81            print(' '.
82                ($unsupported{$_}
83                    ? 'NA'
84                    : $supported{$obj}{$_} || '  ')
85            );
86            print ' ' x (length($_) - 2) . ' |';
87        }
88        print "\n";
89        print '-' x length($header) . "\n";
90    }
91} else {
92    my %supported;
93    my @bases;
94    foreach my $basename (@qbases) {
95       
96        my $labase = $LA->base($basename) or next;
97        push(@bases, $basename);
98        foreach($labase->list_supported_objects) {
99            $supported{$_}{$basename} = 1;
100        }
101    }
102
103    my ($objlen) = sort { $b <=> $a } map { length($_) } keys %supported;
104    $objlen+=1;
105    my $header = '|' . (' ' x $objlen) . ' | ' . join(' | ', @bases) . ' |';
106    print '-' x length($header) . "\n";
107    print $header . "\n";
108    print '-' x length($header) . "\n";
109    foreach my $obj (sort keys %supported) {
110        printf("|%${objlen}s |", $obj);
111        foreach (@bases) {
112            print($supported{$obj}{$_} ? ' x' : '  ');
113            print ' ' x (length($_) - 1) . ' |';
114        }
115        print "\n";
116        print '-' x length($header) . "\n";
117    }
118}
119
120__END__
Note: See TracBrowser for help on using the repository browser.