WE_Frontend/Publish/FTP.pm

filter: Statementstmt 30.5% 22 / 72 Branchbran 2.6% 1 / 38 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 77.7% 7 / 9 Podpod n/a totaltotal 19.6% 30 / 153 CC 29 SCAR 54.7
CC
29
Cov
18%
publish_ftp
408.5
__ANON__
72.0
BEGIN
6.8
CRAP 237.1
« WebEditor/OldFeatures/SystemInfo.pm ↑ Summary WE_Frontend/Plugin/TextTable.pm »
1 # -*- perl -*-
2  
3 #
4 # $Id: FTP.pm,v 1.7 2005/02/18 14:03:39 cmuellermeta Exp $
5 # Author: Slaven Rezic
6 #
7 # Copyright (C) 2001,2002 Online Office Berlin. All rights reserved.
8 # Copyright (c) 2002 Slaven Rezic. All rights reserved.
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 # Mail: slaven@rezic.de
13 # WWW: http://we-framework.sourceforge.net
14 #
15  
16 package WE_Frontend::Publish::FTP;
17  
18 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 $VERSION = sprintf("%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/);
20  
21 package WE_Frontend::Main;
22  
23 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 1 ▶use Net::FTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 ▶use WE_Frontend::Publish;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 1 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=19.2
30 1 ▶ if ($] < 5.006) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.006") 0 1 1
31 0 $INC{"warnings.pm"}++;
32 0 eval q{
33 package warnings;
34 sub unimport { }
35 0 ▶ }; die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
36 }
37 }
38  
39 {
40 1 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶ use WE::Util::Functions qw(_save_pwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
42 }
43  
44 1 ▶sub publish_ftp {
Subroutine publish_ftp: not called CC=20 SCAR=60.1
45 0 my($self, %args) = @_;
46  
47 0 my $v = delete $args{-verbose};
48  
49 0 my $liveuser = $self->Config->staging->user;
50 0 my $livepassword = $self->Config->staging->password;
51 0 my $livedirectory = $self->Config->staging->directory;
52 0 my $livecgidirectory = $self->Config->staging->cgidirectory;
53 0 my $livehost = $self->Config->staging->host;
54 0 my $pubhtmldir = $self->Config->paths->pubhtmldir;
55 my @extracgi = (ref $self->Config->project->stagingextracgi eq 'ARRAY'
56 0 ▶ ? @{ $self->Config->project->stagingextracgi }
Branch: 1 branch
BranchTrueFalseTotal
ref $self->Config->project->stagingextracgi eq 'ARRAY' ? : 0 0 0
57 : ()
58 );
59  
60 0 ▶ if (!defined $liveuser || $liveuser eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $liveuser or $liveuser eq "") 0 0 0
Condition0%0/3
not defined $liveuser or $liveuser eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $liveuser or $liveuser eq ""
not defined $liveuser $liveuser eq ""
Truth table0%0/3
not(A) or B
A= not defined $liveuserB= $liveuser eq ""
ABresult
1X1
011
000
61 0 die "The FTP user is missing (config member WEsiteinfo->staging->user)";
62 }
63 0 ▶ if (!defined $livepassword || $livepassword eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $livepassword or $livepassword eq "") 0 0 0
Condition0%0/3
not defined $livepassword or $livepassword eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $livepassword or $livepassword eq ""
not defined $livepassword $livepassword eq ""
Truth table0%0/3
not(A) or B
A= not defined $livepasswordB= $livepassword eq ""
ABresult
1X1
011
000
64 0 die "The FTP password is missing (config member WEsiteinfo->staging->password)";
65 }
66 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
67 0 die "The target FTP host is missing (config member WEsiteinfo->staging->host)";
68 }
69 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
70 0 die "The publish html directory is missing (config member WEsiteinfo->paths->pubhtmldir)";
71 }
72 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
73 0 die "Extra CGI scripts are defined (@extracgi),
74 but the WEsiteinfo->staging->cgidirectory config is missing";
75 }
76  
77 0 ▶ if ($v) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v) 0 0 0
78 0 print <<EOF
79 Using FTP Protocol.
80 FTP remote host: $livehost
81 FTP remote user: $liveuser
82 FTP remote directory: $livedirectory
83 0 ▶@{[ @extracgi ? "FTP remote CGI directory: $livecgidirectory" : "" ]}
Branch: 1 branch
BranchTrueFalseTotal
@extracgi ? : 0 0 0
84  
85 EOF
86 }
87  
88 0 ▶ my $ftp = Net::FTP->new($livehost, Debug => 0) or die "Can't open FTP connection to $livehost: $@";
Branch: 1 branch
BranchTrueFalseTotal
my $ftp = "Net::FTP"->new($livehost, "Debug", 0) or die "Can't open FTP connection to ${livehost}: $@" 0 0 0
89 0 ▶ $ftp->login($liveuser, $livepassword) or die "Can't login with $liveuser";
Branch: 1 branch
BranchTrueFalseTotal
$ftp->login($liveuser, $livepassword) or die "Can't login with $liveuser" 0 0 0
90 0 $ftp->pasv();
91 0 $ftp->binary();
92 0 ▶ if (defined $livedirectory && $livedirectory ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $livedirectory and $livedirectory ne "") 0 0 0
Condition0%0/3
defined $livedirectory and $livedirectory ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $livedirectory and $livedirectory ne ""
defined $livedirectory $livedirectory ne ""
Truth table0%0/3
A and B
A= defined $livedirectoryB= $livedirectory ne ""
ABresult
0X0
100
111
93 0 ▶ $ftp->cwd($livedirectory) or die "Can't remote chdir to $livedirectory";
Branch: 1 branch
BranchTrueFalseTotal
$ftp->cwd($livedirectory) or die "Can't remote chdir to $livedirectory" 0 0 0
94 }
95  
96 0 my $ret = WE_Frontend::Publish::get_files_to_publish($self, %args);
97 0 my @directories = @{ $ret->{Directories} };
98 0 my @files = @{ $ret->{Files} };
99  
100 0 ▶ _save_pwd {
Subroutine __ANON__: not called CC=8 SCAR=42.8
101 0 ▶ chdir $pubhtmldir || die "Can't change directory to $pubhtmldir: $!";
Branch: 1 branch
BranchTrueFalseTotal
chdir $pubhtmldir or die "Can't change directory to ${pubhtmldir}: $!" 0 0 0
102  
103 0 foreach my $dir (@directories) {
104 0 ▶ if ($v) { print "Create folder $dir\n" }
Branch: 1 branch
BranchTrueFalseTotal
if ($v) 0 0 0
105 0 $ftp->mkdir($dir);
106 }
107  
108 0 foreach my $file (@files) {
109 0 ▶ if ($v) { print "Create document $file\n" }
Branch: 1 branch
BranchTrueFalseTotal
if ($v) 0 0 0
110 0 ▶ if (!-r $file) { warn "The local file $pubhtmldir/$file is not readable" }
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $file) 0 0 0
111 0 ▶ $ftp->put($file, $file) or warn "Can't put $pubhtmldir/$file to remote host $livehost";
Branch: 1 branch
BranchTrueFalseTotal
$ftp->put($file, $file) or warn "Can't put $pubhtmldir/$file to remote host $livehost" 0 0 0
112 }
113  
114 0 };
115  
116 0 return {Directories => \@directories,
117 Files => \@files,
118 };
119 }
120  
121 1 1;
122  
123 __END__
« WebEditor/OldFeatures/SystemInfo.pm ↑ Summary WE_Frontend/Plugin/TextTable.pm »