18 |
|
sub new() |
19 |
|
{ |
20 |
|
my $proto=shift; |
21 |
< |
my $class=ref($proto) || $proto; |
22 |
< |
my $self = |
23 |
< |
{ |
24 |
< |
DOWNLOADED => { tools => undef, url => undef }, # Downloaded tool infos; |
25 |
< |
SELECTED => undef, # The selected tools (info from RequirementsDoc); |
26 |
< |
DEFAULTVERSIONS => {}, # Hash of tools and their default version; |
27 |
< |
RAW => [], # The tools to be set up (the raw data from the tool docs); |
28 |
< |
SETUP => {}, # The saved set-up data; |
29 |
< |
STAMP => undef # The last time the cache was modified |
30 |
< |
}; |
31 |
< |
|
21 |
> |
my $class=ref($proto) || $proto; |
22 |
> |
my $self={}; |
23 |
> |
$self->{SETUP}={}; |
24 |
|
bless $self,$class; |
25 |
|
return $self; |
26 |
|
} |
27 |
|
|
36 |
– |
sub downloadedtools() |
37 |
– |
{ |
38 |
– |
my $self=shift; |
39 |
– |
# Returns an array of downloaded tools, basically all |
40 |
– |
# those listed in configuration: |
41 |
– |
@_ ? $self->{DOWNLOADED}{tools} = shift # |
42 |
– |
: $self->{DOWNLOADED}{tools}; |
43 |
– |
} |
44 |
– |
|
45 |
– |
sub defaultversions() |
46 |
– |
{ |
47 |
– |
my $self=shift; |
48 |
– |
# Returns a hash of tools and their default versions: |
49 |
– |
@_ ? $self->{DEFAULTVERSIONS} = shift # |
50 |
– |
: $self->{DEFAULTVERSIONS}; |
51 |
– |
} |
52 |
– |
|
53 |
– |
sub toolurls() |
54 |
– |
{ |
55 |
– |
my $self=shift; |
56 |
– |
# Returns a hash of tools and their URLs: |
57 |
– |
@_ ? $self->{DOWNLOADED}->{url} = shift # |
58 |
– |
: $self->{DOWNLOADED}->{url}; |
59 |
– |
} |
60 |
– |
|
61 |
– |
sub selected() |
62 |
– |
{ |
63 |
– |
my $self=shift; |
64 |
– |
# Returns hash of selected tools: |
65 |
– |
@_ ? $self->{SELECTED} = $_[0] |
66 |
– |
: $self->{SELECTED}; |
67 |
– |
} |
68 |
– |
|
69 |
– |
sub addtoselected() |
70 |
– |
{ |
71 |
– |
my $self=shift; |
72 |
– |
my ($toolname)=@_; |
73 |
– |
# When "scram setup X" is used to add new tool to environment, we need a way to add this tool |
74 |
– |
# to the list of selected tools. Otherwise, runtime env won't work. |
75 |
– |
# Need to check to see if this tool already exists in the SELECTED hash. |
76 |
– |
# Only try to add a new rank if tool doesn't already exist: |
77 |
– |
if (! exists $self->{SELECTED}->{$toolname}) |
78 |
– |
{ |
79 |
– |
# First, check the highest rank (just number of elements [i.e., keys in hash]). Next |
80 |
– |
# tool added will get next number: |
81 |
– |
my $nextrank = (keys %{$self->{SELECTED}}) + 1; |
82 |
– |
$self->{SELECTED}->{$toolname} = $nextrank; |
83 |
– |
} |
84 |
– |
} |
85 |
– |
|
86 |
– |
sub store() |
87 |
– |
{ |
88 |
– |
my $self=shift; |
89 |
– |
# Store ToolParser objects (tools not set up yet): |
90 |
– |
@_ ? push(@{$self->{RAW}},@_) # |
91 |
– |
: @{$self->{RAW}}; |
92 |
– |
} |
93 |
– |
|
94 |
– |
sub rawtools() |
95 |
– |
{ |
96 |
– |
my $self=shift; |
97 |
– |
# Return a list of tools |
98 |
– |
return @{$self->{RAW}}; |
99 |
– |
} |
100 |
– |
|
28 |
|
sub setup() |
29 |
|
{ |
30 |
|
my $self=shift; |
104 |
– |
# Returns a hash of toolname/ToolData objects (set-up tools): |
31 |
|
return $self->{SETUP}; |
32 |
|
} |
33 |
|
|
108 |
– |
sub cleanup_raw() |
109 |
– |
{ |
110 |
– |
my $self=shift; |
111 |
– |
my ($tremoved)=@_; |
112 |
– |
my $newrtools=[]; |
113 |
– |
|
114 |
– |
# Remove the tool from the list of raw tool objects: |
115 |
– |
foreach my $rawtool (@{$self->{RAW}}) |
116 |
– |
{ |
117 |
– |
# Find the tool name from the ToolParser object $rawtool: |
118 |
– |
if ($tremoved eq $rawtool->toolname()) |
119 |
– |
{ |
120 |
– |
print "Removing ToolParser $tremoved from cache.","\n"; |
121 |
– |
} |
122 |
– |
else |
123 |
– |
{ |
124 |
– |
push(@{$newrtools},$rawtool); |
125 |
– |
} |
126 |
– |
} |
127 |
– |
|
128 |
– |
# Remove from list of selected tools and version list: |
129 |
– |
delete $self->{SELECTED}->{$tremoved}; |
130 |
– |
delete $self->{DEFAULTVERSIONS}->{$tremoved}; |
131 |
– |
# Now save the new tool list: |
132 |
– |
$self->{RAW} = $newrtools; |
133 |
– |
} |
134 |
– |
|
135 |
– |
sub inheritcontent() |
136 |
– |
{ |
137 |
– |
my $self=shift; |
138 |
– |
my ($externaltm)=@_; |
139 |
– |
|
140 |
– |
# Inherit all tool data from an external scram-managed project. |
141 |
– |
# Basically copy RAW, SETUP and SELECTED hash data: |
142 |
– |
$self->{RAW} = [ $externaltm->rawtools() ]; |
143 |
– |
$self->{SETUP} = $externaltm->setup(); |
144 |
– |
|
145 |
– |
my $tmpselected = $externaltm->selected(); |
146 |
– |
|
147 |
– |
# We add the downloaded SELECTED entries to our existing SELECTED data |
148 |
– |
# in the same order as they already appear: |
149 |
– |
foreach my $entry ( sort { %{$tmpselected}->{$a} |
150 |
– |
<=> %{$tmpselected}->{$b}} |
151 |
– |
keys %{$tmpselected} ) |
152 |
– |
{ |
153 |
– |
# Now add them to selected data: |
154 |
– |
$self->addtoselected($entry); |
155 |
– |
} |
156 |
– |
} |
157 |
– |
|
158 |
– |
### Read/write from/to cachefile: |
34 |
|
sub name() |
35 |
|
{ |
36 |
|
my $self = shift; |
38 |
|
@_ ? $self->{CACHENAME} = shift # |
39 |
|
: $self->{CACHENAME}; |
40 |
|
} |
41 |
+ |
|
42 |
+ |
sub dirty() |
43 |
+ |
{ |
44 |
+ |
my $self = shift; |
45 |
+ |
$self->{internal}{dirty}=1; |
46 |
+ |
} |
47 |
|
|
48 |
+ |
sub isdirty() |
49 |
+ |
{ |
50 |
+ |
my $self = shift; |
51 |
+ |
my $dirty = $self->{internal}{dirty} || 0; |
52 |
+ |
return $dirty; |
53 |
+ |
} |
54 |
+ |
|
55 |
|
sub writecache() |
56 |
|
{ |
57 |
|
my $self=shift; |
58 |
< |
use Cache::CacheUtilities; |
59 |
< |
&Cache::CacheUtilities::write($self,$self->{CACHENAME}); |
58 |
> |
if (exists $self->{internal}{dirty}) |
59 |
> |
{ |
60 |
> |
my $file=$self->{CACHENAME}; |
61 |
> |
delete $self->{internal}; |
62 |
> |
use Cache::CacheUtilities; |
63 |
> |
&Cache::CacheUtilities::write($self,$file); |
64 |
> |
} |
65 |
|
} |
66 |
|
|
67 |
|
1; |