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-config - Tools to query configuration of LATMOS::Accounts system. |
---|
12 | |
---|
13 | =head1 SYNOPSIS |
---|
14 | |
---|
15 | List supported base, synchronisation, objects and attributes |
---|
16 | |
---|
17 | la-config [option] [object] |
---|
18 | |
---|
19 | =cut |
---|
20 | |
---|
21 | GetOptions( |
---|
22 | 'c|config=s' => \my $config, |
---|
23 | 'lb' => \my $listbases, |
---|
24 | 'ls' => \my $listsynchros, |
---|
25 | 'base=s' => \my $base, |
---|
26 | 'help' => sub { pod2usage(0) }, |
---|
27 | ) or pod2usage(); |
---|
28 | |
---|
29 | =head1 OPTIONS |
---|
30 | |
---|
31 | =item -c|--config configdir |
---|
32 | |
---|
33 | Use this configuration directory instead of the default one. |
---|
34 | |
---|
35 | =item -b|--base basename |
---|
36 | |
---|
37 | Perform query on this base |
---|
38 | |
---|
39 | =item --lb |
---|
40 | |
---|
41 | List base setup in config |
---|
42 | |
---|
43 | =item --ls |
---|
44 | |
---|
45 | List synchronisation setup in config |
---|
46 | |
---|
47 | =cut |
---|
48 | |
---|
49 | my $LA = LATMOS::Accounts->new($config, noacl => 1); |
---|
50 | |
---|
51 | if ($listbases) { |
---|
52 | my $default = $LA->default_base_name || ''; |
---|
53 | print "Bases:\n"; |
---|
54 | foreach ($LA->list_bases) { |
---|
55 | printf(" %s %s (%s)\n", |
---|
56 | ($_ eq $default ? '*' : ' '), |
---|
57 | $_, |
---|
58 | $LA->val($_, 'type', 'Err: no type') |
---|
59 | ); |
---|
60 | } |
---|
61 | } |
---|
62 | if ($listsynchros) { |
---|
63 | my $default_sync = $LA->default_synchro_name || ''; |
---|
64 | print "Syncro:\n"; |
---|
65 | foreach ($LA->list_synchro) { |
---|
66 | printf(" %s %s (%s => %s)\n", |
---|
67 | ($_ eq $default_sync ? '*' : ' '), |
---|
68 | $_, |
---|
69 | $LA->val("sync:$_", 'from', 'Err: No from'), |
---|
70 | join(', ', $LA->val("sync:$_", 'to', 'Err: No to')), |
---|
71 | ); |
---|
72 | } |
---|
73 | } |
---|
74 | if (!($listsynchros || $listbases)) { |
---|
75 | if (my $otype = $ARGV[0]) { |
---|
76 | my $labase = $base ? $LA->base($base) : $LA->default_base; |
---|
77 | printf "Supported field for object type %s (base %s)\n", |
---|
78 | $otype, |
---|
79 | $base ? $base : $LA->default_base_name; |
---|
80 | foreach($labase->list_canonical_fields($otype, 'a')) { |
---|
81 | my $attr = $labase->attribute($otype, $_); |
---|
82 | printf( |
---|
83 | " %s (%s%s)\n", $_, |
---|
84 | 'r', |
---|
85 | ($attr->readonly ? 'w' : ' '), |
---|
86 | ) |
---|
87 | } |
---|
88 | } else { |
---|
89 | my $labase = $base ? $LA->base($base) : $LA->default_base |
---|
90 | or die "Cannot instanciate " . |
---|
91 | $base ? $base : $LA->default_base_name . "\n"; |
---|
92 | printf "Supported object type by base %s\n", |
---|
93 | $base ? $base : $LA->default_base_name; |
---|
94 | print " $_\n" foreach($labase->ordered_objects); |
---|
95 | } |
---|
96 | } |
---|