Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:00

0001 #!/usr/bin/env perl
0002 
0003 #
0004 # Generates ER diagrams from configuration files
0005 #
0006 # Use dumpRelationships from an sqlplus session to generate the input files
0007 # then run this script to generate the diagram as .dot and .png file
0008 #
0009 # Author: Giovanni.Organtini@roma1.infn.it 2011
0010 #
0011 
0012 use GraphViz;
0013 
0014 my $g = GraphViz->new(rankdir => 1);
0015 
0016 # read tables
0017 
0018 open IN, "TABLES.DAT";
0019 @buffer = <IN>;
0020 close IN;
0021 
0022 $lastTable = 'NONE';
0023 @columns;
0024 foreach $line (@buffer) {
0025     chomp $line;
0026     ($table, $column) = split / +/,$line;
0027     $column =~ s/\t*//g;
0028     $table =~ s/\t*//g;
0029     if ($table !~ m/$lastTable/) {
0030     $lastTable = $table;
0031     }
0032     push @columns, $table . "%" . $column;
0033 }
0034 
0035 $lastTable = 'NONE';
0036 $p = 1;
0037 %port;
0038 foreach $col (@columns) {
0039     ($table, $column) = split /%/, $col;
0040     $name = $table . "." . $column;
0041     if ($table !~ m/$lastTable/) {
0042     print "Creating node $table\n";
0043     if ($lastTable !~ m/NONE/) {
0044         $g->add_node($lastTable, label => \@label, shape => 'record', fontsize => 10, @default_attrs);  
0045     }
0046     @label = ();
0047     $p = 1;
0048     push @label, $table;
0049     $lastTable = $table;
0050     }
0051     $port{$name} = $p++;
0052     push @label, $column;
0053 }
0054 
0055 # read relationsips
0056 
0057 open IN, "RELATIONSHIPS.DAT";
0058 @buffer = <IN>;
0059 close IN;
0060 
0061 foreach $line (@buffer) {
0062     chomp $line;
0063     ($part, $parc, $chit, $chic) = split / +/, $line;
0064     $part =~ s/\t+//g;
0065     $parc =~ s/\t+//g;
0066     $chit =~ s/\t+//g;
0067     $chic =~ s/\t+//g;
0068     $parent = $part . "." . $parc;
0069     $child = $chit . "." . $chic;
0070     print "$parent -> $child\n";
0071     $g->add_edge($part => $chit, from_port => $port{$parent}, to_port => $port{$child},
0072     minlen => 10);
0073 }
0074 
0075 $g->as_png('test.png');
0076 $g->as_text('test.dot');