source: trunk/LATMOS-Accounts/bin/la-sql-loadatt @ 1254

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
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use Getopt::Long;
7use Pod::Usage;
8use 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
20GetOptions(
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
32Use this configuration directory instead of the default one.
33
34=item -b|--base basename
35
36Query this specific base instead of the default one.
37
38=back
39
40=cut
41
42if (!$ARGV[0]) {
43    warn "You must specify a file to load\n";
44    pod2usage();
45}
46
47my $LA = LATMOS::Accounts->new($config, noacl => 1);
48my $labase = $LA->base($base);
49$labase && $labase->load or die "Cannot load base";
50$labase->wexported(1);
51
52open my $fh, "<:encoding(utf8)", $ARGV[0] or die "$ARGV[0]: $!";
53
54my $csv = Text::CSV_XS->new();
55
56while (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;
72print "Load terminated w/o error\n";
73exit 0;
Note: See TracBrowser for help on using the repository browser.