ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/Configuration/ConfigArea.pm
(Generate patch)

Comparing COMP/SCRAM/src/Configuration/ConfigArea.pm (file contents):
Revision 1.22 by sashby, Tue Dec 4 19:24:04 2001 UTC vs.
Revision 1.30 by sashby, Thu Aug 25 17:27:17 2005 UTC

# Line 1 | Line 1
1 < #
2 < # ConfigArea.pm
3 < #
4 < # Written by Christopher Williams
5 < #
6 < # Description
7 < # -----------
8 < # creates and manages a configuration area
9 < #
10 < # Notes
11 < # -------
12 < # Persistency - remember to call the save method to make changes persistent
13 < #
14 < # Interface
15 < # ---------
16 < # new()                         : A new ConfigArea object
17 < # name()                        : get/set project name
18 < # setup(dir[,areaname])         : setup a fresh area in dir
19 < # satellite(dir[,areaname])     : setup a satellite area in dir
20 < # version()                     : get/set project version
21 < # location([dir])               : set/return the location of the work area
22 < # bootstrapfromlocation([location]) : bootstrap the object based on location.
23 < #                                     no location specified - cwd used
24 < #                                     return 0 if succesful 1 otherwise
25 < # requirementsdoc()             : get set the requirements doc
26 < # searchlocation([startdir])    : returns the location directory. search starts
27 < #                                 from cwd if not specified
28 < # scramversion()                : return the scram version associated with
29 < #                                 area
30 < # configurationdir()            : return the location of the project
31 < #                                 configuration directory
32 < # copy(location)                : copy a configuration
33 < # copysetup(location)           : copy the architecture specific tool setup
34 < #                                 returns 0 if successful, 1 otherwise
35 < # copyenv($ref)                 : copy the areas environment into the hashref
36 < # toolbox()                     : return the areas toolbox object
37 < # save()                        : save changes permanently
38 < # linkto(location)              : link the current area to that at location
39 < # unlinkarea()                  : destroy link (autosave)
40 < # linkarea([ConfigArea])        : link the current area to the apec Area Object
41 < # archname()            : get/set a string to indicate architecture
42 < # archdir()             : return the location of the administration arch dep
43 < #                         directory
44 < # objectstore()         : return the objectStore object of the area
45 < # - temporary
46 < # align()                       : adjust hard paths to suit local loaction
1 > =head1 NAME
2 >
3 > Configuration::ConfigArea - Creates and manages a configuration area (i.e. a project area).
4 >
5 > =head1 SYNOPSIS
6 >
7 >        my $obj = Configuration::ConfigArea->new();
8 >
9 > =head1 DESCRIPTION
10 >
11 > Create and manage SCRAM project configuration areas.
12 >
13 > =head1 METHODS
14 >
15 > =over
16 >
17 > =cut
18 >
19 > =item C<new()>
20 >
21 > Create a new Configuration::ConfigArea object.
22 >
23 > =item C<name()>
24 >
25 > Get/set project name.
26 >
27 > =item C<setup($dir[,$areaname])>
28 >
29 > Set up a fresh area in $dir.
30 >
31 > =item C<satellite($dir[,$areaname])>
32 >
33 > Set up a satellite area in $dir.
34 >
35 > =item C<version()>
36 >
37 > Get/set project version.
38 >
39 > =item C<location([$dir])>
40 >
41 > Set/return the location of the work area.
42 >
43 > =item C<bootstrapfromlocation([$location])>
44 >
45 > Bootstrap the object based on location.
46 > No location specified - current directory used
47 > Return 0 if succesful, 1 otherwise.
48 >
49 > =item C<requirementsdoc()>
50 >
51 > Get or set the requirements document.
52 >
53 > =item C<searchlocation([$startdir])>
54 >
55 > Returns the location directory. search starts
56 > from current directory if not specified.
57 >
58 > =item C<scramversion()>
59 >
60 > Return the scram version associated with the area.
61 >
62 > =item C<configurationdir()>
63 >
64 > Return the location of the project configuration directory.
65 >
66 > =item C<copy($location)>
67 >
68 > Copy a configuration from $location.
69 >
70 > =item C<copysetup($location)>
71 >
72 > Copy the architecture-specific tool setup.
73 > Returns 0 if successful, 1 otherwise.
74 >
75 > =item C<copyenv($ref)>
76 >
77 > Copy the area environment into the hashref $ref.
78 >
79 > =item C<toolbox()>
80 >
81 > Return the area toolbox object.
82 >
83 > =item C<save()>
84 >
85 > Save changes permanently.
86 >
87 > =item C<linkto($location)>
88 >
89 > Link the current area to that at location.
90 >
91 > =item C<unlinkarea()>
92 >
93 > Destroy link ($autosave).
94 >
95 > =item C<linkarea([Configuration::ConfigArea])>
96 >
97 > Link the current area to the specified area object.
98 >
99 > =item C<archname()>
100 >
101 > Get/set a string to indicate architecture.
102 >
103 > =item C<archdir()>
104 >
105 > Return the location of the administration
106 > architecture-dependent directory.
107 >
108 > =item C<objectstore()>
109 >
110 > Return the B<objectStore> object of the area temporary.
111 >
112 > =item C<align()>
113 >
114 > Adjust hard paths to suit local location.
115 >
116 >
117 > =back
118 >
119 > =head1 AUTHOR
120 >
121 > Originally written by Christopher Williams.
122 >  
123 > =head1 MAINTAINER
124 >
125 > Shaun ASHBY
126 >
127 > =cut
128  
129   package Configuration::ConfigArea;
130   require 5.004;
# Line 63 | Line 144 | sub new {
144          $self->{admindir}=".SCRAM";
145          $self->{cachedir}="cache";
146          $self->{dbdir}="ObjectDB";
147 +        $self->{tbupdate}=0;
148          undef $self->{linkarea};
149  
150          return $self;
# Line 86 | Line 168 | sub cache {
168          return $self->{cache};
169   }
170  
171 + # Tool and project cache info:
172 + sub cacheinfo
173 +   {
174 +   my $self=shift;
175 +   print "\n","<ConfigArea> cacheinfo: ToolCache = ",$self->{toolcachefile},
176 +   ", ProjectCache = ",$self->{projectcachefile},"\n";
177 +   }
178 +
179 + sub toolcachename
180 +   {
181 +   my $self=shift;
182 +   return ($self->location()."/".$self->{admindir}."/".$ENV{SCRAM_ARCH}."/ToolCache.db");
183 +   }
184 +
185 + sub projectcachename
186 +   {
187 +   my $self=shift;
188 +   return ($self->location()."/".$self->{admindir}."/".$ENV{SCRAM_ARCH}."/ProjectCache.db");
189 +   }
190 +
191 + sub _tbupdate
192 +   {
193 +   # Update toolbox relative to new RequirementsDoc:
194 +   my $self=shift;
195 +   @_?$self->{tbupdate}=shift
196 +      :$self->{tbupdate};
197 +   }
198 +
199   sub _newcache {
200          my $self=shift;
201          my $loc=$self->location()."/".$self->{admindir}."/".$self->{cachedir};
# Line 138 | Line 248 | sub setup {
248          # -- check we have a project name and version
249          my $name=$self->name();
250          my $vers=$self->version();
251 +        
252          if ( ( ! defined $name ) && ( ! defined $version )) {
253            $self->error("Set ConfigArea name and version before setup");
254          }
# Line 181 | Line 292 | sub configurationdir {
292          return (defined $self->{configurationdir})?$self->{configurationdir}:undef;
293   }
294  
295 + sub sourcedir {
296 +        my $self=shift;
297 +        if ( @_ ) {
298 +          $self->{sourcedir}=shift;
299 +        }
300 +        return (defined $self->{sourcedir})?$self->{sourcedir}:undef;
301 + }
302 +
303   sub toolbox {
304          my $self=shift;
305          if ( ! defined $self->{toolbox} ) {
# Line 189 | Line 308 | sub toolbox {
308          return $self->{toolbox};
309   }
310  
311 + sub toolboxversion {
312 +        my $self=shift;
313 +        if ( @_ ) {
314 +          $self->{toolboxversion}=shift;
315 +        }
316 +        return (defined $self->{toolboxversion})?$self->{toolboxversion}:undef;
317 + }
318 +
319   sub requirementsdoc {
320          my $self=shift;
321          if ( @_ ) {
# Line 265 | Line 392 | sub sitename
392     return $self->{sitename};
393     }
394  
395 + sub admindir()
396 +   {
397 +   my $self=shift;
398 +  
399 +   @_ ? $self->{admindir} = shift
400 +      : $self->{admindir};
401 +   }
402  
403   sub bootstrapfromlocation {
404          my $self=shift;
# Line 279 | Line 413 | sub bootstrapfromlocation {
413          else {
414           $self->location($location);
415           $self->verbose("Found top ".$self->location());
282         my $infofile=$self->location()."/".$self->{admindir}."/ConfigArea.dat";
416           $self->_LoadEnvFile();
417          }
418          return $rv;
# Line 364 | Line 497 | sub satellite {
497          $sat->version($self->version());
498          $sat->requirementsdoc($self->{reqdoc});
499          $sat->configurationdir($self->configurationdir());
500 +        $sat->sourcedir($self->sourcedir());
501 +        $sat->toolboxversion($self->toolboxversion());
502          $sat->setup(@_);
503  
504          # -- copy across the cache and ObjectStore
# Line 430 | Line 565 | sub align {
565  
566   sub copysetup {
567          my $self=shift;
568 <        my $dest=shift;
434 <
568 >        my $dest=shift;
569          my $rv=1;
570          # copy across the admin dir
571          my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
# Line 445 | Line 579 | sub copysetup {
579          return $rv;
580   }
581  
582 + sub copyurlcache {
583 +        my $self=shift;
584 +        my $dest=shift;
585 +        my $rv=1;
586 +        # copy across the admin dir
587 +        my $temp=$self->location()."/".$self->{admindir}."/cache";
588 +        my $temp2=$dest."/".$self->{admindir}."/cache";
589 +        if ( $temp ne $temp2 ) {
590 +         if ( -d $temp ) {
591 +          AddDir::copydir($temp,$temp2);
592 +          $rv=0;
593 +         }
594 +        }
595 +        return $rv;
596 + }
597 +
598 + sub copywithskip {
599 +        my $self=shift;
600 +        my $dest=shift;
601 +        my ($filetoskip)=@_;            
602 +        my $rv=1;
603 +        # copy across the admin dir
604 +        my $temp=$self->location()."/".$self->{admindir}."/".$self->arch();
605 +        my $temp2=$dest."/".$self->{admindir}."/".$self->arch();
606 +        if ( $temp ne $temp2 ) {
607 +         if ( -d $temp ) {
608 +          AddDir::copydirwithskip($temp,$temp2,$filetoskip);
609 +          $rv=0;
610 +         }
611 +        }
612 +        return $rv;
613 + }
614 +
615   sub copyenv {
616          my $self=shift;
617          my $hashref=shift;
# Line 462 | Line 629 | sub arch {
629   sub linkto {
630          my $self=shift;
631          my $location=shift;
632 +
633          if ( -d $location ) {
634          my $area=Configuration::ConfigArea->new();
635          $area->bootstrapfromlocation($location);
# Line 495 | Line 663 | sub save {
663          $self->_SaveEnvFile();
664   }
665  
666 + sub reqdoc()
667 +   {
668 +   my $self=shift;
669 +   my ($path)=@_;
670 +   return $path."/".$self->{reqdoc};
671 +   }
672 +
673 + sub creationtime()
674 +   {
675 +   my $self=shift;
676 +   my ($location)= @_;
677 +   $location||=$self->location();
678 +   my $requirementsdoc = $self->reqdoc($location);
679 +   my ($mode, $time) = (stat($requirementsdoc))[2, 9];
680 +   my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
681 +
682 +   ($sec < 10) ? ($sec = "0".$sec) : $sec;
683 +   ($min < 10) ? ($min = "0".$min) : $min;
684 +
685 +   $year += 1900;
686 +   my $months =
687 +      {
688 +      0 => "Jan", 1 => "Feb",
689 +      2 => "Mar", 3 => "Apr",
690 +      4 => "May", 5 => "Jun",
691 +      6 => "Jul", 7 => "Aug",
692 +      8 => "Sept", 9 => "Oct",
693 +      10 => "Nov", 11 => "Dec" };
694 +  
695 +   my $days = { 1 => "Mon", 2 => "Tue", 3 => "Wed", 4 => "Thu", 5 => "Fri", 6 => "Sat", 7 => "Sun"};
696 +  
697 +   # Return the timestamp (as string) of the requirementsdoc:
698 +   return $days->{$wday}."-".$mday."-".$months->{$mon}."-".$year." ".$hour.":".$min.":".$sec;
699 +   }
700 +
701   # ---- support routines
702  
703 < sub _SaveEnvFile {
704 <        my $self=shift;
705 <        use FileHandle;
706 <        my $fh=FileHandle->new();
707 <        open ( $fh, ">".$self->location()."/".$self->{admindir}."/".
708 <                "Environment" ) or
709 <                $self->error("Cannot Open Environment file to Save ("
710 <                                .$self->location().")\n $!");
703 > sub _SaveEnvFile
704 >   {
705 >   my $self=shift;
706 >   my $filemode = 0644;
707 >  
708 >   use FileHandle;
709 >   my $fh=FileHandle->new();
710 >   open ( $fh, ">".$self->location()."/".$self->{admindir}."/".
711 >          "Environment" ) or
712 >          $self->error("Cannot Open Environment file to Save ("
713 >                       .$self->location().")\n $!");
714          
715 <        print $fh "SCRAM_PROJECTNAME=".$self->name()."\n";
716 <        print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n";
717 <        print $fh "projconfigdir=".$self->configurationdir()."\n";
718 <        print $fh "SCRAM_ProjReqsDoc=".$self->{reqdoc}."\n";
719 <        if ( defined $self->linkarea() ) {
720 <          my $area=$self->linkarea()->location();
721 <          if ( $area ne "" ) {
722 <          print $fh "RELEASETOP=".$area."\n";
723 <          }
724 <        }
725 <        undef $fh;
726 < }
727 <
715 >   print $fh "SCRAM_PROJECTNAME=".$self->name()."\n";
716 >   print $fh "SCRAM_PROJECTVERSION=".$self->version()."\n";
717 >   print $fh "SCRAM_CONFIGDIR=".$self->configurationdir()."\n";
718 >   print $fh "SCRAM_SOURCEDIR=".$self->sourcedir()."\n";
719 >   print $fh "SCRAM_ProjReqsDoc=".$self->{reqdoc}."\n";
720 >   print $fh "SCRAM_TOOLBOXVERSION=".$self->{toolboxversion}."\n";
721 >
722 >   if ( defined $self->linkarea() )
723 >      {
724 >      my $area=$self->linkarea()->location();
725 >      if ( $area ne "" )
726 >         {
727 >         print $fh "RELEASETOP=".$area."\n";
728 >         }
729 >      }
730 >  
731 >   undef $fh;
732 >  
733 >   # Set the default permissions (-rw-r--r--):
734 >   chmod $filemode, $self->location()."/".$self->{admindir}."/Environment";
735 >   }
736  
737 < sub _LoadEnvFile {
738 <        my $self=shift;
737 > sub _LoadEnvFile
738 >   {
739 >   my $self=shift;
740  
741 <        use FileHandle;
742 <        my $fh=FileHandle->new();
743 <        open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
744 <                "Environment" ) or
745 <                $self->error("Cannot find Environment file. Area Corrupted? ("
746 <                                .$self->location().")\n $!");
747 <        while ( <$fh> ) {
748 <           chomp;
749 <           next if /^#/;
750 <           next if /^\s*$/ ;
751 <           ($name, $value)=split /=/;
752 <           eval "\$self->{ENV}{${name}}=\"$value\"";
753 <        }
754 <        undef $fh;
741 >   use FileHandle;
742 >   my $fh=FileHandle->new();
743 >   open ( $fh, "<".$self->location()."/".$self->{admindir}."/".
744 >          "Environment" ) or
745 >          $self->error("Cannot find Environment file. Area Corrupted? ("
746 >                       .$self->location().")\n $!");
747 >   while ( <$fh> )
748 >      {
749 >      chomp;
750 >      next if /^#/;
751 >      next if /^\s*$/ ;
752 >      ($name, $value)=split /=/;
753 >      eval "\$self->{ENV}{${name}}=\"$value\"";
754 >      }
755 >   undef $fh;
756          
757 <        # -- set internal variables appropriately
758 <        if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} ) {
759 <          $self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
760 <        }
761 <        if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} ) {
762 <          $self->version($self->{ENV}{"SCRAM_PROJECTVERSION"});
763 <        }
764 <        if ( defined $self->{ENV}{"projconfigdir"} ) {
765 <          $self->configurationdir($self->{ENV}{projconfigdir});
766 <        }
767 <        if ( defined $self->{ENV}{"SCRAM_ProjReqsDoc"} ) {
768 <          $self->requirementsdoc($self->{ENV}{SCRAM_ProjReqsDoc});
769 <        }
770 <        if ( ( defined $self->{ENV}{"RELEASETOP"} ) &&
771 <                        ($self->{ENV}{"RELEASETOP"} ne $self->location())) {
772 <          $self->linkto($self->{ENV}{"RELEASETOP"});
773 <        }
774 <        else {
775 <          $self->{ENV}{"RELEASETOP"}=$self->location();
776 <        }
777 < }
757 >   # -- set internal variables appropriately
758 >   if ( defined $self->{ENV}{"SCRAM_PROJECTNAME"} )
759 >      {
760 >      $self->name($self->{ENV}{"SCRAM_PROJECTNAME"});
761 >      }
762 >   if ( defined $self->{ENV}{"SCRAM_PROJECTVERSION"} )
763 >      {
764 >      $self->version($self->{ENV}{"SCRAM_PROJECTVERSION"});
765 >      }
766 >   if ( defined $self->{ENV}{"SCRAM_CONFIGDIR"} )
767 >      {
768 >      $self->configurationdir($self->{ENV}{"SCRAM_CONFIGDIR"});
769 >      }
770 >   if ( defined $self->{ENV}{"SCRAM_SOURCEDIR"} )
771 >      {
772 >      $self->sourcedir($self->{ENV}{"SCRAM_SOURCEDIR"});
773 >      }
774 >   if ( defined $self->{ENV}{"SCRAM_ProjReqsDoc"} )
775 >      {
776 >      $self->requirementsdoc($self->{ENV}{"SCRAM_ProjReqsDoc"});
777 >      }
778 >   if ( defined $self->{ENV}{"SCRAM_TOOLBOXVERSION"} )
779 >      {
780 >      if ($self->{ENV}{"SCRAM_TOOLBOXVERSION"} eq '')
781 >         {
782 >         $self->toolboxversion("STANDALONE");
783 >         }
784 >      else
785 >         {
786 >         $self->toolboxversion($self->{ENV}{"SCRAM_TOOLBOXVERSION"});
787 >         }
788 >      }
789 >  
790 >   if ( ( defined $self->{ENV}{"RELEASETOP"} ) &&
791 >        ($self->{ENV}{"RELEASETOP"} ne $self->location()))
792 >      {
793 >      $self->linkto($self->{ENV}{"RELEASETOP"});
794 >      }
795 >   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines