#! /usr/bin/perl # Generates index files from examples .meta file info. # Copyright (C) 2008-2015 Red Hat Inc. # # This file is part of systemtap, and is free software. You can # redistribute it and/or modify it under the terms of the GNU General # Public License (GPL); either version 2, or (at your option) any # later version. use strict; use warnings; use Cwd 'abs_path'; use File::Copy; use File::Find; use File::Path; use Text::Wrap; use HTML::Entities; use DBI; my $inputdir; if ($#ARGV >= 0) { $inputdir = $ARGV[0]; } else { $inputdir = "."; } $inputdir = abs_path($inputdir); # get current stap version open(PIPE, " $inputdir/../../configure -V |") or die ("can't find stap version"); my $version_line = ; $version_line =~ /systemtap configure (.*)/ or die ("can't parse configure -V"); my $version = "For systemtap version ${1}."; close(PIPE); my $outputdir; if ($#ARGV >= 1) { $outputdir = $ARGV[1]; } else { $outputdir = $inputdir; } $outputdir = abs_path($outputdir); our $driver = "SQLite"; our $database = "metadatabase.db"; our $dsn = "DBI:$driver:dbname=$database"; our $dbh = DBI->connect($dsn, "", "", { RaiseError => 1 }) or die $DBI::errstr; my $sqlcmd = $dbh->prepare('DELETE FROM metavirt'); $sqlcmd->execute(); my %scripts = (); print "Parsing .meta files in $inputdir...\n"; find(\&parse_meta_files, $inputdir); my $meta; my $keyword; my %keywords; $dbh->disconnect(); # Adds a formatted meta entry to a given file handle as text. sub add_meta_txt(*;$) { my($file,$meta) = @_; print $file "$scripts{$meta}{name} - $scripts{$meta}{title}\n"; # Don't output these, the description mentions all these in general. #print $file "output: $scripts{$meta}{output}, "; #print $file "exits: $scripts{$meta}{exit}, "; #print $file "status: $scripts{$meta}{status}\n"; print $file "keywords: $scripts{$meta}{keywords}\n"; $Text::Wrap::columns = 72; my $description = wrap(' ', ' ', $scripts{$meta}{description}); print $file "\n$description\n"; $Text::Wrap::separator = " \\\n"; my $usage = wrap('', ' ', $scripts{$meta}{test_installcheck}); if ($usage =~ /[a-z]/) { print $file "\n # $usage\n"; } $Text::Wrap::separator = "\n"; print $file "\n\n"; } # Adds a formatted meta entry to a given file handle as text. sub add_meta_html(*;$) { my($file,$meta) = @_; my $name = $scripts{$meta}{name}; print $file "$name "; print $file "- $scripts{$meta}{title}
\n"; # Don't output these, the description mentions all these in general. #print $file "output: $scripts{$meta}{output}, "; #print $file "exits: $scripts{$meta}{exit}, "; #print $file "status: $scripts{$meta}{status}
\n"; print $file "keywords: "; foreach $keyword (split(/ /, $scripts{$meta}{keywords})) { print $file '' . (uc $keyword) . " "; } print $file "
\n"; print $file "

".encode_entities($scripts{$meta}{description})."

"; my $txt = $name; $txt =~ s/.stp$/.txt/; if (-e $txt) { # prefer .txt file link print $file "

sample usage in $txt"; } else { $Text::Wrap::separator = " \\\n"; my $usage = wrap('', '', $scripts{$meta}{test_installcheck}); $Text::Wrap::separator = "\n"; if ($usage =~ /[a-z]/) { $usage = encode_entities($usage); print $file "

# $usage
"; } } print $file "

\n"; } my $HEADER = "SYSTEMTAP EXAMPLES INDEX\n" . "(see also keyword-index.txt)\n\n"; my $header_tmpl = "$inputdir/html/html_header.tmpl"; open(TEMPLATE, "<$header_tmpl") || die "couldn't open $header_tmpl, $!"; my $HTMLHEADER = do { local $/;