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

Last change on this file since 1281 was 861, checked in by nanardon, 13 years ago
  • reimport missing files from previous svn
  • 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 bases, synchronisations, 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    my ($objlen) = sort { $b <=> $a } map { length($_) } keys %supported;
69    $objlen+=1;
70    my $header = '|' . (' ' x $objlen) . ' | ' . join(' | ', @bases) . ' |';
71    print '-' x length($header) . "\n";
72    print $header . "\n";
73    print '-' x length($header) . "\n";
74    foreach my $obj (sort keys %supported) {
75        printf("|%${objlen}s |", $obj);
76        foreach (@bases) {
77            print(' '.
78                ($unsupported{$_}
79                    ? 'NA'
80                    : $supported{$obj}{$_} || '  ')
81            );
82            print ' ' x (length($_) - 2) . ' |';
83        }
84        print "\n";
85        print '-' x length($header) . "\n";
86    }
87} else {
88    my %supported;
89    my @bases;
90    foreach my $basename (@qbases) {
91       
92        my $labase = $LA->base($basename) or next;
93        push(@bases, $basename);
94        foreach($labase->list_supported_objects) {
95            $supported{$_}{$basename} = 1;
96        }
97    }
98
99    my ($objlen) = sort { $b <=> $a } map { length($_) } keys %supported;
100    $objlen+=1;
101    my $header = '|' . (' ' x $objlen) . ' | ' . join(' | ', @bases) . ' |';
102    print '-' x length($header) . "\n";
103    print $header . "\n";
104    print '-' x length($header) . "\n";
105    foreach my $obj (sort keys %supported) {
106        printf("|%${objlen}s |", $obj);
107        foreach (@bases) {
108            print($supported{$obj}{$_} ? ' x' : '  ');
109            print ' ' x (length($_) - 1) . ' |';
110        }
111        print "\n";
112        print '-' x length($header) . "\n";
113    }
114}
115
116__END__
Note: See TracBrowser for help on using the repository browser.