| 1 | # -*- perl -*- | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | # $Id: Publish.pm,v 1.7 2004/06/10 13:18:02 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; | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | $VERSION = sprintf("%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use File::Find; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use WE::Util::Functions qw(_save_pwd); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =head1 NAME | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | WE_Frontend::Publish - common used variables | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | use WE_Frontend::Publish; | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =over 4 | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =item cvs_exclude | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | Return a list of exclude files for publish methods. This is the same as | ||||||||||||||||||||||||||||
| 43 | CVS is ignoring by default. | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | =cut | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub cvs_exclude { | ||||||||||||||||||||||||||
|
Subroutine
cvs_exclude: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 0 | [qw(RCS SCCS CVS CVS.adm RCSLOG .svn cvslog.* tags TAGS | |||||||||||||||||||||||||||
| 49 | .make.state .nse_depinfo *~ *.old *.bak | ||||||||||||||||||||||||||||
| 50 | *.BAK *.orig *.rej .del-* *.a *.o *.obj *.so *.Z | ||||||||||||||||||||||||||||
| 51 | *.elc *.ln core), '#*', '.#*', ',*']; | ||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # hmmm... I can't get the rdist regex right, so use only a minimal version | ||||||||||||||||||||||||||||
| 55 | # of cvs_exclude | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub _min_cvs_exclude { | ||||||||||||||||||||||||||
|
Subroutine
_min_cvs_exclude: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 57 | 0 | [qw(RCS CVS .svn *~ *.old *.bak *.BAK *.orig)]; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =item we_exclude | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | Return a list of additional exclude files related to the web.editor | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub we_exclude { | ||||||||||||||||||||||||||
|
Subroutine
we_exclude: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 0 | [qw(.cvsignore cgi-bin/ we/)]; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =item get_files_to_publish($frontend_object, %args) | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | Return a list of files and directories to publish to the remote side. This | ||||||||||||||||||||||||||||
| 73 | is a static method. | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =cut | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub get_files_to_publish { | ||||||||||||||||||||||||||
|
Subroutine
get_files_to_publish: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 0 | my($self, %args) = @_; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | my $since = delete $args{-since}; | |||||||||||||||||||||||||||
| 81 | 0 | my $pubhtmldir = $self->Config->paths->pubhtmldir; | |||||||||||||||||||||||||||
| 82 | my @extracgi = (ref $self->Config->project->stagingextracgi eq 'ARRAY' | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | ? @{ $self->Config->project->stagingextracgi } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | : () | ||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | my @cvs_exclude = @{ WE_Frontend::Publish->cvs_exclude }; | |||||||||||||||||||||||||||
| 88 | 0 | my @we_exclude = @{ WE_Frontend::Publish->we_exclude }; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | my @directories; | |||||||||||||||||||||||||||
| 91 | my @files; | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | my @cgi_directories; | |||||||||||||||||||||||||||
| 94 | 0 | my @cgi_files; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | my $skip_file = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if (defined $since) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | my(@s) = stat $_; | |||||||||||||||||||||||||||
| 99 | 0 | ▶ | if (!@s) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | warn "Can't stat file $_: $!"; | |||||||||||||||||||||||||||
| 101 | 0 | return 1; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ($s[9] <= $since) { # old file, don't publish | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | return 1; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | 0 | 0; | |||||||||||||||||||||||||||
| 108 | 0 | }; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | my $wanted = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | return if $_ eq '.' || $_ eq '..'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_ eq "." or $_ eq ".."
MC/DC0%0/2
$_ eq "." or $_ eq ".."
$_ eq "."
$_ eq ".."
Truth table0%0/3
A or B
A= $_ eq "."B= $_ eq ".."
| |||||||||||||||||||||||||||||
| 112 | 0 | foreach my $exc_ (@cvs_exclude, @we_exclude) { | |||||||||||||||||||||||||||
| 113 | 0 | my $exc = $exc_; | |||||||||||||||||||||||||||
| 114 | 0 | ▶ | if ($_ eq $exc) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if (-d $_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | $File::Find::prune = 1; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | 0 | return; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | 0 | $exc =~ s/\./\\./g; | |||||||||||||||||||||||||||
| 121 | 0 | $exc =~ s/\*/.*/g; | |||||||||||||||||||||||||||
| 122 | 0 | $exc =~ s|/$||; | |||||||||||||||||||||||||||
| 123 | 0 | ▶ | if ($_ =~ /^$exc$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if (-d $_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | $File::Find::prune = 1; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | 0 | return; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 0 | (my $name = $File::Find::name) =~ s|^\./||; | |||||||||||||||||||||||||||
| 131 | 0 | ▶ | if (-d $_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 0 | push @directories, $name; | |||||||||||||||||||||||||||
| 133 | } else { | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | return if $skip_file->($_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | push @files, $name; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | 0 | }; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | _save_pwd { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | chdir $pubhtmldir || die $!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 0 | find($wanted, "."); | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | push @directories, @{ $args{-adddirectories} } | |||||||||||||||||||||||||||
| 146 | 0 | ▶ | if $args{-adddirectories}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 0 | push @files, @{ $args{-addfiles} } | |||||||||||||||||||||||||||
| 148 | 0 | ▶ | if $args{-addfiles}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if (@extracgi) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 0 | foreach my $cgi (@extracgi) { | |||||||||||||||||||||||||||
| 152 | 0 | my $f = "cgi-bin/$cgi"; | |||||||||||||||||||||||||||
| 153 | 0 | my $dir = dirname($f); | |||||||||||||||||||||||||||
| 154 | 0 | ▶ | if (!$skip_file->($f)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | push @files, $f | ||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if (!grep { $f eq $_ } @files); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | push @directories, $dir | ||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if (!grep { $dir eq $_ } @directories); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | # to make sure that parent directories are always created before | ||||||||||||||||||||||||||||
| 164 | # the children directories | ||||||||||||||||||||||||||||
| 165 | 0 | @directories = sort { length($a) <=> length($b) } @directories; | |||||||||||||||||||||||||||
| 166 | 0 | }; | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | return {Directories => \@directories, | |||||||||||||||||||||||||||
| 169 | Files => \@files, | ||||||||||||||||||||||||||||
| 170 | }; | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 1 | 1; | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | __END__ | ||||||||||||||||||||||||||||