source: trunk/LATMOS-Accounts/bin/la-graph.pl @ 2380

Last change on this file since 2380 was 1044, checked in by nanardon, 12 years ago

Kill redundant LATMOS::Account::default_base()

Use $LA->base(undef) to get default base instead

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1#!/bin/env perl
2
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use Getopt::Long;
7use Pod::Usage;
8use LATMOS::Accounts::Utils;
9use LATMOS::Accounts::Log;
10use GraphViz;
11
12=head1 NAME
13
14    la-group -- Graph user/cells-department
15
16=head1 SYNOPSIS
17
18    la-group [options]
19
20=cut
21
22GetOptions(
23    'c|config=s' => \my $config,
24    'b|base=s'   => \my $base,
25    'help'       => sub { pod2usage(0) },
26) or pod2usage();
27
28=head1 OPTIONS
29
30=over 4
31
32=item -c|--config configdir
33
34Use this configuration directory instead the default one
35
36=item -b|--base basename
37
38Query this specific base instead default.
39
40=back
41
42=cut
43
44my $LA = LATMOS::Accounts->new($config, noacl => 1);
45my $labase = $LA->base($base);
46$labase && $labase->load or die "Cannot load base";
47
48my $g = GraphViz->new(
49    layout => 'dot',
50    overlap => 'false',
51    rankdir => 1,
52    width => 10, height => 8,
53);
54
55open(my $h, '>', 'graph.png') or die 'cannot open graph';
56
57#foreach ($labase->list_objects('user')) {
58#    $g->add_node($_);
59#}
60
61my %users;
62my %cluster;
63
64sub add_user {
65    my ($user) = @_;
66    $users{$user} and return;
67    my $ou = $labase->get_object('user', $user) or return;
68    my $dpmt = $ou->get_attributes('department');
69    if ($dpmt) {
70        $cluster{$dpmt} ||= {
71            name => $dpmt,
72        };
73    }
74    $g->add_node($user, ($dpmt ? (cluster => $cluster{$dpmt}) : ()));
75    1;
76}
77
78$g->add_node('latmos');
79foreach my $gr ($labase->list_objects('group')) {
80    my $o = $labase->get_object('group', $gr);
81    my $sutype = $o->get_c_field('sutype');
82    ($sutype || '') =~ /^(dpmt|cell)$/ or next;
83    $g->add_node($gr,fillcolor => ($sutype eq 'dpmt' ? 'red' : 'green'), style => 'filled');
84    my $manager = $o->get_attributes('managedBy') || '';
85    warn "MANAGER $manager";
86    if ($manager) {
87        add_user($manager);
88        $g->add_edge('latmos', $gr);
89        $g->add_edge($manager => $gr, weight => 3);
90    }
91    foreach ($o->get_attributes('member')) {
92        $_ eq $manager and next;
93        add_user($_);
94        warn "$_ => $gr";
95        $g->add_edge($gr => $_, weight => 1);
96    }
97}
98
99print $h $g->as_png;
100close($h);
Note: See TracBrowser for help on using the repository browser.