Last change
on this file since 1254 was
1066,
checked in by nanardon, 12 years ago
|
- fix attributes existance check
|
-
Property svn:executable set to
*
|
File size:
1.4 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 | use Text::CSV_XS; |
---|
9 | |
---|
10 | =head1 NAME |
---|
11 | |
---|
12 | la-sql-loadatt - Tools to register attributes in LA SQL base |
---|
13 | |
---|
14 | =head1 SYNOPSIS |
---|
15 | |
---|
16 | la-sql-loadatt [options] csv_file |
---|
17 | |
---|
18 | =cut |
---|
19 | |
---|
20 | GetOptions( |
---|
21 | 'c|config=s' => \my $config, |
---|
22 | 'b|base=s' => \my $base, |
---|
23 | 'help' => sub { pod2usage(0); } |
---|
24 | ) or pod2usage(); |
---|
25 | |
---|
26 | =head1 OPTIONS |
---|
27 | |
---|
28 | =over 4 |
---|
29 | |
---|
30 | =item -c|--config configdir |
---|
31 | |
---|
32 | Use this configuration directory instead of the default one. |
---|
33 | |
---|
34 | =item -b|--base basename |
---|
35 | |
---|
36 | Query this specific base instead of the default one. |
---|
37 | |
---|
38 | =back |
---|
39 | |
---|
40 | =cut |
---|
41 | |
---|
42 | if (!$ARGV[0]) { |
---|
43 | warn "You must specify a file to load\n"; |
---|
44 | pod2usage(); |
---|
45 | } |
---|
46 | |
---|
47 | my $LA = LATMOS::Accounts->new($config, noacl => 1); |
---|
48 | my $labase = $LA->base($base); |
---|
49 | $labase && $labase->load or die "Cannot load base"; |
---|
50 | $labase->wexported(1); |
---|
51 | |
---|
52 | open my $fh, "<:encoding(utf8)", $ARGV[0] or die "$ARGV[0]: $!"; |
---|
53 | |
---|
54 | my $csv = Text::CSV_XS->new(); |
---|
55 | |
---|
56 | while (my $row = $csv->getline($fh)) { |
---|
57 | my ($otype, $attribute, $comment) = @$row; |
---|
58 | if ($labase->is_registered_attribute($otype, $attribute)) { |
---|
59 | } else { |
---|
60 | $labase->register_attribute($otype, $attribute, $comment) |
---|
61 | or die "Error, aborting\n"; |
---|
62 | print "Attr. $attribute for object type $otype registred\n"; |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | $csv->eof or do { |
---|
67 | $csv->error_diag(); |
---|
68 | die "Cannot load attribute\n" |
---|
69 | }; |
---|
70 | |
---|
71 | $labase->commit; |
---|
72 | print "Load terminated w/o error\n"; |
---|
73 | exit 0; |
---|
Note: See
TracBrowser
for help on using the repository browser.