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