source: branches/1.0/LATMOS-Accounts/bin/la-graph.pl @ 1341

Last change on this file since 1341 was 457, checked in by nanardon, 15 years ago
  • add options to not load acls, command line tools are superuser command, then skip acls checks
  • Property svn:executable set to *
File size: 1.5 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 configfile
33
34Use this configuration file 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 = $base ? $LA->base($base) : $LA->default_base;
46$labase && $labase->load or die "Cannot load base";
47
48my $g = GraphViz->new(
49    layout => 'neato',
50    concentrate => 1,
51    overlap => 'compress',
52    ratio => 'compress',
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;
62
63foreach my $gr ($labase->list_objects('group')) {
64    my $o = $labase->get_object('group', $gr);
65    ($o->get_c_field('sutype') || '') =~ /^(dpmt|cell)$/ or next;
66    $g->add_node($gr,fillcolor => 'red', style => 'filled');
67    foreach ($o->get_attributes('member')) {
68        $users{$_} or do {
69            $users{$_} = 1;
70            $g->add_node($_);
71        };
72        warn "$_ => $gr";
73        $g->add_edge($_ => $gr);
74    }
75}
76
77print $h $g->as_png;
78close($h);
Note: See TracBrowser for help on using the repository browser.