| 3 |
# $Id$ |
# $Id$ |
| 4 |
# |
# |
| 5 |
# $Log$ |
# $Log$ |
| 6 |
|
# Revision 1.13 2002/12/23 04:25:13 joko |
| 7 |
|
# + sub bool2status |
| 8 |
|
# |
| 9 |
|
# Revision 1.12 2002/12/22 14:15:02 joko |
| 10 |
|
# + sub mkObject |
| 11 |
|
# |
| 12 |
|
# Revision 1.11 2002/12/19 16:27:17 joko |
| 13 |
|
# +- renamed 'cmd' to 'run_cmd' |
| 14 |
|
# |
| 15 |
|
# Revision 1.10 2002/12/19 01:05:35 joko |
| 16 |
|
# + sub today |
| 17 |
|
# |
| 18 |
|
# Revision 1.9 2002/12/05 13:54:00 joko |
| 19 |
|
# + fix: let 'deep_copy' print its message out (instead of die) |
| 20 |
|
# |
| 21 |
|
# Revision 1.8 2002/12/01 22:11:35 joko |
| 22 |
|
# + sub cmd |
| 23 |
|
# + sub run_cmds |
| 24 |
|
# |
| 25 |
|
# Revision 1.7 2002/11/29 04:44:53 joko |
| 26 |
|
# - sub array_getRelations |
| 27 |
|
# + sub getNewPerlObjectByPkgName |
| 28 |
|
# |
| 29 |
|
# Revision 1.6 2002/11/17 07:18:59 joko |
| 30 |
|
# + sub deep_copy |
| 31 |
|
# |
| 32 |
|
# Revision 1.5 2002/10/27 18:34:28 joko |
| 33 |
|
# + sub now |
| 34 |
|
# |
| 35 |
|
# Revision 1.4 2002/08/16 19:06:39 cvsjoko |
| 36 |
|
# + sub getDirList |
| 37 |
|
# |
| 38 |
# Revision 1.3 2002/07/19 18:13:50 cvsjoko |
# Revision 1.3 2002/07/19 18:13:50 cvsjoko |
| 39 |
# no message |
# no message |
| 40 |
# |
# |
| 49 |
|
|
| 50 |
package libp; |
package libp; |
| 51 |
|
|
| 52 |
|
use strict; |
| 53 |
|
use warnings; |
| 54 |
|
|
| 55 |
require Exporter; |
require Exporter; |
| 56 |
@ISA = qw( Exporter ); |
our @ISA = qw( Exporter ); |
| 57 |
@EXPORT = qw( |
our @EXPORT_OK = qw( |
| 58 |
Dumper |
Dumper |
| 59 |
md5 md5_hex md5_base64 |
md5 md5_hex md5_base64 |
| 60 |
ParseDate UnixDate |
ParseDate UnixDate |
| 61 |
strftime |
strftime |
|
stripHtml stripSpaces stripNewLines toReal trim |
|
| 62 |
croak |
croak |
| 63 |
|
|
| 64 |
|
stripHtml stripSpaces stripNewLines toReal trim |
| 65 |
array_getDifference |
array_getDifference |
| 66 |
|
getDirList |
| 67 |
|
now today |
| 68 |
|
deep_copy |
| 69 |
|
getNewPerlObjectByPkgName |
| 70 |
|
run_cmd run_cmds |
| 71 |
|
mkObject |
| 72 |
|
bool2status |
| 73 |
); |
); |
| 74 |
|
|
|
use strict; |
|
|
use warnings; |
|
|
|
|
| 75 |
use Data::Dumper; |
use Data::Dumper; |
| 76 |
use Digest::MD5 qw(md5 md5_hex md5_base64); |
use Digest::MD5 qw(md5 md5_hex md5_base64); |
| 77 |
|
|
| 87 |
|
|
| 88 |
use Carp; |
use Carp; |
| 89 |
|
|
| 90 |
|
use DirHandle; |
| 91 |
|
|
| 92 |
|
|
| 93 |
######################################## |
######################################## |
| 94 |
|
|
| 139 |
return $result; |
return $result; |
| 140 |
} |
} |
| 141 |
|
|
| 142 |
sub array_getRelations { |
|
| 143 |
my $a_ref = shift; |
|
| 144 |
my $b_ref = shift; |
|
| 145 |
my @a = @{$a_ref}; |
# ============================================= |
| 146 |
my @b = @{$b_ref}; |
# "global" vars used in directory-recursive-parsing |
| 147 |
|
my $dirlist_buf; |
| 148 |
my @isect = my @diff = my @union = (); |
my @dirlist_path; |
| 149 |
my $e; |
my $dirlist_base; |
| 150 |
my %count; |
|
| 151 |
|
sub entry_callback { |
| 152 |
foreach $e (@a, @b) { $count{$e}++ } |
|
| 153 |
|
my $entry = shift; |
| 154 |
foreach $e (keys %count) { |
|
| 155 |
push(@union, $e); |
# CHECKS |
| 156 |
push @{ $count{$e} == 2 ? \@isect : \@diff }, $e; |
# dont't use this: |
| 157 |
|
if ($entry eq '.' || $entry eq '..') { return; } |
| 158 |
|
|
| 159 |
|
# PREPARE |
| 160 |
|
# prepare path to current entry |
| 161 |
|
my $cur_entry = join('/', @dirlist_path, $entry); |
| 162 |
|
# prepare path to current entry (absolute) |
| 163 |
|
my $cur_entry_abs = join('/', $dirlist_base, @dirlist_path, $entry); |
| 164 |
|
|
| 165 |
|
# ENTRY |
| 166 |
|
# add current entry to buffer |
| 167 |
|
$dirlist_buf .= $cur_entry . "\n"; |
| 168 |
|
|
| 169 |
|
# (SUB-)DIRECTORY |
| 170 |
|
# check if current entry is a (sub-)directory ... |
| 171 |
|
if (-d $cur_entry_abs) { |
| 172 |
|
push @dirlist_path, $cur_entry; |
| 173 |
|
# ... and parse this (recursion here!!!) |
| 174 |
|
iterate_path($cur_entry_abs); |
| 175 |
|
pop @dirlist_path; |
| 176 |
|
} |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
sub iterate_path { |
| 180 |
|
|
| 181 |
|
my $path = shift; |
| 182 |
|
|
| 183 |
|
# create new "DirHandle"-object |
| 184 |
|
my $d = new DirHandle $path; |
| 185 |
|
if (defined $d) { |
| 186 |
|
|
| 187 |
|
# iterate through all entries in $path ($d->read) and call out entry-handler on each entry |
| 188 |
|
while (defined(my $line = $d->read)) { |
| 189 |
|
entry_callback($line); |
| 190 |
|
} |
| 191 |
|
|
| 192 |
|
undef $d; |
| 193 |
} |
} |
| 194 |
|
} |
| 195 |
my $result = { |
|
| 196 |
union => \@union, |
sub getDirList { |
| 197 |
isect => \@isect, |
|
| 198 |
diff => \@diff, |
$dirlist_base = shift; |
| 199 |
}; |
|
| 200 |
|
# reset vars |
| 201 |
|
$dirlist_buf = ''; |
| 202 |
|
@dirlist_path = (); |
| 203 |
|
|
| 204 |
|
# start parsing file-structure |
| 205 |
|
iterate_path($dirlist_base); |
| 206 |
|
|
| 207 |
|
# return complete list of directory-content including files and subdirs |
| 208 |
|
# entries are newline (\n) - seperated |
| 209 |
|
return $dirlist_buf; |
| 210 |
|
|
| 211 |
|
} |
| 212 |
|
# ============================================= |
| 213 |
|
|
| 214 |
|
|
| 215 |
|
sub now { |
| 216 |
|
return strftime("%Y-%m-%d %H:%M:%S", localtime); |
| 217 |
|
} |
| 218 |
|
|
| 219 |
|
sub today { |
| 220 |
|
return strftime("%Y-%m-%d", localtime); |
| 221 |
|
} |
| 222 |
|
|
| 223 |
|
# ACK's go to ... |
| 224 |
|
sub deep_copy { |
| 225 |
|
my $this = shift; |
| 226 |
|
if (not ref $this) { |
| 227 |
|
$this; |
| 228 |
|
} elsif (ref $this eq "ARRAY") { |
| 229 |
|
[map deep_copy($_), @$this]; |
| 230 |
|
} elsif (ref $this eq "HASH") { |
| 231 |
|
+{map { $_ => deep_copy($this->{$_}) } keys %$this}; |
| 232 |
|
} elsif (ref $this eq "CODE") { |
| 233 |
|
$this; |
| 234 |
|
#} else { die "deep_copy asks: what type is $this?" } |
| 235 |
|
} else { print "deep_copy asks: what type is $this?", "\n"; } |
| 236 |
|
} |
| 237 |
|
|
| 238 |
|
sub getNewPerlObjectByPkgName { |
| 239 |
|
my $pkgname = shift; |
| 240 |
|
my $args = shift; |
| 241 |
|
#$logger->debug( __PACKAGE__ . "->getNewPerlObjectByPkgName( pkgname $pkgname args $args )" ); |
| 242 |
|
my $evstring = "use $pkgname;"; |
| 243 |
|
eval($evstring); |
| 244 |
|
#$@ && $logger->error( __PACKAGE__ . ':' . __LINE__ . " Error in eval $evstring: " . $@ ); |
| 245 |
|
$@ && print( __PACKAGE__ . ':' . __LINE__ . " Error in eval \"$evstring\": " . $@ ); |
| 246 |
|
return $pkgname->new($args); |
| 247 |
|
} |
| 248 |
|
|
| 249 |
|
sub mkObject { |
| 250 |
|
my $pkgname = shift; |
| 251 |
|
#my $args = shift; |
| 252 |
|
#$logger->debug( __PACKAGE__ . "->getNewPerlObjectByPkgName( pkgname $pkgname args $args )" ); |
| 253 |
|
my $evstring = "use $pkgname;"; |
| 254 |
|
eval($evstring); |
| 255 |
|
#$@ && $logger->error( __PACKAGE__ . ':' . __LINE__ . " Error in eval $evstring: " . $@ ); |
| 256 |
|
$@ && print( __PACKAGE__ . ':' . __LINE__ . " Error in eval \"$evstring\": " . $@ ); |
| 257 |
|
return $pkgname->new(@_); |
| 258 |
|
} |
| 259 |
|
|
| 260 |
|
sub run_cmd { |
| 261 |
|
my $cmd = shift; |
| 262 |
|
$cmd = 'perl ' . $cmd; |
| 263 |
|
my $sep = "-" x 90; |
| 264 |
|
print $sep, "\n"; |
| 265 |
|
print " ", $cmd, "\n"; |
| 266 |
|
print $sep, "\n"; |
| 267 |
|
system($cmd); |
| 268 |
|
print "\n"; |
| 269 |
|
} |
| 270 |
|
|
| 271 |
|
sub run_cmds { |
| 272 |
|
foreach (@_) { |
| 273 |
|
run_cmd($_); |
| 274 |
|
} |
| 275 |
} |
} |
| 276 |
|
|
| 277 |
sub array_getDifference { |
sub bool2status { |
| 278 |
my $res = array_getRelations(shift, shift); |
my $bool = shift; |
| 279 |
return $res->{diff}; |
return ($bool ? 'ok' : 'failed'); |
| 280 |
} |
} |
| 281 |
|
|
| 282 |
1; |
1; |