WE_Frontend/Publish/Rdist.pm

filter: Statementstmt 9.5% 14 / 146 Branchbran 0.0% 0 / 80 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 50.0% 4 / 8 Podpod n/a totaltotal 6.6% 18 / 271 CC 50 SCAR 72.7
CC
50
Cov
6%
publish_rdist
1892.0
is_in_path
42.0
file_name_is_absolute
12.0
CRAP 1432.5
« WE_Frontend/Publish/FTP_MD5Sync.pm ↑ Summary WE_Frontend/Publish/Rsync.pm »
1 # -*- perl -*-
2  
3 #
4 # $Id: Rdist.pm,v 1.8 2004/03/08 10:44:59 eserte Exp $
5 # Author: Slaven Rezic
6 #
7 # Copyright (C) 2002 Online Office Berlin. All rights reserved.
8 # Copyright (C) 2002 Slaven Rezic.
9 # This is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License, see the file COPYING.
11  
12 #
13 # Mail: slaven@rezic.de
14 # WWW: http://we-framework.sourceforge.net
15 #
16  
17 package WE_Frontend::Publish::Rdist;
18  
19 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 $VERSION = sprintf("%d.%02d", q$Revision: 1.8 $ =~ /(\d+)\.(\d+)/);
21  
22 package WE_Frontend::Main;
23  
24 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 1 ▶use WE_Frontend::Publish;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 0 ▶sub publish_rdist {
Subroutine publish_rdist: not called CC=43 SCAR=75.5
31 0 my($self, %args) = @_;
32  
33 0 my $do_exec = !delete $args{-n};
34 0 my $v = delete $args{-verbose};
35 0 my $since = delete $args{-since};
36 0 ▶ if (defined $since) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $since) 0 0 0
37 0 warn "The -since option is ignored with publish_rdist!";
38 }
39 0 my $liveuser = $self->Config->staging->user;
40 0 ▶ if ($liveuser eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($liveuser eq "") 0 0 0
41 0 undef $liveuser;
42 }
43 0 my $livedirectory = $self->Config->staging->directory;
44 0 my $livecgidirectory = $self->Config->staging->cgidirectory;
45 0 my $livehost = $self->Config->staging->host;
46 0 ▶ if (!defined $livehost || $livehost eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $livehost or $livehost eq "") 0 0 0
Condition0%0/3
not defined $livehost or $livehost eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $livehost or $livehost eq ""
not defined $livehost $livehost eq ""
Truth table0%0/3
not(A) or B
A= not defined $livehostB= $livehost eq ""
ABresult
1X1
011
000
47 0 $livehost = "localhost";
48 }
49 0 my $pubhtmldir = $self->Config->paths->pubhtmldir;
50 0 my $cgidir = $self->Config->paths->cgidir;
51 my @extracgi = (ref $self->Config->project->stagingextracgi eq 'ARRAY'
52 0 ▶ ? @{ $self->Config->project->stagingextracgi }
Branch: 1 branch
BranchTrueFalseTotal
ref $self->Config->project->stagingextracgi eq 'ARRAY' ? : 0 0 0
53 : ()
54 );
55 my $distfile = ($self->Config->staging->stagingext &&
56 $self->Config->staging->stagingext->{'distfile'}
57 0 ▶ ? $self->Config->staging->stagingext->{'distfile'}
Branch: 1 branch
BranchTrueFalseTotal
$self->Config->staging->stagingext && $self->Config->staging->stagingext->{'distfile'} ? : 0 0 0
Condition0%0/3
$self->Config->staging->stagingext and $self->Config->staging->stagingext->{"distfile"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->Config->staging->stagingext and $self->Config->staging->stagingext->{"distfile"}
$self->Config->staging->stagingext $self->Config->staging->stagingext->{"distfile"}
Truth table0%0/3
A and B
A= $self->Config->staging->stagingextB= $self->Config->staging->stagingext->{"distfile"}
ABresult
0X0
100
111
58 : undef);
59 0 my @extra_args;
60 0 ▶ if (exists $args{-transport}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"-transport"}) 0 0 0
61 0 my $exec = is_in_path($args{-transport});
62 0 ▶ if (!defined $exec) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $exec) 0 0 0
63 0 die "Cannot find executable for $args{-transport} in $ENV{PATH}";
64 }
65 0 push @extra_args, "-P", $exec;
66 0 delete $args{-transport};
67 }
68 my $deleteold = ($self->Config->staging->stagingext &&
69 $self->Config->staging->stagingext->{'deleteold'}
70 0 ▶ ? $self->Config->staging->stagingext->{'deleteold'}
Branch: 1 branch
BranchTrueFalseTotal
$self->Config->staging->stagingext && $self->Config->staging->stagingext->{'deleteold'} ? : 0 0 0
Condition0%0/3
$self->Config->staging->stagingext and $self->Config->staging->stagingext->{"deleteold"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->Config->staging->stagingext and $self->Config->staging->stagingext->{"deleteold"}
$self->Config->staging->stagingext $self->Config->staging->stagingext->{"deleteold"}
Truth table0%0/3
A and B
A= $self->Config->staging->stagingextB= $self->Config->staging->stagingext->{"deleteold"}
ABresult
0X0
100
111
71 : 0);
72  
73 0 ▶ if (!defined $distfile) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $distfile) 0 0 0
74 0 ▶ if (!defined $livedirectory) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $livedirectory) 0 0 0
75 0 die "\$livedirectory is not defined";
76 }
77 0 ▶ if (!defined $pubhtmldir || $pubhtmldir eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $pubhtmldir or $pubhtmldir eq "") 0 0 0
Condition0%0/3
not defined $pubhtmldir or $pubhtmldir eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $pubhtmldir or $pubhtmldir eq ""
not defined $pubhtmldir $pubhtmldir eq ""
Truth table0%0/3
not(A) or B
A= not defined $pubhtmldirB= $pubhtmldir eq ""
ABresult
1X1
011
000
78 0 die "The publish html directory is missing (config member WEsiteinfo->paths->pubhtmldir)";
79 }
80 0 ▶ if (@extracgi && (!defined $livecgidirectory || $livecgidirectory eq '')) {
Branch: 1 branch
BranchTrueFalseTotal
if (@extracgi and !defined($livecgidirectory) || $livecgidirectory eq "") 0 0 0
Condition0%0/6
@extracgi and !defined($livecgidirectory) || $livecgidirectory eq ""
!ll&&!rl&&r
000
not defined $livecgidirectory or $livecgidirectory eq ""
l!l&&r!l&&!r
000
MC/DC0%0/3
@extracgi and !defined($livecgidirectory) || $livecgidirectory eq ""
@extracgi not defined $livecgidirectory $livecgidirectory eq ""
Truth table0%0/4
A and not(B) or C
A= @extracgiB= not defined $livecgidirectoryC= $livecgidirectory eq ""
ABCresult
0XX0
1000
11X1
1011
81 0 die "Extra CGI scripts are defined (@extracgi),
82 but the WEsiteinfo->staging->cgidirectory config is missing";
83 }
84 }
85  
86 # XXX same as in Rsync.pm
87 0 my @cvs_exclude_pat = @{ WE_Frontend::Publish->_min_cvs_exclude }; # XXX!
88 0 my @we_exclude_pat = @{ WE_Frontend::Publish->we_exclude };
89 0 my @exclude_pat = (@cvs_exclude_pat, @we_exclude_pat);
90 0 my @exclude;
91 my %additional;
92 0 ▶ if ($self->Config->project->stagingexceptpat) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Config->project->stagingexceptpat) 0 0 0
93 0 push @exclude_pat, @{ $self->Config->project->stagingexceptpat };
94 }
95 0 ▶ if ($self->Config->project->stagingexcept) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Config->project->stagingexcept) 0 0 0
96 0 push @exclude, @{ $self->Config->project->stagingexcept };
97 }
98 0 ▶ if ($self->Config->project->stagingadditional) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Config->project->stagingadditional) 0 0 0
99 0 %additional = %{ $self->Config->project->stagingadditional };
100 }
101  
102 0 ▶ if ($v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v) 0 0 0
103 0 print <<EOF;
104 Using rdist.
105 Rdist remote host: $livehost
106 0 ▶Rdist remote user: @{[ defined $liveuser ? $liveuser : "current" ]}
Branch: 1 branch
BranchTrueFalseTotal
defined $liveuser ? : 0 0 0
107 Rdist remote directory: $livedirectory
108 EOF
109 0 ▶ if (@extracgi) {
Branch: 1 branch
BranchTrueFalseTotal
if (@extracgi) 0 0 0
110 0 print "Rdist remote CGI directory: $livecgidirectory\n";
111 }
112 0 ▶ print ($deleteold ? "Delete unused remote files\n" : "Leave unused remote files\n");
Branch: 1 branch
BranchTrueFalseTotal
$deleteold ? : 0 0 0
113 0 ▶ if (@exclude) {
Branch: 1 branch
BranchTrueFalseTotal
if (@exclude) 0 0 0
114 0 print "Exclude files: @exclude\n";
115 }
116 0 ▶ if (@exclude_pat) {
Branch: 1 branch
BranchTrueFalseTotal
if (@exclude_pat) 0 0 0
117 0 print "Exclude patterns: @exclude_pat\n";
118 }
119 0 ▶ if (%additional) {
Branch: 1 branch
BranchTrueFalseTotal
if (%additional) 0 0 0
120 print "Additional files: ",
121 0 join(", ", map { "$_ => $additional{$_}" } keys %additional),
122 "\n";
123 }
124 0 print "\n";
125 }
126  
127 0 ▶ my $dest = (defined $liveuser ? "$liveuser\@" : "") . $livehost;
Branch: 1 branch
BranchTrueFalseTotal
defined $liveuser ? : 0 0 0
128  
129 0 my @directories;
130 my @files;
131  
132 0 my $diststring;
133 0 my @additional_cmd;
134 0 ▶ if (!$distfile) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($distfile) 0 0 0
135 0 $distfile = "-";
136  
137 0 my $exclude_pat_string = "";
138 0 my $exclude_string = "";
139 0 my @additional_install_string = ();
140  
141 0 ▶ if (@exclude_pat) {
Branch: 1 branch
BranchTrueFalseTotal
if (@exclude_pat) 0 0 0
142 $exclude_pat_string = "\texcept_pat (" .
143 0 join("\n", map { "\t\t " . glob2rx($_) } @exclude_pat) .
144 "\n\t\t );\n";
145 }
146 0 ▶ if (@exclude) {
Branch: 1 branch
BranchTrueFalseTotal
if (@exclude) 0 0 0
147 $exclude_string = "\texcept (" .
148 0 join("\n", map { "\t\t " . "$pubhtmldir/$_" } @exclude) .
149 "\n\t\t );\n";
150 }
151 0 ▶ if (%additional) {
Branch: 1 branch
BranchTrueFalseTotal
if (%additional) 0 0 0
152 0 my $i = 1;
153 0 ▶ while(my($k, $v) = each %additional) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %additional) 0 0 0
154 0 my $label = "additional$i";
155 0 push @additional_cmd, $label;
156 0 push @additional_install_string, <<EOF;
157 $label:
158 $pubhtmldir/$k -> $dest
159 install ${livedirectory}/$v ;
160  
161 EOF
162 0 $i++;
163 }
164 }
165  
166 # dump rdist bug? There have to be more than one file!
167 0 ▶ if (@extracgi == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@extracgi == 1) 0 0 0
168 0 push @extracgi, @extracgi;
169 }
170  
171 0 my $cgi_files = join(" ", map { "$cgidir/$_" } @extracgi);
172  
173 0 $diststring = <<EOF;
174 # distfile for publishing edit to www
175  
176 HTDOCS = ( $pubhtmldir )
177 CGIFILES = ( $cgi_files )
178  
179 #
180 # htdocs
181 #
182 htdocs:
183 \${HTDOCS} -> $dest
184 install ${livedirectory} ;
185 $exclude_pat_string
186 $exclude_string
187  
188 0 @{[ join("\n", @additional_install_string) ]}
189  
190 #
191 # cgi-bin
192 #
193 cgi:
194 \${CGIFILES} -> $dest
195 install ${livecgidirectory} ;
196  
197 EOF
198  
199 0 ▶ if ($v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v) 0 0 0
200 0 my $line = 1;
201 0 warn join("\n", map { $line++." ".$_} split /\n/, $diststring);
202 }
203 }
204  
205 0 my $cmd = "rdist -f $distfile";
206 0 ▶ if (!$do_exec) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($do_exec) 0 0 0
207 0 $cmd .= " -n";
208 }
209 0 ▶ if ($deleteold) {
Branch: 1 branch
BranchTrueFalseTotal
if ($deleteold) 0 0 0
210 0 $cmd .= " -oremove";
211 }
212  
213 0 $cmd .= " " . join(" ", qw(htdocs cgi), @additional_cmd);
214  
215 0 ▶ if ($distfile eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($distfile eq '-') { } 0 0 0
216 0 ▶ warn $cmd if $v;
Branch: 1 branch
BranchTrueFalseTotal
if $v 0 0 0
217 0 ▶ open(RDIST, "| $cmd") or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open RDIST, "| $cmd" or die $! 0 0 0
218 0 print RDIST $diststring;
219 0 close RDIST;
220 } else {
221 0 system($cmd);
222 0 ▶ die "Error while executing $cmd" if $?/256!=0;
Branch: 1 branch
BranchTrueFalseTotal
if $? / 256 != 0 0 0 0
223 }
224  
225 0 return;
226 }
227  
228 0 ▶sub glob2rx {
Subroutine glob2rx: not called CC=1 SCAR=6.9
229 0 my $glob = shift;
230 0 my %glob2rx = ("*" => ".*",
231 "." => "\\.",
232 "#" => "\\#",
233 ); # XXX more to follow
234 0 $glob =~ s/([\.\*\#])/$glob2rx{$1}/g;
235 0 $glob = ".*/" . $glob . ".*";
236 0 $glob =~ s/\Q.*.*/.*/g;
237 0 $glob;
238 }
239  
240 # REPO BEGIN
241 # REPO NAME is_in_path /home/e/eserte/src/repository
242 # REPO MD5 1aa226739da7a8178372aa9520d85589
243 0 ▶sub is_in_path {
Subroutine is_in_path: not called CC=6 SCAR=37.4
244 0 my($prog) = @_;
245 0 ▶ return $prog if (file_name_is_absolute($prog) and -x $prog);
Branch: 1 branch
BranchTrueFalseTotal
if file_name_is_absolute($prog) and -x $prog 0 0 0
Condition0%0/3
file_name_is_absolute($prog) and -x $prog
!ll&&!rl&&r
000
MC/DC0%0/2
file_name_is_absolute($prog) and -x $prog
file_name_is_absolute($prog) -x $prog
Truth table0%0/3
A and B
A= file_name_is_absolute($prog)B= -x $prog
ABresult
0X0
100
111
246 0 require Config;
247 0 ▶ my $sep = $Config::Config{'path_sep'} || ':';
Condition0%0/2
$Config::Config{'path_sep'} || ':'
l!l
00
MC/DC0%0/1
$Config::Config{'path_sep'} || ':'
$Config::Config{'path_sep'}
Truth table0%0/2
A
A= $Config::Config{'path_sep'}
Aresult
11
00
248 0 foreach (split(/$sep/o, $ENV{PATH})) {
249 0 ▶ return "$_/$prog" if -x "$_/$prog";
Branch: 1 branch
BranchTrueFalseTotal
if -x "$_/$prog" 0 0 0
250 }
251 0 undef;
252 }
253 # REPO END
254  
255 # REPO BEGIN
256 # REPO NAME file_name_is_absolute /home/e/eserte/src/repository
257 # REPO MD5 a77759517bc00f13c52bb91d861d07d0
258 0 ▶sub file_name_is_absolute {
Subroutine file_name_is_absolute: not called CC=3 SCAR=24.8
259 0 my $file = shift;
260 0 my $r;
261 0 eval {
262 0 require File::Spec;
263 0 $r = File::Spec->file_name_is_absolute($file);
264 };
265 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
266 0 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 0 0
267 0 $r = ($file =~ m;^([a-z]:(/|\\)|\\\\|//);i);
268 } else {
269 0 $r = ($file =~ m|^/|);
270 }
271 }
272 0 $r;
273 }
274 # REPO END
275  
276 1 1;
277  
278 __END__
« WE_Frontend/Publish/FTP_MD5Sync.pm ↑ Summary WE_Frontend/Publish/Rsync.pm »