source: LATMOS-Accounts/bin/la-attributes @ 494

Last change on this file since 494 was 459, checked in by nanardon, 15 years ago
  • add bin/la-attributes, show a list of all base/object or attributes
  • Property svn:executable set to *
  • Property svn:keywords set to Id Rev
File size: 2.8 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-attrbiutes - Show summary of supported object and attributes of config bases
12
13=head1 SYNOPSIS
14
15List supported base, synchronisation, objects and attributes
16
17    la-config [option]
18    la-config [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=item -c|--config configfile
31
32Use this configuration file instead default
33
34=item -b|--base basename
35
36Perform query on this bases (can be set multiple times)
37
38=cut
39
40my $LA = LATMOS::Accounts->new($config, noacl => 1);
41
42if (!@qbases) { @qbases = $LA->list_bases }
43
44if (my ($otype) = @ARGV) {
45    my %supported;
46    my @bases;
47    my %unsupported;
48    foreach my $basename (@qbases) {
49       
50        my $labase = $LA->base($basename) or next;
51        push(@bases, $basename);
52        $labase->is_supported_object($otype) or do {
53            $unsupported{$basename} = 1;
54            next;
55        };
56        foreach($labase->list_canonical_fields($otype, 'a')) {
57            $supported{$_}{$basename} = sprintf('%s%s',
58                ($labase->get_field_name($otype, $_, 'r') ? 'r' : ' '),
59                ($labase->get_field_name($otype, $_, 'w') ? 'w' : ' '),
60            );
61        }
62    }
63
64    my ($objlen) = sort { $b <=> $a } map { length($_) } keys %supported;
65    $objlen+=1;
66    my $header = '|' . (' ' x $objlen) . ' | ' . join(' | ', @bases) . ' |';
67    print '-' x length($header) . "\n";
68    print $header . "\n";
69    print '-' x length($header) . "\n";
70    foreach my $obj (sort keys %supported) {
71        printf("|%${objlen}s |", $obj);
72        foreach (@bases) {
73            print(' '.
74                ($unsupported{$_}
75                    ? 'NA'
76                    : $supported{$obj}{$_} || '  ')
77            );
78            print ' ' x (length($_) - 2) . ' |';
79        }
80        print "\n";
81        print '-' x length($header) . "\n";
82    }
83} else {
84    my %supported;
85    my @bases;
86    foreach my $basename (@qbases) {
87       
88        my $labase = $LA->base($basename) or next;
89        push(@bases, $basename);
90        foreach($labase->list_supported_objects) {
91            $supported{$_}{$basename} = 1;
92        }
93    }
94
95    my ($objlen) = sort { $b <=> $a } map { length($_) } keys %supported;
96    $objlen+=1;
97    my $header = '|' . (' ' x $objlen) . ' | ' . join(' | ', @bases) . ' |';
98    print '-' x length($header) . "\n";
99    print $header . "\n";
100    print '-' x length($header) . "\n";
101    foreach my $obj (sort keys %supported) {
102        printf("|%${objlen}s |", $obj);
103        foreach (@bases) {
104            print($supported{$obj}{$_} ? ' x' : '  ');
105            print ' ' x (length($_) - 1) . ' |';
106        }
107        print "\n";
108        print '-' x length($header) . "\n";
109    }
110}
111
112__END__
Note: See TracBrowser for help on using the repository browser.