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

Re: Debian source code statistics computed weekly

Lars Wirzenius wrote:
> I put my script that computes source code statistics in my
> crontab, and it is now run weekly. The results are published at
> <http://hibase.cs.hut.fi/~liw/debian-stats/>. I hope they can be of
> some amusement.

Vaguely related, I wrote a program last night that takes a debian source
mirror and scrolls every line of source code in it, displaying a line count
and info about the current package and file being displayed at the top (or
in the xterm title bar). I'm thinking about running this on a monitor at
linuxworld expo.

I wonder how long it will take to run all the way through...

see shy jo

# Displays the source to debian packages.
# Pass it the .dsc files of the packages, or exisiting directories with
# unpacked packages in them to display.

# copright: GPL 1999 Joey Hess

my $linecount=0;
my $package='';

use File::Find;
use Getopt::Long;

my ($insplitvt, $delay, $setup_only, $interval, $title)='';

my $ret=GetOptions(
	"insplitvt", \$insplitvt,
	"delay=f", \$delay,
	"setup", \$setup_only,
	"interval=i", \$interval,
	"title=s", \$title

$interval = 100 unless $interval;

if (! $ret) {
	print <<eof;
Usage: $0 [options] [dscs|dirs]
        --delay=x       Pause x seconds after each line.
                        Can specify delays with millisecond resolution.
	--setup		Unpack .dsc files into current directory, so that
			$0 can be pointed at the resulting directories later.
	--interval=x    Update the line count after this many lines.
	--title=text	The text is printed before the number of lines in the
	dscs		Debian source package .dsc files to unpack and display.
	dirs		Unpacked package directories to display.

if (! $setup_only && $ENV{DISPLAY} eq '') {
	# use splitvt.
	if ($insplitvt) {
		# Running as child process.
		open (OUT,">>$outfile");
		select OUT;
		select STDOUT;
	else {
		# File has to be there already for tail.
		open (OUT,">/tmp/scroller.$$");
		print OUT "Starting up...\n";
		close OUT;
		# Startup splitvt with child process.
		if ($delay) {
		exec 'splitvt','-s','2','-f',
			'-upper',"tail -f /tmp/scroller.$$",
			'-lower',"$0 -insplitvt /tmp/scroller.$$ $delay @ARGV";

foreach $item (@ARGV) {
	if (-f $item) {
		($package) = $item=~ m#(?:.*/)?(.*?)_#;
		mkdir "$package-tmp.$$", 0755 || die "mkdir: $!\n";
		chdir "$package-tmp.$$" || die "chdir: $!\n"; 
		system "dpkg-source","-x",$item;
		find(\&display, '.') unless $setup_only;
		chdir "..";
		system "rm -rf $package-tmp.$$ &" unless $setup_only;
		system "rm -f $package-tmp.$$/*.tar.gz" if $setup_only;
	elsif (-d $item) {
		($package) = $item=~ m#(?:.*/)?(.*)-#;
		find(\&display, $item) unless $setup_only;

sub display {
	if ((/\.(c|h|cc|cpp|py|s|S|scm|tcl|el|f|p|pas|pl|sh)$/i || 
	     /^(rules|Makefile)$/i) && -f && -T) {
		my $f=$_;
		open (F,$f);
		while (<F>) {
			if (int($linecount / $interval) * $interval == $linecount) {
			print $_;
			if ($delay) {
		close F;

sub status {
	if ($ENV{DISPLAY}) {
		print "\033]0;$title lines: $_[2] package: $_[0] file: $_[1]\007";
	else {
		print OUT "$title lines: $_[2] package: $_[0] file: $_[1]\n";

Reply to: