Update of /cvsroot/leaf/src/bering-uclibc/buildtool/tools
In directory sc8-pr-cvs1:/tmp/cvs-serv22414

Added Files:
        genpage.pl packages.conf 
Log Message:
Added script to generate PHPWebsite packages page from the content of .help and 
.version files in CVS
The script is not quite ready yet and it generates a full HTML page rather than just 
the part needed for PHPWebsite, so use it for testing only!


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

use strict;
use warnings;

# INCLUDES
use Getopt::Long;
use Config::General;
use Data::Dumper;
use File::Spec;
use File::Path;
use File::Temp;
use Carp;
use Symbol;

my $tempDir;

# prototype - needed because of the recursion
sub getLrpList($$);
sub getLrpList($$) {
        my ($current_dir, $p_h_files) = @_;;


        # Get the contents.
        my $dirFH = Symbol::gensym();

        if (! opendir($dirFH, $current_dir)) {
                confess("Can't opendir (" . $current_dir . "). $!");
        }

        my @files = readdir($dirFH);
        closedir($dirFH);

        foreach my $file (@files) {
                next if $file eq '.' || $file eq '..';
                my $filename = File::Spec->catdir($current_dir, $file);



                if (-d File::Spec->catdir($current_dir, $file)) {
                        getLrpList(
                                                $filename,
                                                $p_h_files
                                        );
                } else {

                        if ($file =~ /(.*)\.lrp$/) {
                                my $package = $1;
                                $p_h_files->{$package} = {};
                                $p_h_files->{$package}->{'FILENAME'} = $filename;
                                $p_h_files->{$package}->{'TYPE'} = 'FILE';
                        }
                }
        }
}

sub prepareTempDir()
{
        eval {
                $tempDir = File::Temp::tempdir(
                                        'PACKAGE_TEMP_XXXX',
                                        'TMPDIR' => 1
                                );
        };
        if ($@ ne '') {
                confess("Unable to create temporary directory. $@");
        }
}

sub cleanTempDir() {
        confess("Temp dir undefined") unless defined($tempDir);
        confess("Will not delete root dir") if File::Spec->canonpath($tempDir) eq 
File::Spec->rootdir();
        system("rm -rf $tempDir");
        rmdir($tempDir);
}

sub readFile($) {
        my ($name) = @_;
        my $lines = [];
        my $line ;

        my $hInputFile     = Symbol::gensym();

        open($hInputFile,$name) or return [];


        $line = '';
        while($line = <$hInputFile>){
                # stop on the first blank line
                last if ($line =~ /^\s*$/ );

                # trim trailing spaces
                $line =~ s/\s+$/\n/;
                push(@{$lines},$line);

        }
        close($hInputFile);
        return $lines;

}

=head2 escape($$$)

 from XML::Generator
 escape the provided string to conform to HTML or XML standards


=cut

sub escape($;$$) {
        my ($argument, $quoteFlag, $alwaysFlag)= @_;

        return unless defined $argument;

        $quoteFlag = 1 unless defined($quoteFlag) ;
        $alwaysFlag = 1 unless defined($alwaysFlag);

        if ($alwaysFlag) {
                $argument =~ s/&/&amp;/g;  # & first of course
                $argument =~ s/</&lt;/g;
                $argument =~ s/>/&gt;/g;
                $argument =~ s/"/&quot;/g if $quoteFlag; # "
        } else {
                $argument =~ s/([^\\]|^)&/$1&amp;/g;
                $argument =~ s/\\&/&/g;
                $argument =~ s/([^\\]|^)</$1&lt;/g;
                $argument =~ s/\\</</g;
                $argument =~ s/([^\\]|^)>/$1&gt;/g;
                $argument =~ s/\\>/>/g;
                $argument =~ s/([^\\]|^)"/$1&quot;/g if $quoteFlag;     # "
                $argument =~ s/\\"/"/g if $quoteFlag;                           # "
        }

        return($argument);
}


sub replaceLinks($) {
        my ($string) = @_;

        $string =~ s/(http:\/\/[^\s<]*)/<A HREF="$1">$1<\/A>/g;
        $string =~ s/(ftp:\/\/[^\s<]*)/<A HREF="$1">$1<\/A>/g;

        return($string);
}

my $Usage =
qq{$0: --version=uclibc-version [--directory=directory_of_lrps]
 version   Version of uclibc to use (0.9.15, 0.9.20)
 directory Directory where the lrps reside (overrides setting in config)
};

my $options = {};
my $sourceDir;

Getopt::Long::GetOptions(       $options,
                                                        'version=s',
                                                        'directory=s'
                                                        )       or die $Usage;

die $Usage unless exists($options->{'version'});
$sourceDir = $options->{'directory'} if exists($options->{'directory'});

# MAIN
#fetch the buildtool config
my $packageConfig= new Config::General(
                        "-ConfigFile" => 'packages.conf',
                        "-LowerCaseNames" => 1,
                        "-ExtendedAccess"=> 1
                );


my $p_h_template;


$packageConfig = $packageConfig->value('config');

my $head = $packageConfig->{'body_head'} if exists($packageConfig->{'body_head'});
my $foot = $packageConfig->{'body_foot'} if exists($packageConfig->{'body_foot'});

my $p_h_packages_to_skip = {};
foreach my $pkg (split(/,/,$packageConfig->{'packages_to_skip'})){
        $p_h_packages_to_skip->{$pkg} = 1;
}

foreach my $item (@{$packageConfig->{'package_template'}}) {
        next unless $item->{'version'} eq $options->{'version'};
        $p_h_template= $item;
        $p_h_template->{'source'} = $sourceDir if defined($sourceDir);
        last;
}

die "Version " . $options->{'version'} ." not found in packages.conf" unless 
defined($p_h_template);


# overwrite version specific settings, if they were specified
$head = $p_h_template->{'body_head'} if exists($p_h_template->{'body_head'});
$foot = $p_h_template->{'body_foot'} if exists($p_h_template->{'body_foot'});


my $p_h_files = {};
getLrpList($p_h_template->{'source'}, $p_h_files);

prepareTempDir();

my $lines = [];
foreach my $package (sort keys %{$p_h_files}) {
        # skip initrd, initrd_ide and so on
        next if exists($p_h_packages_to_skip->{$package});

        my $item = $packageConfig->{'item'} if exists($packageConfig->{'item'});
        $item = $p_h_template->{'item'} if exists($p_h_template->{'item'});
        die "no config for 'item'" unless defined($item);

        my $file = $p_h_files->{$package}->{'FILENAME'};
        my $link = $p_h_template->{'link'};

        my $command = "tar xvfz $file -C $tempDir 2>&1 > /dev/null ";
        #print STDERR "$command\n";
        my $retVal = system($command);
        if ($retVal>>8 != 0 ) {
                cleanTempDir();
                confess("Extracting $file failed. $!");
        }

        my $p_l_packageVersion ;
        my $p_l_packageHelp ;

#use Data::Dumper;
#my $dumper = Data::Dumper->new([$packageConfig->value('package_template')]);
#$dumper->Indent(1);
#print STDERR  $dumper->Dumpxs(), "\n";
#print STDERR  "\n\n$package\n";

        if (    exists($p_h_template->{'overrides'}) &&
                        exists($p_h_template->{'overrides'}->{$package}) &&
                        exists($p_h_template->{'overrides'}->{$package}->{'help'})) {
                $p_l_packageHelp = 
[split(/\n/,$p_h_template->{'overrides'}->{$package}->{'help'})];
        } else {

                $p_l_packageHelp = readFile(File::Spec->catfile($tempDir, "var", 
"lib","lrpkg",$package.".help"));
        }

        if (    exists($p_h_template->{'overrides'}) &&
                        exists($p_h_template->{'overrides'}->{$package}) &&
                        exists($p_h_template->{'overrides'}->{$package}->{'version'})) 
{
                $p_l_packageVersion = 
[split(/\n/,$p_h_template->{'overrides'}->{$package}->{'version'})];
        } else {
                $p_l_packageVersion = readFile(File::Spec->catfile($tempDir, "var", 
"lib","lrpkg",$package.".version"));
        }

        #print STDERR join("", @{$p_l_packageHelp});
        my $packageHelp = '';
        my $packageVersion = '';
        foreach my $line (@{$p_l_packageHelp}) {
                #print STDERR $line . "\n";
                $line = escape($line);
                $line =~ s/(LEAF package by)/<BR \/>$1/gs;
                $line =~ s/^(.{1,60})$/$1 <BR \/>/ig;
                $line =~ s/^\s+(.*)(?<!<BR \/>)$/$1 <BR \/>/ig;

                $line = replaceLinks($line);

                # pretend what's followed by "Requires:" is a list of links
                # for this to work, "Requires: needs to be followed by a whitespace 
delimited list of package names (with or without the ".lrp").
                if ($line =~ /(\s*Requires:*\s+)([^<]*)(.*)/ig) {
                        my $newLine = $1;
                        my $pkgs = $2;
                        my $suffix = $3;
                        my $tmpLink = $link;

                        foreach my $dependency (split(/\s+/,$pkgs)) {
                                my $tmpLink = $link;
                                if ($dependency =~ /(.*)\.lrp/ig) {
                                        $dependency =~ /(.*)\.lrp/ig;
                                        $dependency=$1;
                                }

                                $tmpLink =~ s/__PACKAGE_NAME__/$dependency/ig;
                                $newLine .= qq{<A HREF="$tmpLink">$dependency.lrp</A> 
};
                        }
                        $line = $newLine . $suffix;
                }
                $packageHelp.=$line;
        }

        foreach my $line (@{$p_l_packageVersion}) {
                #print STDERR $line . "\n";
                $line = escape($line);
                $packageVersion.=$line;
        }
        $packageVersion = replaceLinks($packageVersion);



        $link =~ s/__PACKAGE_NAME__/$package/ig;
        $link =~ s/__HELP__/$packageHelp/ig;
        $link =~ s/__VERSION__/$packageVersion/ig;

        $item =~ s/__LINK__/$link/ig;
        $item =~ s/__PACKAGE_NAME__/$package/ig;
        $item =~ s/__HELP__/$packageHelp/ig;
        $item =~ s/__VERSION__/$packageVersion/ig;

        # Clean up unnecessary <BR /> tags
        $item =~ s/(<BR \/>\s*)+/<BR \/>/igs;
        $item =~ s/(<p>\s*<BR \/>)+/<p>/igs;

        # format the code, to make it more readable
        $item =~ s/\s*<BR \/>/<BR \/>\n/igs;
        $item .="\n";

        push(@{$lines},$item);

}
cleanTempDir();


print
"<html><body>".
$head . join('', @{$lines}) . $foot . "\n" .
"</body></html>\n";

exit;

__END__



--- NEW FILE: packages.conf ---
<config>
        packages_to_skip=initrd,initrd_ide,initrd_ide_cd
        
        item <<EOF_ITEM
                <li>
                <a href="__LINK__">__PACKAGE_NAME__.lrp</a> 
                <p>__HELP__
                </p><p>Version: __VERSION__</p><BR />
                </li>
                EOF_ITEM

        body_foot <<EOF_FOOT
                </ol></td></tr><tr><td class="type5" width="90%" valign="top">
                </td></tr><tr><td class="type5" width="90%" valign="top">
                </td></tr></table>
                </div><br /></td>
                </tr>
                </table>
                EOF_FOOT

<package_template>
        version=0.9.15
        source=../../../../bin/packages/uclibc-0.9/15

        
link=http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/leaf/bin/packages/uclibc-0.9/15/__PACKAGE_NAME__.lrp?rev=HEAD&amp;content-type=application/octet-stream

        intro <<EOF_HEAD
                <table width="100%" border="0" cellspacing="1" cellpadding="3">
                <tr>
                <td><div class="mainblock"><span class="title"><b>Additional packages 
for Bering-uClibc 1.x</b></span>
                <br /><table width="100%">
                <tr><td class="type5" width="90%" valign="top">
                <br /><p>In this section you can find a list of packages that are 
already
                converted to uClibc 0.9.15. These packages are mostly derived from the 
original
                LRP's, where the programs in those packages are upgraded from their
                latest sources (and patches) and rebuilt against uClibc-0.9.15.</p>
                <p><b>Please note: These packages are only for Bering-uClibc versions 
1.x</b>
                </p>
                <p>List of packages:</p>
                <ol>
                EOF_HEAD



</package_template>

<package_template>
        version=0.9.20
        source=../../../../bin/packages/uclibc-0.9/20


        
link=http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/leaf/bin/packages/uclibc-0.9/20/__PACKAGE_NAME__.lrp?rev=HEAD&amp;content-type=application/octet-stream

        body_head <<EOF_HEAD
                <table width="100%" border="0" cellspacing="1" cellpadding="3">
                <tr>
                        <td><div class="mainblock"><span class="title"><b>Additional 
packages for Bering-uClibc 2.x</b></span>
                        <br /><table width="100%">

                <tr><td class="type5" width="90%" valign="top">
                <br /><p>In this section you can find a list of packages that are 
already
                converted to uClibc 0.9.20. These packages are mostly derived from the 
original
                LRP's, where the programs in those packages are upgraded from their
                latest sources (and patches) and rebuild against uClibc-0.9.20.</p>
                <p><b>Please note: These packages are only for Bering-uClibc versions 
2.0 and above.</b>
                </p>
                <p>List of packages:</p>
                <ol>
                EOF_HEAD

# Comment these in to override the global setting above
#       body_foot <<EOF_FOOT
#               </ol></td></tr><tr><td class="type5" width="90%" valign="top">
#               </td></tr><tr><td class="type5" width="90%" valign="top">
#               </td></tr></table>
#               </div><br /></td>
#               </tr>
#               </table>
#               EOF_FOOT
#
#
#       item <<EOF_ITEM
#               <li>
#               <a href="__LINK__">__PACKAGE_NAME__.lrp</a> 
#               <p>__HELP__
#               <BR />Version: __VERSION__</p><BR />
#               </li>
#               EOF_ITEM
#               
        <overrides>
                <netstatn>
                        HELP <<EOF_NETSTATN_HELP
                                Netstat-nat is a small program written in C. It 
displays NAT connections, managed by netfilter/iptables which comes with the > 2.4.x 
linux kernels. The program reads its information from '/proc/net/ip_conntrack', which 
is the temporary conntrack-storage of netfilter. 
                                
                                See http://tweegy.demon.nl/projects/netstat-nat
                        EOF_NETSTATN_HELP
                        VERSION=1.4.1
                </netstatn>

        </overrides>
</package_template>
</config>



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Leaf-cvs-commits mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/leaf-cvs-commits

Reply via email to