ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Configuration/ConfigArea.pm
Revision: 1.3
Committed: Fri Jan 21 08:59:34 2000 UTC (25 years, 3 months ago) by williamc
Content type: text/plain
Branch: MAIN
Changes since 1.2: +20 -8 lines
Log Message:
updates

File Contents

# User Rev Content
1 williamc 1.1 #
2     # ConfigArea.pm
3     #
4     # Originally Written by Christopher Williams
5     #
6     # Description
7     #
8     # Interface
9     # ---------
10     # new(ActiveConfig) : A new ConfigArea object
11     # setup() : setup the configuration area
12     # location([dir]) : set/return the location of the area
13     # version([version]) : set/return the version of the area
14     # name([name]) : set/return the name of the area
15     # store(location) : store data in file location
16     # restore(location) : restore data from file location
17     # meta() : return a description string of the area
18     # addconfigitem(url) : add a new item to the area
19     # configitem(@keys) : return a list of fig items that match
20     # the keys - all if left blank
21    
22     package Configuration::ConfigArea;
23     use ActiveDoc::ActiveDoc;
24     require 5.004;
25     use Utilities::AddDir;
26     use ObjectUtilities::ObjectStore;
27     @ISA=qw(ActiveDoc::ActiveDoc ObjectUtilities::StorableObject);
28    
29     sub init {
30     my $self=shift;
31     $self->newparse("init");
32     $self->newparse("download");
33     $self->newparse("setup");
34     $self->addtag("init","project",\&Project_Start,$self,
35     \&Project_text,$self,"", $self );
36     $self->addurltags("download");
37     $self->addtag("download","use",\&Use_download_Start,$self,
38     "", $self, "",$self);
39     $self->addurltags("setup");
40     $self->addtag("setup","use",\&Use_Start,$self, "", $self, "",$self);
41     }
42    
43     sub setup {
44     my $self=shift;
45    
46     # --- find out the location
47     my $location=$self->requestoption("area_location",
48     "Please Enter the location of the directory");
49    
50     # --- find area directory name , default name projectname_version
51     my $name=$self->option("area_name");
52     my $vers=$self->version;
53     if ( ! defined $name ) {
54     $name=$self->name();
55     $vers=~s/^$name_//;
56     $name=$name."_".$vers;
57     }
58     $self->location($location."/".$name);
59    
60    
61     # make a new store handler
62 williamc 1.3 my $parentconfig=$self->_setupstore();
63 williamc 1.1
64     # --- download everything first
65     # FIX-ME --- cacheing is broken
66 williamc 1.2 $self->parse("download");
67 williamc 1.1
68     # --- and parse the setup file
69     $self->parse("setup");
70 williamc 1.3
71     # --- store self in original database
72     $parentconfig->store($self,"ConfigArea",$self->name(),
73     $self->version());
74     }
75    
76     sub _setupstore {
77     my $self=shift;
78    
79     # --- make a new ActiveStore at the location and add it to the db list
80     my $ad=ActiveDoc::ActiveConfig->new($self->location()."/\.SCRAM");
81    
82     my $parentconfig=$self->config();
83     $self->config(Configuration::ConfigureStore->new());
84     $self->config()->db("local",$ad);
85     $self->config()->db("parent",$parentconfig);
86     $self->config()->policy("cache","local");
87     $self->config()->basedoc($parentconfig->basedoc());
88     return $parentconfig;
89 williamc 1.1 }
90    
91     sub store {
92     my $self=shift;
93     my $location=shift;
94    
95     my $fh=$self->openfile(">".$location);
96     print $fh $self->location()."\n";
97     $fh->close();
98     }
99    
100     sub restore {
101     my $self=shift;
102    
103     my $fh=$self->openfile("<".$location);
104     $self->{location}=<$fh>;
105     chomp $self->{location};
106     $fh->close();
107    
108     }
109    
110     sub name {
111     my $self=shift;
112    
113     @_?$self->{name}=shift
114     :$self->{name};
115     }
116    
117     sub version {
118     my $self=shift;
119    
120     @_?$self->{version}=shift
121     :$self->{version};
122     }
123    
124     sub location {
125     my $self=shift;
126    
127     @_?$self->{location}=shift
128     :$self->{location};
129     }
130    
131     sub meta {
132     my $self=shift;
133    
134     my $string=$self->name()." ".$self->version()." located at :\n ".
135     $self->location;
136     }
137    
138     sub configitem {
139     my $self=shift;
140     my $location=shift;
141    
142     $self->config()->find("ConfigItem",@_);
143     }
144    
145     sub addconfigitem {
146     my $self=shift;
147     my $url=shift;
148    
149     my $docref=$self->activatedoc($url);
150     # Set up the document
151     $docref->setup();
152 williamc 1.2 $self->config()->storepolicy("local");
153 williamc 1.1 $docref->save();
154     }
155    
156     # -------------- Tags ---------------------------------
157     # -- init parse
158     sub Project_Start {
159     my $self=shift;
160     my $name=shift;
161     my $hashref=shift;
162    
163     $self->checktag($name,$hashref,'name');
164     $self->checktag($name,$hashref,'version');
165    
166     $self->name($$hashref{'name'});
167     $self->version($$hashref{'version'});
168     }
169    
170    
171     sub Project_text {
172     my $self=shift;
173     my $name=shift;
174     my $string=shift;
175    
176     print $string;
177     }
178    
179     # ---- download parse
180    
181     sub Use_download_Start {
182     my $self=shift;
183     my $name=shift;
184     my $hashref=shift;
185    
186     $self->checktag($name,$hashref,'url');
187     print "Downloading .... ".$$hashref{'url'}."\n";
188     $self->getfile($$hashref{'url'});
189     }
190    
191     # --- setup parse
192    
193     sub Use_Start {
194     my $self=shift;
195     my $name=shift;
196     my $hashref=shift;
197    
198     $self->checktag($name,$hashref,'url');
199     $self->addconfigitem($$hashref{'url'});
200     }
201