common/tools/findPhysicalDrive.pl
author Simon Howkins <simonh@symbian.org>
Fri, 29 Jan 2010 11:34:39 +0000
changeset 866 9dc266797c72
parent 858 f9fc2a3f8f70
child 891 6c56420d1006
permissions -rw-r--r--
Changed the way that the sf.spec.sourcesync.enable property is used to control the syncing, so that it can sync test repos even if it's not syncing any source repos.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
858
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     1
#!perl -w
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     2
#
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     3
# Copyright (c) 2010 Symbian Foundation Ltd
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     4
# This component and the accompanying materials are made available
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     6
# which accompanies this distribution, and is available
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     8
#
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
     9
# Initial Contributors:
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    10
# Symbian Foundation Ltd - initial contribution.
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    11
# 
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    12
# Contributors:
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    13
#
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    14
# Description:
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    15
# Find and output the drive letter mapped to the physical volume with the
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    16
# largest amount of free space
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    17
# 
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    18
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    19
use strict;
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    20
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    21
# Use Windows command to list physical volumes on the machine
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    22
# (No substed drives, or mapped network drives)
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    23
my @drives = map {chomp;$_} `echo list volume | diskpart`;
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    24
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    25
my %drives;
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    26
for my $driveLine (@drives)
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    27
{
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    28
	# If this line of output is actually about a healthy HD volume...
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    29
	if ($driveLine =~ m{^\s+Volume \d+\s+([A-Z]).*?(Partition|RAID-5)\s+\d+ [A-Z]+\s+Healthy} )
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    30
	{
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    31
		my $letter = $1;
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    32
		# Ignore the system drive
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    33
		next if ($driveLine =~ m{System\s*$});
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    34
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    35
		# Use dir to get the freespace (bytes)
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    36
		my @bytesFree = grep { s{^.*?(\d+) bytes free\s*$}{$1} } map {chomp;$_} `cmd /c dir /-C $letter:\\`;
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    37
		# Take the value from the bottom of the report
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    38
		my $bytesFree = $bytesFree[-1];
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    39
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    40
		# Record info for this volume
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    41
		$drives{$letter} = $bytesFree;
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    42
	}
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    43
}
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    44
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    45
die "Unable to find any suitable drives at all\n" unless %drives;
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    46
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    47
# Switch keys and values
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    48
%drives = reverse %drives;
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    49
# Sort by space to find the volume with the largest amount of space and print out the corresponding letter
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    50
print "$drives{(reverse sort keys %drives)[0]}:\n";
f9fc2a3f8f70 Code to automatically find a physical drive for running a build, triggered as necessary.
Simon Howkins <simonh@symbian.org>
parents:
diff changeset
    51