source: LATMOS-Accounts/bin/la-config @ 861

Last change on this file since 861 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.3 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-config - Tools to query configuration of LATMOS::Accounts system.
12
13=head1 SYNOPSIS
14
15List supported base, synchronisation, objects and attributes
16
17    la-config [option] [object]
18
19=cut
20
21GetOptions(
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
33Use this configuration directory instead of the default one.
34
35=item -b|--base basename
36
37Perform query on this base
38
39=item --lb
40
41List base setup in config
42
43=item --ls
44
45List synchronisation setup in config
46
47=cut
48
49my $LA = LATMOS::Accounts->new($config, noacl => 1);
50
51if ($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}
62if ($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}
74if (!($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}
Note: See TracBrowser for help on using the repository browser.