source: LATMOS-Accounts/bin/la-sql-loadatt @ 981

Last change on this file since 981 was 861, checked in by nanardon, 13 years ago
  • reimport missing files from previous svn
  • 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) or pod2usage();
24
25=head1 OPTIONS
26
27=over 4
28
29=item -c|--config configdir
30
31Use this configuration directory instead of the default one.
32
33=item -b|--base basename
34
35Query this specific base instead of the default one.
36
37=back
38
39=cut
40
41if (!$ARGV[0]) {
42    warn "You must specify a file to load\n";
43    pod2usage();
44}
45
46my $LA = LATMOS::Accounts->new($config, noacl => 1);
47my $labase = $base ? $LA->base($base) : $LA->default_base;
48$labase && $labase->load or die "Cannot load base";
49$labase->wexported(1);
50
51open my $fh, "<:encoding(utf8)", $ARGV[0] or die "$ARGV[0]: $!";
52
53my $csv = Text::CSV_XS->new();
54
55while (my $row = $csv->getline($fh)) {
56    my ($otype, $attribute, $comment) = @$row;
57    if ($labase->attribute($otype, $attribute)) {
58    } else {
59        $labase->register_attribute($otype, $attribute, $comment)
60            or die "Error, aborting\n";
61        print "Attr. $attribute for object type $otype registred\n";
62    }
63}
64
65$csv->eof or do {
66    $csv->error_diag();
67    die "Cannot load attribute\n"
68};
69
70$labase->commit;
71print "Load terminated w/o error\n";
72exit 0;
Note: See TracBrowser for help on using the repository browser.