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