File: clean-filter

package info (click to toggle)
popularity-contest 1.61
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 536 kB
  • ctags: 76
  • sloc: perl: 1,139; sh: 284; python: 218; makefile: 42
file content (51 lines) | stat: -rwxr-xr-x 1,279 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/perl
#
# Author: Alain Schroeder
# Date:   2005-07-09
# Modified by Petter Reinholdtsen 2005-07-15


use strict;

my %table;
my $foundentry = 0;
my $ignorecount = 0;
my $debug = 0;

open (PACKAGES, '< packages') or
    die ("packages not found. please run clean-genpkglist first\n");

while (<PACKAGES>) {
    chomp;
    $table{$_} = "1";
}
close PACKAGES;

# Truncate timestamps to the start of the day, to avoid giving out
# timezone information.
sub fuzzy_timestamp {
    my $timestamp = shift;
    return 86400 * int($timestamp / 86400);
}

while (my $line = <STDIN>) {
    
    if ($line =~ m/^POPULARITY-CONTEST-0/i) {
	$foundentry = 1;
	$ignorecount = 0;
	$line =~ s/\b(TIME:)(\d+)\b/sprintf("%s%s", $1,fuzzy_timestamp($2))/e;
    } elsif ($line =~ m/^END-POPULARITY-CONTEST-0/i) {
	$foundentry = 0;
	print "# Ignored $ignorecount entries\n";
	$line =~ s/\b(TIME:)(\d+)\b/sprintf("%s%s", $1,fuzzy_timestamp($2))/e;
    } elsif ($line =~ m/^\d+ \d+ (\S*).*/i && !exists $table{$1}) {
	print STDERR "Ignoring package $1\n" if $debug;
	$ignorecount++;
	next;
    } elsif ($line =~ m/^(\d+) (\d+) (\S+) (.+)$/i && exists $table{$3}) {
	# Package entry
	$line = sprintf("%d %d %s %s\n", fuzzy_timestamp($1),
			fuzzy_timestamp($2), $3, $4);
    }
    print $line;
}