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 | |
---|
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 | ) or pod2usage(); |
---|
24 | |
---|
25 | =head1 OPTIONS |
---|
26 | |
---|
27 | =over 4 |
---|
28 | |
---|
29 | =item -c|--config configdir |
---|
30 | |
---|
31 | Use this configuration directory instead of the default one. |
---|
32 | |
---|
33 | =item -b|--base basename |
---|
34 | |
---|
35 | Query this specific base instead of the default one. |
---|
36 | |
---|
37 | =back |
---|
38 | |
---|
39 | =cut |
---|
40 | |
---|
41 | if (!$ARGV[0]) { |
---|
42 | warn "You must specify a file to load\n"; |
---|
43 | pod2usage(); |
---|
44 | } |
---|
45 | |
---|
46 | my $LA = LATMOS::Accounts->new($config, noacl => 1); |
---|
47 | my $labase = $base ? $LA->base($base) : $LA->default_base; |
---|
48 | $labase && $labase->load or die "Cannot load base"; |
---|
49 | $labase->wexported(1); |
---|
50 | |
---|
51 | open my $fh, "<:encoding(utf8)", $ARGV[0] or die "$ARGV[0]: $!"; |
---|
52 | |
---|
53 | my $csv = Text::CSV_XS->new(); |
---|
54 | |
---|
55 | while (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; |
---|
71 | print "Load terminated w/o error\n"; |
---|
72 | exit 0; |
---|
Note: See
TracBrowser
for help on using the repository browser.