[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Graph Private Woody Archives



In case in body is interested, I hacked out a Perl script that:

1. takes two Sources files, a Debian one (A), and one for a private
archive (B).

2. Using the information from (B) outputs a vcg nodelist (for producing
a graph in vcg) that shows build dependancies for the private archive.
(debhelper is a special case; I hardcoded it so it would not get
displayed, because there were too many build depedancies on it).

The build depends version information is totally ignored.

3. If the source code in B is older then A, it is displayed in red,
it is is newer then A, it is displayed in green.

The result? A graph that tells you at a glance which packages are out of
date in a private archive, and the order you should use to rebuild them.

So I can tell at a glance for instance in my archive that while acl is
out-of-date, I probably should rebuild attr first, because acl depends
on acl.

What is amazing is that it works. The code perhaps could be cleaner...

Comments?

Has anybody else done anything similar?
-- 
Brian May <bam@debian.org>
#!/usr/bin/perl -w
###############################################################################
#   Copyright (C) 2003 Brian May
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
###############################################################################
use strict;
use AptPkg::Config '$_config';
use AptPkg::System '$_system';
use AptPkg::Version;

my %binary_source;
my %debian_source_version;
my %source_version;
my %source_depends;
my $source=undef;
my $version=undef;

if ($#ARGV < 1) {
  die "Usage: sourcedepends Debian_Packages_File Source_File\n";
}
my $packages=shift;
my $sources=shift;

$_config->init;
$_system = $_config->system;
my $vs = $_system->versioning;

open(DEB_SOURCES,"<".$packages) or die "Cannot open packages $packages: $!\n";
while (<DEB_SOURCES>) {
  if (/^Package: ([\w\d\.\-\+]+)$/) {
    $source=$1;
  }
  elsif (defined($source) && /^Version: (.*)$/) {
    $debian_source_version{$source} = $1;
  }
  elsif (/^(Version): .*$/) {
    chomp($_);
    die "Unexpected tag: $_";
  }
  elsif (/^$/) {
    $source=undef;
  }
}
close (DEB_SOURCES) or die "Cannot close packages: $!\n";

open(SOURCES,"<".$sources) or die "Cannot open sources $sources: $!\n";
while (<SOURCES>) {
  if (/^Package: ([\w\d\.\-\+]+)$/) {
#    print "Package: $1\n";
    $source=$1;
    $source_depends{$source} = [];
  }
  elsif (defined($source) && /^Binary: ([\w\d\.\-\+, ]+)$/) {
    my @array=split(/,\s*/,$1);
#    print "Binary:",join('+',@array),"\n";
    foreach my $binary (@array) {
#      print "($source,$binary)\n";
      $binary_source{$binary} = $source;
    }
  }
  elsif (defined($source) && /^Build-Depends: (.+)$/) {
    my @array=split(/\s*[,\|]\s*/,$1);
#    print "Build-Depends:",join('+',@array),"\n";
    foreach my $binary (@array) {
      my ($name,$version) = ($binary =~ /^([\w\d\.\-\+]+)\s*(\(.*\))?\s*(\[.*\])?$/);
      $version = "" if (!defined($version));
#      print "($source,$name,$version)\n";
      push(@{$source_depends{$source}}, { $name => $version });
    }
  }
  elsif (defined($source) && /^Version: (.*)$/) {
    $source_version{$source} = $1;
  }
  elsif (/^(Package|Binary|Build-Depends|Version): .*$/) {
    chomp($_);
    die "Unexpected tag: $_";
  }
  elsif (/^$/) {
    $source=undef;
  }
}
close (SOURCES) or die "Cannot close sources: $!\n";

delete $source_version{"debhelper"};
delete $source_depends{"debhelper"};

print "graph: { title: \"Source Dependancies\"\n";
foreach $source (keys %source_depends) {
  my $version = $source_version{$source};
  my $debian_version = $debian_source_version{$source};

  my $color="white";
  if (!defined($debian_version)) {
    $color="green";
    $debian_version="N/A";
  } else {
    my $rc = $vs->compare($version, $debian_version);
    if ($rc < 0) {
      $color="red";
    } elsif ($rc>0) {
      $color="green";
    }
  }
  print "node: { title: \"$source\" label: \"$source $version ($debian_version)\" color: $color }\n";

  my %depends_source;

  foreach my $x (@{$source_depends{$source}}) {
    foreach my $depends_binary (keys %$x) {
      my $depends = $binary_source{$depends_binary};
      if (defined($depends)) {
	if (defined($source_depends{$depends})) {
	  $depends_source{$binary_source{$depends_binary}} = 1;
	}
      }
    }
  }

  foreach my $depends (keys %depends_source) {
    print "edge: { sourcename: \"$source\" targetname: \"$depends\" class: 2 }\n";
  }
}
print "}\n";

Reply to: