PVCS.pm

filter: Statementstmt 11.8% 9 / 76 Branchbran 0.0% 0 / 38 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 33.3% 3 / 9 Podpod n/a totaltotal 9.3% 12 / 128 CC 24 SCAR 36.2
CC
24
Cov
8%
new
72.0
readMasterConfigFile
42.0
readMasterProjFile
42.0
CRAP 37.2
« PVCS/Folder.pm ↑ Summary PVCS/Archive.pm »
1 # PVCS.pm - super class for VCS::PVCS::Project
2 #
3 # Copyright (c) 1998 Bill Middleton
4 #
5 #
6  
7 require 5.003;
8 $VERSION = "0.01";
9  
10 =head1 NAME
11  
12 VCS::PVCS - Global configuration class for for VCS::PVCS::*.
13  
14 =head1 SYNOPSIS
15  
16 use VCS::PVCS::Project; # preferred
17 $project = new VCS::PVCS::Project("ProjectName");
18  
19 =head1 DESCRIPTION
20  
21 The VCS::PVCS class simply parses the PVCS global configuration files,
22 including pvcsproj.pub and MASTER.CFG, found in PVCSPROJ.
23 The resulting object is then included in the VCS::PVCS::Project
24 object as it's "CONFIG". The class members are used at various
25 times in other subclasses, as needed.
26  
27 NOTE: This module may require some configuration. If your
28 scripts wont run, you may need to hardwire some of the global
29 parameters, including $ISLVINI, $PVCSPROJ, $NFSMAP, $PVCS_BINDIR and
30 possibly others. You should inspect the module before installing
31 it, to verify the settings will work.
32  
33 This module also exports several GLOBAL variables, which are
34 used in various places throughout it's children, and can be
35 used in scripts which load the B<VCS::PVCS::Project> class.
36 These variables include, but may not always be limited to:
37  
38 =over 5
39  
40 =item B<$PVCSERR>
41  
42 PVCSERR is set to the current value of B<$?> after each command.
43  
44 =item B<$PVCSDEBUG>
45  
46 PVCSDEBUG can be turned on to see copious (sometimes useful) debugging
47 output as the module is configuring itself, and running.
48  
49 =item B<$PVCSOUTPUT>
50  
51 PVCSOUTPUT is all of the output from the current method, when it
52 executes a pvcs command. If the command was executed on a folder
53 or project-wide basis, then PVCSOUTPUT contains ALL of the output
54 for all archives.
55  
56 =item B<$PVCSCURROUTPUT>
57  
58 PVCSCURROUTPUT is ONLY the output for the most recent command sent
59 to the shell.
60  
61 =item B<$PVCSSHOWMODE>
62  
63 PVCSSHOWMODE is turned on to see, and not execute, commands.
64  
65 =item B<$PVCS_BINDIR>
66  
67 PVCS_BINDIR is set in the environment or in VCS::PVCS.pm to be
68 the location of the PVCS binaries, B<get>, B<put>, B<vlog>, B<vcs>,
69 B<vdiff>, etc.
70  
71 =item B<$PVCSMASTERCFG>
72  
73 PVCSMASTERCFG is the path to the master configuration file. This
74 variable is not exported to the world through VCS::PVCS::Project,
75 but only intended for internal use.
76  
77 =item B<$PVCSCURRPROJCFG>
78  
79 PVCSCURRPROJCFG is the location of the current projects' Config file.
80 This variable is not exported to the world through VCS::PVCS::Project,
81 but only intended for internal use.
82  
83 =item B<$PVCSMULTIPLATFORM>
84  
85 PVCSMULTIPLATFORM tells the modules whether to make certain path
86 translations when operating on something other than WIN. Turn
87 this on if you are using PVCS in a multiplatform environment.
88  
89 B<This variable is turned on automatically if an NFSMAP is found>
90  
91 =item B<$PVCSPROJ>
92  
93 PVCSPROJ is the base directory for all PVCS control files.
94  
95 =back
96  
97 Ordinarily, this class wont be used directly. Rather, it
98 is in the @ISA for VCS::PVCS::Project. When creating a new
99 VCS::PVCS::Project object, this module's new() method is
100 invoked automatically.
101  
102 =head1 AUTHOR
103  
104 Bill Middleton, wjm@metronet.com
105  
106 =head1 COPYRIGHT
107  
108 The PVCS module is Copyright (c) 1998 Bill Middleton.
109 All rights reserved.
110  
111 You may distribute under the terms of either the GNU General Public
112 License or the Artistic License, as specified in the Perl README file.
113  
114 =head1 SUPPORT / WARRANTY
115  
116 The VCS::PVCS modules are free software.
117  
118 B<THEY COME WITHOUT WARRANTY OF ANY KIND.>
119  
120 Commercial support agreements for Perl can be arranged via
121 The Perl Clinic. See http://www.perl.co.uk/tpc for more details.
122  
123 =head1 SEE ALSO
124  
125 perl(1), VCS::PVCS::Project
126  
127 =cut
128  
129 package VCS::PVCS;
130 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
131 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
132 require Exporter;
133 4 ▶use vars qw($PVCSDEBUG $USESQL @ISA @EXPORT $VERSION $PVCSPROJ $PVCSDONTSAVE
Subroutine BEGIN: called CC=1 SCAR=0.0
134 $PVCSPRIV $NFSMAP $PVCSERR $PVCSOUTPUT $PVCSCURROUTPUT $ISLVINI $PVCS_BINDIR
135 4 $PVCSMASTERCFG $PVCSSHOWMODE $PVCSCURRPROJCFG %NFSMAP $PVCSMULTIPLATFORM);
136 @ISA = qw(Exporter);
137 @EXPORT = qw(translatePath2Win translatePath2Unix );
138 $VERSION = "0.01";
139 $PVCSDEBUG= 0;
140 $PVCSSHOWMODE = 0;
141  
142  
143 ####################################################################
144 # Configuration Defaults extracted from ISLVINI
145 ####################################################################
146  
147 $USESQL =0;
148 $PVCSDEBUG = 0; # Set this to get debug output for all PVCS modules
149  
150 $PVCSDONTSAVE = 1; # Save config files when VCSDIR changes.
151 # change this if you dont use conditional directives
152 # in your config files for pvcs
153 if($ENV{'ISLVINI'}){
154 $ISLVINI = $ENV{'ISLVINI'};
155 }
156 elsif($^O eq "MSWin32"){
157 if(-e "$ENV{'WINDIR'}/islv.ini"){
158 $ISLVINI = $ENV{'WINDIR'}.'/islv.ini';
159 }
160 }
161 elsif(-e "$ENV{'HOME'}/.islvrc"){
162 $ISLVINI = $ENV{'HOME'}.'/.islvrc';
163 }
164 else{
165 print "$ENV{'HOME'}/.islvrc\n";
166 croak "Cannot find the ISLVINI file\n";
167 }
168  
169 # Better change these!
170  
171 if($ENV{'PVCS_BINDIR'}){
172 $PVCS_BINDIR = $ENV{'PVCS_BINDIR'};
173 if(! ((-e "$PVCS_BINDIR/vcs") or (-e "$PVCS_BINDIR/vcs.exe"))){
174 croak "Cant find PVCS Binaries. Set PVCS_BINDIR in PVCS.pm or ENV.\n";
175 }
176 }
177 elsif($^O eq "MSWin32"){ # There is probably a better way to do this on WIN
178 $PVCS_BINDIR = "N:\\pvcs6.0\\nt";
179 if(! (-e "$PVCS_BINDIR/vcs.exe")){
180 croak "Cant find PVCS Binaries. Set PVCS_BINDIR in PVCS.pm or ENV.\n";
181 }
182 $ENV{'PVCS_BINDIR'} = $PVCS_BINDIR;
183 }
184 else{ # unix
185 $PVCS_BINDIR = "/usr/pvcs";
186 if(! (-e "$PVCS_BINDIR/vcs")){
187 croak "Cant find PVCS Binaries. Set PVCS_BINDIR in PVCS.pm or ENV.\n";
188 }
189 $ENV{'PVCS_BINDIR'} = $PVCS_BINDIR;
190 }
191 $PVCSERR = $PVCSOUTPUT= $PVCSCURROUTPUT = $PVCSPROJ = "";
192 $PVCSMULTIPLATFORM = 0; # Assume were in a heterogeneous environment
193 # unless we find an nfsmap
194  
195 push(@EXPORT,"\$PVCSERR");
196 push(@EXPORT,"\$PVCSDEBUG");
197 push(@EXPORT,"\$PVCSOUTPUT");
198 push(@EXPORT,"\$PVCSCURROUTPUT");
199 push(@EXPORT,"\$PVCSSHOWMODE");
200 push(@EXPORT,"\$PVCS_BINDIR");
201 push(@EXPORT,"\$PVCSMASTERCFG");
202 push(@EXPORT,"\$PVCSCURRPROJCFG");
203 push(@EXPORT,"\$PVCSMULTIPLATFORM");
204 push(@EXPORT,"\$PVCSPROJ");
205  
206 ####################################################################
207 0 ▶sub new{
Subroutine new: not called CC=8 SCAR=42.8
208 0 my $proto = shift;
209 0 my $self = {};
210 0 ▶ open(ISLVINI,$ISLVINI) || croak "Cant open ISLVINI: $ISLVINI\n";
Branch: 1 branch
BranchTrueFalseTotal
open ISLVINI, $VCS::PVCS::ISLVINI or croak("Cant open ISLVINI: $VCS::PVCS::ISLVINI\n") 0 0 0
211 0 ▶ while(<ISLVINI>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline ISLVINI)) 0 0 0
212 0 chomp;
213 0 ▶ next unless (/^(PVCSPROJ|PVCSPRIV|NFSMAP)=(.*)/);
Branch: 1 branch
BranchTrueFalseTotal
unless /^(PVCSPROJ|PVCSPRIV|NFSMAP)=(.*)/ 0 0 0
214 0 eval "\${$1}= \$2";
215 }
216 0 ▶ (croak "Your PVCSPROJ AND PVCSPRIV directories are not defined in $ISLVINI\n")
Branch: 1 branch
BranchTrueFalseTotal
unless length $VCS::PVCS::PVCSPROJ and length $VCS::PVCS::PVCSPRIV 0 0 0
Condition0%0/3
length $VCS::PVCS::PVCSPROJ and length $VCS::PVCS::PVCSPRIV
!ll&&!rl&&r
000
MC/DC0%0/2
length $VCS::PVCS::PVCSPROJ and length $VCS::PVCS::PVCSPRIV
length $VCS::PVCS::PVCSPROJ length $VCS::PVCS::PVCSPRIV
Truth table0%0/3
A and B
A= length $VCS::PVCS::PVCSPROJB= length $VCS::PVCS::PVCSPRIV
ABresult
0X0
100
111
217 unless (length($PVCSPROJ) && length($PVCSPRIV));
218  
219 0 readMasterProjFile($self);
220 0 ▶ if(-e "$PVCSPROJ/MASTER.CFG"){ # Um, you may need to change this too.
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$VCS::PVCS::PVCSPROJ/MASTER.CFG") { } 0 0 0
221 0 $PVCSMASTERCFG = "$PVCSPROJ/MASTER.CFG";
222 0 readMasterConfigFile($self);
223 }
224 else{
225 0 croak "No MASTER.CFG config file found in $PVCSPROJ\n";
226 }
227 0 ▶ if(-e "$NFSMAP/nfsmap"){
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$VCS::PVCS::NFSMAP/nfsmap") 0 0 0
228 0 readNFSMap($self);
229 }
230 0 bless($self,"VCS::PVCS");
231 }
232  
233 0 ▶sub readMasterConfigFile{
Subroutine readMasterConfigFile: not called CC=6 SCAR=37.4
234 0 my($self) = shift;
235 0 my($key,$value)=();
236 0 my(@tmp);
237 # Eventually, this'll be replaced with API call
238 # Right now the only thing we're interested in is VCSDIR,
239 # since the command line tools will read them for themselves.
240  
241 0 ▶(croak "Cant find your Master Config file, $PVCSMASTERCFG")
Branch: 1 branch
BranchTrueFalseTotal
unless -e "$VCS::PVCS::PVCSMASTERCFG" 0 0 0
242 unless (-e "$PVCSMASTERCFG");
243 0 ▶open(MASTER, "$PVCSMASTERCFG") ||
Branch: 1 branch
BranchTrueFalseTotal
open MASTER, "$VCS::PVCS::PVCSMASTERCFG" or croak("cant open $VCS::PVCS::PVCSMASTERCFG") 0 0 0
244 croak "cant open $PVCSMASTERCFG";
245 0 ▶while(<MASTER>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline MASTER)) 0 0 0
246 0 chop;chop; # icky but ok
247 0 ($key,$value) = split(/\s+[= ]+\s*/,$_);
248 0 ▶ next unless (defined($key));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 0 0
249 0 ▶ next unless ($key =~ s/.*(VCSDIR).*/$1/);
Branch: 1 branch
BranchTrueFalseTotal
unless $key =~ s/.*(VCSDIR).*/$1/ 0 0 0
250 0 $value =~s/^\s*\"//;
251 0 $value =~s/\"\s*$//;
252 0 @{$self->{'VCSDIR'}} = split(/\"\;\"/,$value);
253 0 last;
254 }
255 }
256  
257  
258 0 ▶sub readMasterProjFile{
Subroutine readMasterProjFile: not called CC=6 SCAR=37.4
259 0 my($self) = shift;
260 0 my($nextline,$project);
261 0 ▶(croak "Cant find your Master Project file, $PVCSPROJ/pvcsproj.pub")
Branch: 1 branch
BranchTrueFalseTotal
unless -e "$VCS::PVCS::PVCSPROJ/pvcsproj.pub" 0 0 0
262 unless (-e "$PVCSPROJ/pvcsproj.pub");
263 0 ▶ open(MASTER, $PVCSPROJ."/pvcsproj.pub") || croak "cant open ";
Branch: 1 branch
BranchTrueFalseTotal
open MASTER, $VCS::PVCS::PVCSPROJ . '/pvcsproj.pub' or croak("cant open ") 0 0 0
264 0 ▶ while(<MASTER>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline MASTER)) 0 0 0
265 0 chomp;
266 0 ▶ next unless (/^\[Project=(.*)\]/);
Branch: 1 branch
BranchTrueFalseTotal
unless /^\[Project=(.*)\]/ 0 0 0
267 0 $project = $1;
268 0 for(1 .. 4){
269 0 chomp($nextline = scalar(<MASTER>));
270 0 $nextline =~ /^(CFG|DIR|ARDIR|WKDIR)=([^\015]*)/;
271 0 $self->{'projects'}->{$project}->{$1} = $2;
272 }
273 0 $self->{'projects'}->{$project}->{'NAME'} = $project;
274 }
275 }
276  
277 0 ▶sub readNFSMap{
Subroutine readNFSMap: not called CC=3 SCAR=24.8
278 0 my($self) = shift;
279 0 my($key,$value);
280 0 open(MASTER,"$NFSMAP/nfsmap");
281 0 $PVCSMULTIPLATFORM = 1;
282 0 ▶while(<MASTER>){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline MASTER)) 0 0 0
283 0 chomp;
284 0 ▶ next if /^[\s#]/;
Branch: 1 branch
BranchTrueFalseTotal
if /^[\s#]/ 0 0 0
285 0 ($key,$value) = split(' ',$_);
286 0 $NFSMAP{$key} = $value;
287 }
288 }
289  
290 0 ▶sub translatePath2Unix{
Subroutine translatePath2Unix: not called CC=3 SCAR=24.8
291 0 my($pathref) = shift;
292 0 my($key,$path);
293 0 foreach $key (keys %NFSMAP){
294 0 ▶ if($$pathref =~ s#$key:\\#$NFSMAP{$key}/#){
Branch: 1 branch
BranchTrueFalseTotal
if ($$pathref =~ s[$key:\\][$VCS::PVCS::NFSMAP{$key}/]) 0 0 0
295 0 last;
296 }
297 }
298 0 $$pathref =~ s/\\/\//g;
299 }
300  
301 0 ▶sub translatePath2Win{
Subroutine translatePath2Win: not called CC=3 SCAR=24.8
302 0 my($pathref) = shift;
303 0 my($key,$value,$path);
304 0 foreach $key (keys %NFSMAP){
305 0 $value = $NFSMAP{$key};
306 0 ▶ if($$pathref =~ s#$value/#$key:\\#){
Branch: 1 branch
BranchTrueFalseTotal
if ($$pathref =~ s[$value/][${key}:\\]) 0 0 0
307 0 last;
308 }
309 }
310 0 $$pathref =~ s/\//\\/g;
311 }
312  
313  
314 1;
315 __END__
« PVCS/Folder.pm ↑ Summary PVCS/Archive.pm »