12 |
|
# new(dbfile) : A new dbobject object |
13 |
|
# file() : return the db file |
14 |
|
# getarea(name,version) : return the object matching the name version |
15 |
< |
# addarea(ConfigArea) : add a project |
15 |
> |
# addarea(ConfigArea) : add a project - return 0 for success 1 for abort |
16 |
|
# list() : list areas (retunns $name,$version pairs) |
17 |
|
# removearea(name,version) : remove the named project |
18 |
|
# link(dblocation) : link with specified db |
29 |
|
bless $self, $class; |
30 |
|
$self->{dbfile}=shift; |
31 |
|
$self->_readdbfile($self->{dbfile}); |
32 |
+ |
$self->{projectobjects}={}; |
33 |
|
return $self; |
34 |
|
} |
35 |
|
|
47 |
|
my $index=$self->_findlocal($name,$version); |
48 |
|
if ( $index != -1 ) { |
49 |
|
my $location=$self->{projects}[$index][3]; |
50 |
+ |
if ( defined $self->{projectobjects}{$location} ) { |
51 |
+ |
$area=$self->{projectobjects}{$location}; |
52 |
+ |
} |
53 |
+ |
else { |
54 |
|
$area=Configuration::ConfigArea->new(); |
55 |
|
$self->verbose("Attempt to ressurect $name $version from $location"); |
56 |
|
if ( $area->bootstrapfromlocation($location) == 1 ) { |
59 |
|
} |
60 |
|
else { |
61 |
|
$self->verbose("area found"); |
62 |
+ |
$self->{projectobjects}{$location}=$area; |
63 |
+ |
} |
64 |
|
} |
65 |
|
} |
66 |
|
else { |
71 |
|
|
72 |
|
sub addarea { |
73 |
|
my $self=shift; |
74 |
+ |
my $name=shift; |
75 |
+ |
my $version=shift; |
76 |
|
my $area=shift; |
77 |
|
|
78 |
< |
my $name=$area->name(); |
79 |
< |
my $version=$area->version(); |
80 |
< |
my $type="_location"; |
81 |
< |
my $url=$area->location(); |
82 |
< |
push @{$self->{projects}}, [ ($name,$version,$type,$url) ]; |
78 |
> |
my $rv=1; |
79 |
> |
|
80 |
> |
#my $type="_location"; not ready for this yet |
81 |
> |
my $type="file"; |
82 |
> |
my $url=$area->location()."/.SCRAM/InstallFile"; |
83 |
> |
# -- check for duplicates |
84 |
> |
for ( my $index=0; $index<=$#{$self->{projects}}; $index++ ) { |
85 |
> |
if ( $self->{projects}[$index][0] eq $name ) { |
86 |
> |
if ( $self->{projects}[$index][1] eq $version ) { |
87 |
> |
print "$name $version alreay exists. Overwrite (y/n)\n"; |
88 |
> |
if ( ! (<STDIN>=~/y/i ) ) { |
89 |
> |
print "Aborting install ...\n"; |
90 |
> |
return 1; |
91 |
> |
} |
92 |
> |
else { |
93 |
> |
$rv=0; |
94 |
> |
$self->{projects}[$index]=[ ($name,$version,$type,$url) ]; |
95 |
> |
} |
96 |
> |
} |
97 |
> |
else { |
98 |
> |
print "Related Project : $name ".$self->{projects}[$index][1]."\n"; |
99 |
> |
} |
100 |
> |
} |
101 |
> |
} |
102 |
> |
if ( $rv ) { |
103 |
> |
# -- add to our list and save |
104 |
> |
push @{$self->{projects}}, [ ($name,$version,$type,$url) ]; |
105 |
> |
} |
106 |
|
$self->_save(); |
107 |
+ |
return 0; |
108 |
|
} |
109 |
|
|
110 |
|
sub list { |
154 |
|
|
155 |
|
use FileHandle; |
156 |
|
my $fh=FileHandle->new(); |
157 |
< |
my $filename=$self->{dbfile}."_tmp"; |
157 |
> |
my $filename=$self->{dbfile}; |
158 |
|
open ( $fh, ">$filename" ); |
159 |
|
# print current links |
160 |
|
foreach $db ( @{$self->{linkeddbs}} ) { |
164 |
|
my $temp; |
165 |
|
foreach $elem ( @{$self->{projects}} ) { |
166 |
|
$temp=join ":", @{$elem}; |
167 |
< |
print $fh $temp; |
167 |
> |
print $fh $temp."\n"; |
168 |
|
} |
169 |
|
undef $fh; |
170 |
|
} |