source: LATMOS-Accounts/import/epo.pl @ 569

Last change on this file since 569 was 569, checked in by nanardon, 15 years ago
  • new data, new format...
  • Property svn:executable set to *
File size: 3.8 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use Getopt::Long;
7use Pod::Usage;
8
9GetOptions(
10    'c|config=s' => \my $config,
11    'b|base=s'   => \my $base,
12) or pod2usage();
13
14my $otype ||= 'user';
15
16my $LA = LATMOS::Accounts->new($config, noacl => 1);
17my $labase = $base ? $LA->base($base) : $LA->default_base;
18$labase->{wexported} = 1;
19$labase && $labase->load or die "Cannot load base";
20
21while (my $line = <STDIN>) {
22
23    chomp($line);
24
25    my @passwd = split("\t", $line);
26    # warn (join(' - ', map { $_ => $passwd[$_] } 0 ..$#passwd));
27    my @epo;
28
29    my $login = {
30        clerbaux => 'ccl',
31        cgranier => 'clg',
32        vernier => 'jeanpaul82',
33    }->{$passwd[27]} || $passwd[27];
34    my $obj = $labase->get_object($otype, $login) or do {
35        warn "Cannot get $login user";
36        #warn $line . "\n";
37        next;
38    };
39    my %changes;
40
41    { # le nom/ prénom
42        $changes{sn} = $passwd[0];
43        $changes{sn} =~ s/_/ /g;
44        $changes{givenName} = $passwd[1];
45        $changes{givenName} =~ s/_/ /g;
46        if ($passwd[10] =~ /^NICK(.*)$/) {
47            if ($1 eq 'zzz') {
48            $changes{nickname} = undef;
49            } else { $changes{nickname} = $1 }
50        }
51        $changes{mail} = $passwd[9];
52        $changes{mail} =~ s/cetp.ipsl.fr/latmos.ipsl.fr/;
53    }
54
55    { # address, a bit more complex
56        # trash old
57        foreach ($obj->get_attributes('otheraddress')) {
58            $labase->delete_object('address', $_);
59        }
60
61
62        foreach my $col (3, 5, 7) {
63            if($passwd[$col] ne 'AJETER') {
64                my %param = (user => $obj->id,);
65                $passwd[$col] =~ /^(SAV|SAJ|vel|StM|GY)-(.*)/i or do {
66                    warn "unknown $passwd[$col]";
67                    next;
68                };
69                my $eposite = $1;
70                $param{physicalDeliveryOfficeName} = $2;
71                $param{telephoneNumber} = '+33 1 ' . $passwd[$col + 5];
72
73                for ($eposite) {
74                    /^SAV$/i and do {
75                        $param{site} = 'VerriÚres';
76                        $passwd[14] =~ /aerov/ and $param{isMainAddress} = 1;
77                        last;
78                    };
79                    /^Vel$/i and do {
80                        $param{site} = 'Vélizy';
81                        $passwd[14] =~ /cetp/ and $param{isMainAddress} = 1;
82                        last;
83                    };
84                    /^Stm$/i and do {
85                        $param{site} = 'St Maur';
86                        last;
87                    };
88                    /^SAJ$/i and do {
89                        $param{site} = 'Jussieu';
90                        $passwd[14] =~ /aero$/ and $param{isMainAddress} = 1;
91                        last;
92                    };
93                    /^GY$/i and do {
94                        $param{site} = 'Guyancourt';
95                        # is not main address at time
96                        last;
97                    };
98                    warn "unmanaged $eposite";
99                }
100                $labase->create_object(
101                    'address',
102                    $obj->id . '-' . $eposite,
103                    %param
104                );
105            }
106        }
107        $passwd[16] =~ /^T(\d\d\d\d)(\d\d)(\d\d)$/ and do {
108            if($1 < 2100) {
109                $changes{expire} = "$3/$2/$1 23:59:59";
110            } else {
111                $changes{expire} = undef;
112            }
113        };
114        $passwd[22] =~ /^GRADE(.*)/ and do {
115            $changes{grade} = $1;
116        };
117    }
118
119    {
120        my @group = @{ $obj->get_c_field('memberOf') || []};
121        foreach ($passwd[20] =~ /^DOM(.*)/g) {
122            $changes{departement} = '$1';
123            push @group, $1;
124            next;
125        }
126        $changes{'memberOf'} = \@group;
127    }
128
129    keys %changes or next;
130    $obj->set_c_fields(%changes);
131}
132$labase->commit;
Note: See TracBrowser for help on using the repository browser.