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

Last change on this file since 575 was 575, checked in by nanardon, 15 years ago
  • properly get main address, department and cells
  • Property svn:executable set to *
File size: 4.3 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
27    # warn (join(' - ', map { $_ => $passwd[$_] } 0 ..$#passwd));
28    my @epo;
29
30    my $login = $passwd[27]; 
31    warn $login . ' ' . scalar(@passwd);
32    my $obj = $labase->get_object($otype, $login) or do {
33        warn "Cannot get $login user";
34        #warn $line . "\n";
35        next;
36    };
37    my %changes;
38
39    { # le nom/ prénom
40        $changes{sn} = $passwd[0];
41        $changes{sn} =~ s/_/ /g;
42        if ($passwd[1] ne 'Compte-de-service') {
43            $changes{givenName} = $passwd[1];
44            $changes{givenName} =~ s/_/ /g;
45        }
46        if ($passwd[10] =~ /^NICK(.*)$/) {
47            if ($1 eq 'zzz') {
48            $changes{nickname} = undef;
49            } else { $changes{nickname} = $1 }
50        }
51
52        if ($passwd[1] ne 'Compte-de-service') {
53            $changes{mail} = $passwd[13];
54            $changes{mail} =~ s/cetp.ipsl.fr/latmos.ipsl.fr/;
55        }
56    }
57
58    { # address, a bit more complex
59        # trash old
60        foreach ($obj->get_attributes('otheraddress')) {
61            $labase->delete_object('address', $_);
62        }
63
64
65        if ($passwd[1] ne 'Compte-de-service') {
66        foreach my $col (3, 5, 7) {
67            if($passwd[$col] ne 'AJETER') {
68                my %param = (user => $obj->id,);
69                $passwd[$col] =~ /^(SAV|SAJ|vel|StM|GY)-(.*)/i or do {
70                    warn "unknown $passwd[$col]";
71                    next;
72                };
73                my $eposite = $1;
74                $param{physicalDeliveryOfficeName} = $2;
75                $param{telephoneNumber} = '+33 1 ' . $passwd[$col + 5];
76
77                for ($eposite) {
78                    /^SAV$/i and do {
79                        $param{site} = 'VerriÚres';
80                        $passwd[18] =~ /aerov/ and $param{isMainAddress} = 1;
81                        last;
82                    };
83                    /^Vel$/i and do {
84                        $param{site} = 'Vélizy';
85                        $passwd[18] =~ /cetp/ and $param{isMainAddress} = 1;
86                        last;
87                    };
88                    /^Stm$/i and do {
89                        $param{site} = 'St Maur';
90                        last;
91                    };
92                    /^SAJ$/i and do {
93                        $param{site} = 'Jussieu';
94                        $passwd[18] =~ /aero$/ and $param{isMainAddress} = 1;
95                        last;
96                    };
97                    /^GY$/i and do {
98                        $param{site} = 'Guyancourt';
99                        # is not main address at time
100                        last;
101                    };
102                    warn "unmanaged $eposite";
103                }
104                $labase->create_object(
105                    'address',
106                    $obj->id . '-' . $eposite,
107                    %param
108                );
109            }
110        }
111        $passwd[16] =~ /^T(\d\d\d\d)(\d\d)(\d\d)$/ and do {
112            if($1 < 2100) {
113                $changes{expire} = "$3/$2/$1 23:59:59";
114            } else {
115                $changes{expire} = undef;
116            }
117        };
118        $passwd[22] =~ /^GRADE(.*)/ and do {
119            $changes{grade} = $1;
120        };
121        } # Not compte-de-service
122        else {
123            $changes{grade} = undef,
124            $changes{expire} = undef;
125            $changes{description} = "$passwd[1] $passwd[0]";
126        }
127    }
128
129    {
130        my @group = @{ $obj->get_c_field('memberOf') || []};
131        foreach (split('DOM', $passwd[19])) {
132            $_ or next;
133            $changes{department} ||= $_;
134            push @group, $_;
135            next;
136        }
137        foreach (split('CEL', $passwd[20])) {
138            $_ or next;
139            push @group, $_;
140        }
141        $changes{'memberOf'} = \@group;
142    }
143
144    keys %changes or next;
145    $obj->set_c_fields(%changes);
146    $labase->commit;
147}
Note: See TracBrowser for help on using the repository browser.