williamr/delete_builds.pl
author William Roberts <williamr@symbian.org>
Fri, 27 Aug 2010 15:27:06 +0100
changeset 281 c62bd4f9dbce
child 282 a265a2da5fcb
permissions -rw-r--r--
Add delete_builds.pl - a utility for making space quickly on build machines This Perl script deletes some directories known to contain very large files first, before deleting the rest of the build which contains millions of small files. Given multiple builds, it will do this breadth first, so that lost of space is released quickly.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
281
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
     1
#! perl
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
     2
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
     3
# Copyright (c) 2010 Symbian Foundation Ltd
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
     4
# This component and the accompanying materials are made available
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
     6
# which accompanies this distribution, and is available
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
     8
#
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
     9
# Initial Contributors:
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    10
# Symbian Foundation Ltd - initial contribution.
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    11
# 
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    12
# Contributors:
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    13
#
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    14
# Description:
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    15
# Delete a directory full of builds, making space as quickly as possible by
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    16
# deleting known regions of massive files first
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    17
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    18
use strict;
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    19
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    20
# List directory subtrees containing mostly big files, biggest first
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    21
my @rich_pickings = (
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    22
  'output/zips',
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    23
  'output/logs',
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    24
  'epoc32/release/winscw/udeb'
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    25
  );
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    26
  
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    27
if (scalar @ARGV == 0)
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    28
  {
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    29
  print <<'EOF';
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    30
Usage: perl delete_builds.pl dir1 [dir2 ...]
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    31
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    32
Delete one or more builds, making free space as quickly as possible
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    33
by deleting a few selected directories first
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    34
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    35
You can use wildcards in the directory names, and they can be either
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    36
individual builds or directories of builds. A build is identified by
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    37
the present of an "output" subdirectory. 
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    38
EOF
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    39
  exit(1);
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    40
  }
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    41
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    42
my @builds = ();
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    43
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    44
@ARGV = map {glob} @ARGV;
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    45
foreach my $dir (@ARGV)
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    46
  {
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    47
  $dir =~ s/\\/\//g;  # unix separators
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    48
  $dir =~ s/\/+$//;   # remove trailing /
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    49
  if (!-d $dir)
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    50
    {
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    51
    print "Ignoring $dir - not a directory\n";
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    52
    next;
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    53
    }
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    54
  if (!-d "$dir/output")
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    55
    {
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    56
    print "Ignoring $dir - not a build\n";
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    57
    next;
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    58
    }
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    59
  push @builds, $dir;
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    60
  }
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    61
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    62
foreach my $subdir (@rich_pickings)
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    63
  {
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    64
  foreach my $build (@builds)
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    65
    {
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    66
    my $victim = "$build/$subdir";
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    67
    next if (!-d $victim);  # nothing to delete
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    68
    $victim =~ s/\//\\/g;   # windows separators again (sigh!)
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    69
    print "* rmdir /s/q $victim\n";
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    70
    system("rmdir","/s/q",$victim);
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    71
    }
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    72
  }
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    73
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    74
foreach my $build (@builds)
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    75
  {
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    76
  $build =~ s/\//\\/g;
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    77
  print "* rmdir /s/q $build";
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    78
  system("rmdir","/s/q",$build);   
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    79
  }