tools/release/MozBuild/TinderLogParse.pm
author dtownsend@oxymoronical.com
Tue, 29 Jan 2008 18:00:45 -0800
changeset 10979 6e65d9a3ce0fe82b0205f096b7725a91da479bb0
parent 4646 930bb2fac8f69cb65ae716385cd77a0da20cb8ce
child 12982 826cdcc8e46ac29245000d69e89ba8b488f60c9a
permissions -rw-r--r--
Bug 406807: Remove unneccesary parts of xpinstall. r=bsmedberg, sr=dveditz, a=damons

##
# TinderLogParse - A tinderbox log parser
##

package MozBuild::TinderLogParse;

sub new {
    my $class = shift;
    my %args = @_;

    my $logFile = $args{'logFile'};
    if (! defined($logFile)) {
        die("ASSERT: TinderLogParse::new logFile is a required argument");
    }

    my $this = { logFile => $logFile };
    bless($this, $class);
    return $this;
}

## 
# GetBuildID - attempts to find build ID in a tinderbox log file
#
# Searches for a string of the form:
#  Got Build ID: 2007030311
# Only the buildID, '2007030311', is to be returned.
#
##

sub GetBuildID {
    my $this = shift;
    my %args = @_;

    my $log = $this->GetLogFileName();

    my $buildID = undef;
    my $searchString = "Got build ID ";

    open (FILE, "< $log") or die("Cannot open file $log: $!");
    while (<FILE>) {
        if ($_ =~ /$searchString/) {
            $buildID = $_;
 
            # remove search string
            $buildID =~ s/$searchString//;

            # remove trailing slash
            $buildID =~ s/\.$//;
            last;
        }
    }

    close FILE or die("Cannot close file $log: $!");

    if (! defined($buildID)) {
        return undef;
    }
    if (! $buildID =~ /^\d+$/) {
        die("ASSERT: Build: build ID is not numerical: $buildID")
    }

    chomp($buildID);
    return $buildID;
}

## 
# GetPushDir - attempts to find the directory Tinderbox pushed to build to
#
# Searches for a string of the form:
#  Linux Firefox Build available at: 
#  localhost/2007-04-07-18-firefox2.0.0.4/ 
# Matches on "Build available at:" and returns the next line.
##

sub GetPushDir {
    my $this = shift;
    my %args = @_;

    my $log = $this->GetLogFileName();

    my $found = 0;
    my $pushDir = undef;
    my $searchString = "Build available at:";

    open (FILE, "< $log") or die("Cannot open file $log: $!");
    while (<FILE>) {
        if ($found) {
            $pushDir = $_;
            last;
        }
        if ($_ =~ /$searchString/) {
            $found = 1;
        }
    }

    close FILE or die("Cannot close file $log: $!");
 
    if (! defined($pushDir)) {
        return undef;
    }

    chomp($pushDir);
    # remove empty space at end of URL
    $pushDir =~ s/\s+$//;

    return $pushDir;
}

sub GetLogFileName {
    my $this = shift;
    my %args = @_;

    return $this->{'logFile'};
}

1;