source: trunk/LATMOS-Accounts/bin/la-sql-regatt @ 987

Last change on this file since 987 was 861, checked in by nanardon, 13 years ago
  • reimport missing files from previous svn
  • Property svn:executable set to *
File size: 1.6 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-sql-attreg - Tools to register attributes in LA SQL base
12
13=head1 SYNOPSIS
14
15    la-sql-attreg [options] name comment
16
17=cut
18
19GetOptions(
20    'c|config=s' => \my $config,
21    'b|base=s'   => \my $base,
22    'o|object=s' => \my $otype,
23    'comment'    => \my $comment,
24) or pod2usage();
25
26$otype ||= 'user';
27
28=head1 OPTIONS
29
30=over 4
31
32=item -c|--config configdir
33
34Use this configuration directory instead of the default one.
35
36=item -b|--base basename
37
38Query this specific base instead of the default one.
39
40=item -o|object object_type
41
42Query will be performed on this object. Default is the 'User' object.
43
44=item --comment
45
46Set a comment to existing attribute instead adding the attribute
47
48=back
49
50=cut
51
52if (!$ARGV[0]) {
53    warn "You must specify attribute name, aborting\n";
54    pod2usage();
55}
56
57my $LA = LATMOS::Accounts->new($config, noacl => 1);
58my $labase = $base ? $LA->base($base) : $LA->default_base;
59$labase && $labase->load or die "Cannot load base";
60$labase->wexported(1);
61
62if ($comment) {
63    if ($labase->set_attribute_comment($otype, @ARGV)) {
64        $labase->commit;
65        print "Attribute $ARGV[0] commented for object $otype\n";
66        exit(0);
67    } else {
68        warn "Error commenting attribute $ARGV[0] for object $otype\n";
69        exit(1);
70    }
71} else {
72    if ($labase->register_attribute($otype, @ARGV)) {
73        $labase->commit;
74        print "Attribute $ARGV[0] register for object $otype\n";
75        exit(0);
76    } else {
77        warn "Error registing attribute $ARGV[0] for object $otype\n";
78        exit(1);
79    }
80}
Note: See TracBrowser for help on using the repository browser.