clean_package_dirs.pl
author Dario Sestito <darios@symbian.org>
Tue, 21 Jul 2009 12:52:36 +0100
changeset 30 45b248d07f63
parent 18 27ea4714a2aa
permissions -rw-r--r--
Fix regexp in clean_package_dirs.pl to account of test builds numbering
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     1
# Copyright (c) 2009 Symbian Foundation Ltd
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     2
# This component and the accompanying materials are made available
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     3
# under the terms of the License "Eclipse Public License v1.0"
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     4
# which accompanies this distribution, and is available
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     5
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     6
#
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     7
# Initial Contributors:
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     8
# Symbian Foundation Ltd - initial contribution.
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
     9
#
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    10
# Contributors:
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    11
#
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    12
# Description:
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    13
# This is a helper script which cleans up some space on the machine by
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    14
# removing old package-build-related directories 
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    15
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    16
use strict;
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    17
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    18
use Getopt::Long;
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    19
use File::Path;
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    20
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    21
my $sJOB_BASE_DIR = "D:\\fbf_job";
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    22
my $nJOB_MAX_DIR_AGE_SECS = 259200; # 259200=3 days
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    23
my $bJOB_SAVE_LAST_DIR = 1;
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    24
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    25
my $sPROJECT_BASE_DIR = "D:\\fbf_project";
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    26
my $nPROJECT_MAX_DIR_AGE_SECS = 259200; # 259200=3 days
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    27
my $bPROJECT_SAVE_LAST_DIR = 1;
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    28
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    29
my $nNow = time();
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    30
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    31
print "#### Cleaning old job dirs. ####\n";
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    32
opendir(DIR, "$sJOB_BASE_DIR");
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    33
my @asDirs = readdir(DIR);
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    34
close(DIR);
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    35
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    36
for my $sDir ( @asDirs )
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    37
{
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    38
	next if ( $sDir eq "." or $sDir eq ".." );
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    39
	next if ( ! -d "$sJOB_BASE_DIR\\$sDir" );
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    40
	
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    41
	#print "--- $sDir\n";
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    42
	
30
45b248d07f63 Fix regexp in clean_package_dirs.pl to account of test builds numbering
Dario Sestito <darios@symbian.org>
parents: 18
diff changeset
    43
	if ( $sDir =~ /^([^.]+)\.T?(\d+)/ )
18
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    44
	{
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    45
		my $sBaseName = $1;
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    46
		my $sBuildNumber = $2;
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    47
		
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    48
		my $nTs = (stat("$sJOB_BASE_DIR\\$sDir"))[9]; # modified time
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    49
			
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    50
		my $bLastDir = 0;
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    51
		if ( $bJOB_SAVE_LAST_DIR )
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    52
		{
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    53
			my @asSimilarDirs = grep(/^$sBaseName(\.|$)/, @asDirs);
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    54
			$bLastDir = 1;
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    55
			for my $sSimilarDir ( @asSimilarDirs )
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    56
			{
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    57
				my $nSimDirTs = (stat("$sJOB_BASE_DIR\\$sSimilarDir"))[9];
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    58
				$bLastDir = 0 if ( $nSimDirTs > $nTs );
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    59
			}
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    60
			$bLastDir = 1 if ( ! scalar @asSimilarDirs );
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    61
		}
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    62
		
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    63
		if ( $bJOB_SAVE_LAST_DIR && $bLastDir )
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    64
		{
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    65
			print "Skipping $sDir as last dir in the series\n";
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    66
		}
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    67
		elsif ( $nNow - $nTs > $nJOB_MAX_DIR_AGE_SECS )
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    68
		{
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    69
			print "Removing $sDir...\n";
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    70
			print "rmdir /S $sJOB_BASE_DIR\\$sDir\n";
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    71
			system("rmdir /S /Q $sJOB_BASE_DIR\\$sDir");
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    72
		}
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    73
		else
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    74
		{
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    75
			print "Keeping $sDir\n";
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    76
		}
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    77
	}
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    78
	else
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    79
	{
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    80
		print "$sDir doesn't match\n";
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    81
	}
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    82
}
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    83
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    84
print "#### Cleaning old project dirs. ####\n";
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    85
opendir(DIR, "$sPROJECT_BASE_DIR");
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    86
@asDirs = readdir(DIR);
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    87
close(DIR);
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    88
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    89
for my $sDir ( @asDirs )
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    90
{
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    91
	next if ( $sDir eq "." or $sDir eq ".." );
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    92
	next if ( ! -d "$sPROJECT_BASE_DIR\\$sDir" );
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    93
	
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    94
	if ( $sDir =~ /^([^.]+)\.(\d+)/ or $sDir =~ /^([^.]+)$/ )
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    95
	{
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    96
		my $sBaseName = "";
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    97
		my $sBuildNumber = 0;
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    98
		if ( $sDir =~ /^([^.]+)\.(\d+)/ )
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
    99
		{
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   100
			$sBaseName = $1;
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   101
			$sBuildNumber = $2;
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   102
		}
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   103
		elsif ( $sDir =~ /^([^.]+)$/ )
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   104
		{
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   105
			$sBaseName = $1;
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   106
		}
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   107
		
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   108
		my $nTs = (stat("$sPROJECT_BASE_DIR\\$sDir"))[9]; # modified time
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   109
		
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   110
		my $bLastDir = 0;
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   111
		if ( $bPROJECT_SAVE_LAST_DIR )
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   112
		{
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   113
			my @asSimilarDirs = grep(/^$sBaseName(\.|$)/, @asDirs);
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   114
			$bLastDir = 1;
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   115
			for my $sSimilarDir ( @asSimilarDirs )
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   116
			{
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   117
				my $nSimDirTs = (stat("$sPROJECT_BASE_DIR\\$sSimilarDir"))[9];
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   118
				$bLastDir = 0 if ( $nSimDirTs > $nTs );
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   119
			}
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   120
			$bLastDir = 1 if ( ! scalar @asSimilarDirs );
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   121
		}
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   122
		
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   123
		if ( $bPROJECT_SAVE_LAST_DIR && $bLastDir )
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   124
		{
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   125
			print "Skipping $sDir as last dir in the series\n";
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   126
		}
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   127
		elsif ( $nNow - $nTs > $nPROJECT_MAX_DIR_AGE_SECS )
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   128
		{
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   129
			print "Removing $sDir...\n";
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   130
			print "rmdir /S $sPROJECT_BASE_DIR\\$sDir\n";
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   131
			system("rmdir /S /Q $sPROJECT_BASE_DIR\\$sDir");
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   132
		}
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   133
		else
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   134
		{
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   135
			print "Keeping $sDir\n";
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   136
		}
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   137
	}
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   138
	else
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   139
	{
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   140
		print "$sDir doesn't match\n";
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   141
	}
27ea4714a2aa Added script to clean old build-related folders
Dario Sestito <darios@symbian.org>
parents:
diff changeset
   142
}