1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use LATMOS::Accounts; |
---|
6 | use Getopt::Long; |
---|
7 | use 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 | |
---|
15 | List supported base, synchronisation, objects and attributes |
---|
16 | |
---|
17 | la-config [option] |
---|
18 | la-config [option] object |
---|
19 | |
---|
20 | =cut |
---|
21 | |
---|
22 | GetOptions( |
---|
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 | |
---|
32 | Use this configuration file instead default |
---|
33 | |
---|
34 | =item -b|--base basename |
---|
35 | |
---|
36 | Perform query on this bases (can be set multiple times) |
---|
37 | |
---|
38 | =cut |
---|
39 | |
---|
40 | my $LA = LATMOS::Accounts->new($config, noacl => 1); |
---|
41 | |
---|
42 | if (!@qbases) { @qbases = $LA->list_bases } |
---|
43 | |
---|
44 | if (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__ |
---|