williamr/delete_builds.pl
author William Roberts <williamr@symbian.org>
Fri, 27 Aug 2010 15:38:43 +0100
changeset 282 a265a2da5fcb
parent 281 c62bd4f9dbce
child 291 66b0448c2de4
permissions -rw-r--r--
Fix handling of directories of builds
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
    {
282
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    56
    # not a build - perhaps a directory of builds?
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    57
    opendir DIR, $dir;
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    58
    my @files = grep !/^\.\.?$/, readdir DIR;
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    59
    closedir DIR;
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    60
    
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    61
    my @subbuilds = ();
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    62
    foreach my $file (@files)
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    63
      {
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    64
      next if (!-d "$dir/$file");
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    65
      next if (!-d "$dir/$file/output");
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    66
      push @subbuilds, "$dir/$file";
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    67
      }
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    68
    if (scalar @subbuilds == 0)
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    69
      {
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    70
      print "Ignoring $dir - not a build and contains no builds\n";
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    71
      next;
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    72
      }
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    73
    push @builds, @subbuilds;
281
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    74
    }
282
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    75
  else
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    76
    {
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    77
    push @builds, $dir;
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    78
    }
281
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    79
  }
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    80
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    81
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
    82
  {
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    83
  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
    84
    {
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    85
    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
    86
    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
    87
    $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
    88
    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
    89
    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
    90
    }
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    91
  }
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    92
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    93
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
    94
  {
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    95
  $build =~ s/\//\\/g;
282
a265a2da5fcb Fix handling of directories of builds
William Roberts <williamr@symbian.org>
parents: 281
diff changeset
    96
  print "* rmdir /s/q $build\n";
281
c62bd4f9dbce Add delete_builds.pl - a utility for making space quickly on build machines
William Roberts <williamr@symbian.org>
parents:
diff changeset
    97
  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
    98
  }