ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Configuration/ConfigArea.pm
Revision: 1.1
Committed: Thu Jan 20 18:21:54 2000 UTC (25 years, 3 months ago) by williamc
Content type: text/plain
Branch: MAIN
Log Message:
Not fixed yet - save work

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     # --- make a new ActiveStore at the location and add it to the db list
61     my $ad=ActiveDoc::ActiveConfig->new($self->location()."/\.SCRAM");
62    
63     # make a new store handler
64     my $parentconfig=$self->config;
65     $self->config(Configuration::ConfigureStore);
66     $self->config()->db("local",$ad);
67     $self->config()->db("parent",$parentconfig);
68     $self->config()->policy("cache","local");
69     $self->config()->basedoc($parentconfig->basedoc());
70    
71     # --- download everything first
72     # FIX-ME --- cacheing is broken
73     # $self->parse("download");
74    
75     # --- and parse the setup file
76     $self->parse("setup");
77     }
78    
79     sub store {
80     my $self=shift;
81     my $location=shift;
82    
83     my $fh=$self->openfile(">".$location);
84     print $fh $self->location()."\n";
85     $fh->close();
86     }
87    
88     sub restore {
89     my $self=shift;
90    
91     my $fh=$self->openfile("<".$location);
92     $self->{location}=<$fh>;
93     chomp $self->{location};
94     $fh->close();
95    
96     }
97    
98     sub name {
99     my $self=shift;
100    
101     @_?$self->{name}=shift
102     :$self->{name};
103     }
104    
105     sub version {
106     my $self=shift;
107    
108     @_?$self->{version}=shift
109     :$self->{version};
110     }
111    
112     sub location {
113     my $self=shift;
114    
115     @_?$self->{location}=shift
116     :$self->{location};
117     }
118    
119     sub meta {
120     my $self=shift;
121    
122     my $string=$self->name()." ".$self->version()." located at :\n ".
123     $self->location;
124     }
125    
126     sub configitem {
127     my $self=shift;
128     my $location=shift;
129    
130     $self->config()->find("ConfigItem",@_);
131     }
132    
133     sub addconfigitem {
134     my $self=shift;
135     my $url=shift;
136    
137     my $docref=$self->activatedoc($url);
138     # Set up the document
139     $docref->setup();
140     $self->config()->savepolicy("local");
141     $docref->save();
142     }
143    
144     # -------------- Tags ---------------------------------
145     # -- init parse
146     sub Project_Start {
147     my $self=shift;
148     my $name=shift;
149     my $hashref=shift;
150    
151     $self->checktag($name,$hashref,'name');
152     $self->checktag($name,$hashref,'version');
153    
154     $self->name($$hashref{'name'});
155     $self->version($$hashref{'version'});
156     }
157    
158    
159     sub Project_text {
160     my $self=shift;
161     my $name=shift;
162     my $string=shift;
163    
164     print $string;
165     }
166    
167     # ---- download parse
168    
169     sub Use_download_Start {
170     my $self=shift;
171     my $name=shift;
172     my $hashref=shift;
173    
174     $self->checktag($name,$hashref,'url');
175     print "Downloading .... ".$$hashref{'url'}."\n";
176     $self->getfile($$hashref{'url'});
177     }
178    
179     # --- setup parse
180    
181     sub Use_Start {
182     my $self=shift;
183     my $name=shift;
184     my $hashref=shift;
185    
186     $self->checktag($name,$hashref,'url');
187     $self->addconfigitem($$hashref{'url'});
188     }
189