ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Scram/ScramProjectDB.pm
Revision: 1.1.2.1
Committed: Fri Apr 28 12:47:35 2000 UTC (25 years ago) by williamc
Content type: text/plain
Branch: V0_9branch
CVS Tags: V0_12_2
Changes since 1.1: +153 -0 lines
Log Message:
some basic functionality - only getting project area really supported and tested

File Contents

# User Rev Content
1 williamc 1.1.2.1 #
2     # ScramProjectDB.pm - Keep a track of available projects
3     #
4     # Originally Written by Christopher Williams
5     #
6     # Description
7     # -----------
8     # Stores project area information
9     #
10     # Interface
11     # ---------
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
16     # removearea(name,version) : remove the named project
17     # link(dblocation) : link with specified db
18     # unlink(dblocation) : remove link with a specified db
19    
20     package Scram::ScramProjectDB;
21     use Utilities::Verbose;
22     require 5.004;
23     @ISA=qw(Utilities::Verbose);
24    
25     sub new {
26     my $class=shift;
27     my $self={};
28     bless $self, $class;
29     $self->{dbfile}=shift;
30     $self->_readdbfile($self->{dbfile});
31     return $self;
32     }
33    
34     sub file {
35     my $self=shift;
36     return $self->{dbfile};
37     }
38    
39     sub getarea {
40     my $self=shift;
41     my $name=shift;
42     my $version=shift;
43    
44     my $area;
45     my $index=$self->_findlocal($name,$version);
46     if ( $index != -1 ) {
47     my $location=$self->{projects}[$index][3];
48     $area=Configuration::ConfigArea->new();
49     $self->verbose("Attempt to ressurect $name $version from $location");
50     if ( $area->bootstrapfromlocation($location) == 1 ) {
51     undef $area;
52     $self->verbose("attempt unsuccessful");
53     }
54     else {
55     $self->verbose("area found");
56     }
57     }
58     return $area;
59     }
60    
61     sub addarea {
62     my $self=shift;
63     my $area=shift;
64    
65     my $name=$area->name();
66     my $version=$area->version();
67     my $type="_location";
68     my $url=$area->location();
69     push @{$self->{projects}}, [ ($name,$version,$type,$url) ];
70     $self->_save();
71     }
72    
73     sub removearea {
74     my $self=shift;
75     my $name=shift;
76     my $version=shift;
77    
78     print "Not yet implemented\n";
79     }
80    
81     sub link {
82     my $self=shift;
83     my $dbfile=shift;
84    
85     my $newdb=Scram::ScramProjectDB->new($dbfile);
86     push @{$self->{linkeddbs}},$newdb;
87     $self->_save();
88     }
89    
90     # -- Support Routines
91    
92     #
93     # Search through the project list until we get a match
94     sub _findlocal {
95     my $self=shift;
96     my $name=shift;
97     my $version=shift;
98    
99     my $found=-1;
100     for (my $i=0; $i<=$#{$self->{projects}}; $i++ ) {
101     if ( ( $self->{projects}[$i][0] eq $name) &&
102     ( $self->{projects}[$i][1] eq $version) ) {
103     $found=$i;
104     last;
105     }
106     }
107     return $found;
108     }
109    
110     sub _save {
111     my $self=shift;
112    
113     use FileHandle;
114     my $fh=FileHandle->new();
115     my $filename=$self->{dbfile}."_tmp";
116     open ( $fh, ">$filename" );
117     # print current links
118     foreach $db ( @{$self->{linkeddbs}} ) {
119     print $fh "\!DB ".$db->file()."\n";
120     }
121     # save project info
122     my $temp;
123     foreach $elem ( @{$self->{projects}} ) {
124     $temp=join ":", @{$elem};
125     print $fh $temp;
126     }
127     undef $fh;
128     }
129    
130     sub _readdbfile {
131     my $self=shift;
132     my $file=shift;
133    
134     use FileHandle;
135     my $fh=FileHandle->new();
136     open ( $fh, "<$file" );
137    
138     my @vars;
139     while ( $map=<$fh> ) {
140     chomp $map;
141     if ( $map=~/^\!DB (.*)/ ) { # Check for other DB files
142     my $db=$1;
143     if ( -f $db ) {
144     $newdb=Scram::ScramProjectDB->new($db);
145     push @{$self->{linkeddbs}},$newdb;
146     }
147     next;
148     }
149     @vars = split ":", $map;
150     push @{$self->{projects}}, [ @vars ];
151     }
152     undef $fh;
153     }