CVS: brutus/elaine find.pl,NONE,1.1 makedeps.pl,NONE,1.1

elaine at lunar-linux.org elaine at lunar-linux.org
Thu Aug 21 03:05:47 GMT 2003


Update of /var/cvs/lunar/brutus/elaine
In directory dbguin.lunar-linux.org:/tmp/cvs-serv17789

Added Files:
	find.pl makedeps.pl 
Log Message:
Simple tools for extracting dependencies into db and searching db


--- NEW FILE: find.pl ---
#!/usr/bin/perl 

#######################################################################################
# 
#  v0.1
# Very crude required-dependency finder in perl 
# Works with Berkely DB file created by 'makedeps.pl'
# 
# Caveats:
# Full recursive search, no pruning and returns (many) duplicate deps.
# I think I want to record the deepest-found requirement and order the
# build deepest-found modules first
# 
# Needs some re-write, originally I intended to handle varrying numbers of
# input modules, and gave that up as too complex, however the structure
# is still there and needs to be removed.
# 
# Needs to be turned into a method, where the class handles dependency
# data in general and     depend->find is just one metod
# 
# "depends.db" data file hardcoded in src
#
# Usage:  find.pl all|module
# 
# 
# Todo: optimize-out duplicates while remembering the deepest-found instance
#       Add optional-depends handling, probably managed in a separate bdb file
#
#######################################################################################


use strict;
use DB_File;


my $level=0;
my @list;
sub find {

    $main'level++;
    my  ($get) = @_;
    print "Dbg: enter find $get depth= $main'level\n";
    my $infind; 
    my $item; 
    my $found;
    my $try;

    for $infind ($get) {
        if ($main'database{$infind} ne "") {
            for $try ($get) { 
                for $item (split " ", $main'database{$try}) {
                    unshift (@main'list, $item);
                    find ($item);
                }
            }

        $main'level--;
        return  $main'database{$found};
        }
        else{
            $main'level--;
            return;
        }          
    }
}


my %data;
my $db= tie ( %data , 'DB_File', 'depends.db',O_RDWR, 0666 ) or die "Can't open";
my $fd = $db->fd();
open DATAFILE, "+<&=$fd";

%main'database = %data;
my $tofind=shift;

if ($tofind ne "all"){
    print "finding $tofind\n";
    find ($tofind);
    print "Module $tofind: found @main'list\n";
}
else {
    for my $key (keys %data) {
        $#main'list = 0;
        find ($key);
        print "Module $key: found @main'list\n";
    }
}
    

print "found @main'list\n";
my $used=times();
print "User: $used\n";


--- NEW FILE: makedeps.pl ---
#!/usr/bin/perl

#######################################################################################
# 
# Very crude required-dependency db writer to extract the Lunar 1.x  moonbase
# dependencies into a perl hash accessible Berkely DB file.
# 
# Caveats: 
# at present this only manages required dependencies
# 
# Usage: find /path/to/moonbase -name 'DEPENDS' | sed 's/DEPENDS//' \
#          | grep -v CVS | ./makedeps.pl >/dev/null
#
#######################################################################################



use DB_File;
use Fcntl ':flock';

my %database ;
my $db= tie ( %database , 'DB_File', 'depends.db', O_CREAT | O_RDWR, 0666 ) or die "Can't open";

my $fd = $db->fd();
open DATAFILE, "+<&=$fd"
    or die "Can't safely open file: $!\n";
flock( DATAFILE, LOCK_EX )
    or die "Unable to acquire lock: $!. Aborting";
print "Acquired lock. Ready to update database!\n\n";

while (<>) {
    chop;
#    print "$_/DETAILS \n";
    open(DTL, "<$_/DETAILS") || die "can't open DETAILS $_/DETAILS ";
    open(DEP, "<$_/DEPENDS") || die "can't open DEPS";
    print "processing $_ : ";

    while ($_ = <DTL>) {
	if (/^\s*MODULE[S]*=/) {
	    chop;
	    ($nil, $module) = split /=/;
	    print "$module ";
	}
    }
    close DTL;
    $m_deps = "";
    print "DEPENDS:";
    while ($_ = <DEP>) {
	if (/^ *depend/) {
	    s/\"//g;
	    ($nil, $tdep, $nil) = split;
	    $tdep =~ s/\s//g ;
	    print " $tdep";
	    $m_deps .= "$tdep";
	    $m_deps .= ' ';
	}
	
    }
    close DEP;
    chop $m_deps;
    print "\n";
    $database{"$module"} = "$m_deps";
}

$db->sync;
close DATAFILE;

$stat=times();
print "$stat\n";




More information about the Lunar-commits mailing list