1 |
+ |
#____________________________________________________________________ |
2 |
+ |
# File: Architecture.pm |
3 |
+ |
#____________________________________________________________________ |
4 |
+ |
# |
5 |
+ |
# Author: Shaun Ashby <Shaun.Ashby@cern.ch> |
6 |
+ |
# Update: 2003-10-23 17:20:41+0200 |
7 |
+ |
# Revision: $Id$ |
8 |
|
# |
9 |
< |
# Provide machine/architecture information services |
3 |
< |
# simply set the architecture variable based on uname |
9 |
> |
# Copyright: 2003 (C) Shaun Ashby |
10 |
|
# |
11 |
< |
# --------- |
6 |
< |
# Interface |
7 |
< |
# --------- |
8 |
< |
# new() : new object - will autoinitialise to architecture |
9 |
< |
# getarch() : return the current (assumed) architecture |
10 |
< |
# archfile($filename,$base) : Will check various relevant architecture specific |
11 |
< |
# dirs in search for an architecture specific $file |
12 |
< |
# starting from base |
13 |
< |
|
11 |
> |
#-------------------------------------------------------------------- |
12 |
|
package Architecture; |
13 |
< |
require 5.001; |
13 |
> |
require 5.004; |
14 |
> |
use Exporter; |
15 |
> |
|
16 |
> |
@ISA=qw(Exporter); |
17 |
> |
@EXPORT_OK=qw( ); |
18 |
> |
|
19 |
> |
sub new() |
20 |
> |
{ |
21 |
> |
############################################################### |
22 |
> |
# new() # |
23 |
> |
############################################################### |
24 |
> |
# modified : Thu Oct 23 17:21:05 2003 / SFA # |
25 |
> |
# params : # |
26 |
> |
# : # |
27 |
> |
# function : # |
28 |
> |
# : # |
29 |
> |
############################################################### |
30 |
> |
my $proto=shift; |
31 |
> |
my $class=ref($proto) || $proto; |
32 |
> |
my $self={}; |
33 |
> |
|
34 |
> |
bless $self,$class; |
35 |
> |
|
36 |
> |
$self->_initarch(); |
37 |
> |
|
38 |
> |
return $self; |
39 |
> |
} |
40 |
> |
|
41 |
> |
sub arch() |
42 |
> |
{ |
43 |
> |
my $self=shift; |
44 |
> |
|
45 |
> |
@_ ? $self->{arch} = shift |
46 |
> |
: $self->{arch}; |
47 |
> |
} |
48 |
> |
|
49 |
> |
# A subroutine to determine the architecture. This |
50 |
> |
# is done by parsing the architecture map contained as |
51 |
> |
# data inside SCRAM_SITE.pm and looking for an appropriate |
52 |
> |
# match for our platform: |
53 |
> |
sub _initarch() |
54 |
> |
{ |
55 |
> |
my $self=shift; |
56 |
> |
$self->parse_architecture_map(); |
57 |
> |
return $self; |
58 |
> |
} |
59 |
> |
|
60 |
> |
# Parse the map data: |
61 |
> |
sub parse_architecture_map() |
62 |
> |
{ |
63 |
> |
my $self=shift; |
64 |
> |
my $matches={}; |
65 |
> |
|
66 |
> |
require Installation::SCRAM_SITE; |
67 |
> |
my $architectures = &Installation::SCRAM_SITE::read_architecture_map(); |
68 |
> |
|
69 |
> |
while (my ($archstring,$archtest) = each %{$architectures}) |
70 |
> |
{ |
71 |
> |
my $rval = eval join(" ",@$archtest); |
72 |
> |
|
73 |
> |
if ($rval) |
74 |
> |
{ |
75 |
> |
# Store the matched string: |
76 |
> |
$matches->{$archstring}=1; |
77 |
> |
|
78 |
> |
if ((my $nkeys = keys %{$matches}) > 1) |
79 |
> |
{ |
80 |
> |
print "\n"; |
81 |
> |
print "SCRAM: WARNING: more than one architecture definition in ","\n"; |
82 |
> |
print " SCRAM_SITE matches current platform!","\n"; |
83 |
> |
print "Unable to set the architecture correctly!","\n"; |
84 |
> |
print "\n"; |
85 |
> |
exit(1); |
86 |
> |
} |
87 |
> |
# Store the match (only the *first* match in the case |
88 |
> |
# of multiple matches): |
89 |
> |
$self->arch($archstring); |
90 |
> |
} |
91 |
> |
else |
92 |
> |
{ |
93 |
> |
next; |
94 |
> |
} |
95 |
> |
} |
96 |
> |
} |
97 |
|
|
98 |
< |
sub new { |
18 |
< |
my $class=shift; |
19 |
< |
$self={}; |
20 |
< |
bless $self, $class; |
21 |
< |
$self->_initarch(); |
22 |
< |
return $self; |
23 |
< |
} |
24 |
< |
|
25 |
< |
sub getarch { |
26 |
< |
my $self=shift; |
27 |
< |
return $self->{arch}; |
28 |
< |
} |
29 |
< |
|
30 |
< |
sub archfile { |
31 |
< |
my $self=shift; |
32 |
< |
my $filename=shift; |
33 |
< |
my $base=shift; |
34 |
< |
|
35 |
< |
my $archdir; |
36 |
< |
|
37 |
< |
foreach $dir ( @{$self->{archdirs}} ) { |
38 |
< |
$archdir=$base."/".$dir."/".$filename; |
39 |
< |
if ( -f $archdir ) { |
40 |
< |
return $self->{archdir}; |
41 |
< |
} |
42 |
< |
} |
43 |
< |
} |
44 |
< |
|
45 |
< |
# ------------ Support Routines --------------------------------- |
46 |
< |
|
47 |
< |
sub _initarch { |
48 |
< |
my $self=shift; |
49 |
< |
|
50 |
< |
$self->{realarch}=$; |
51 |
< |
# Seperate Variables means we can pretend to be other architectures |
52 |
< |
$self->{arch}=$self->{realarch}; |
53 |
< |
|
54 |
< |
# get the hostname |
55 |
< |
use Sys::Hostname; |
56 |
< |
$self->{host}=hostname(); |
57 |
< |
|
58 |
< |
# Architecture directory search path |
59 |
< |
@{$self->{archdirs}}=( $self->{arch}."/".$self->{host}, "$self->{arch}" ); |
60 |
< |
} |
98 |
> |
1; |