Changeset 193
- Timestamp:
- 01/13/06 15:08:27 (18 years ago)
- Location:
- trunk/soft/ObsData
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/soft/ObsData/ObsData.pm
- Property cvs2svn:cvs-rev changed from 1.49 to 1.50
r189 r193 268 268 grep { $_ !~ /^Obs\s+/ } 269 269 grep { !$self->is_obs($_) } $self->{config}->Sections; 270 }271 272 =head2 match_data_type($datatype, $label)273 274 Check if $label match the regexp associate to $datatype, return match values275 or nothing if no match.276 277 =cut278 279 sub match_data_type {280 my ($self, $datatype, $label) = @_;281 my $regexp = $self->getvalue($datatype, 'match') or return;282 my @data = $label =~ /$regexp/;283 if (! @data) {284 return;285 }286 return @data;287 }288 289 =head2 find_match_data_type($label)290 291 Check if $label match one of the regexp associate to datatype in the292 configuration, if yes, return the datatype and assiociate values, else293 return nothing294 295 =cut296 297 sub find_match_data_type {298 my ($self, $label) = @_;299 foreach my $datatype ($self->list_datatype) {300 my @data = $self->match_data_type($datatype, $label);301 if (@data) {302 return($datatype, @data);303 }304 }305 }306 307 =head2 build_dest_filename($label, $datatype, $magic_words)308 309 Build the destination file from original filename ($label) and optionnaly310 from $datatype. Return the datatype and the filename. If no datatype apply,311 return undef, if destination file cannot be build, return only the datatype.312 313 If $datatype is not defined, the function try to find the right datatype from314 configuration.315 316 =cut317 318 sub build_dest_filename {319 my ($self, $label, $datatype, $magic_words) = @_;320 my @data;321 if ($datatype) {322 @data = $self->match_data_type($datatype, $label);323 } else {324 ($datatype, @data) = $self->find_match_data_type($label);325 }326 327 if ($datatype && @data) {328 my $dest = $self->getvalue($datatype, 'dest');329 my @matcharg = split(/\s+/, $self->getvalue($datatype, 'matcharg'));330 my @destarg = split(/\s+/, $self->getvalue($datatype, 'destarg'));331 my @gmtime = gmtime;332 my %val;333 foreach (@matcharg) {334 $val{$_} = shift(@data);335 }336 foreach (keys %{$magic_words || {}}) {337 $val{'$' . $_} = $magic_words->{$_};338 }339 $val{'$datafile'} = $label;340 return ($datatype, sprintf(341 $dest,342 map { m/^%/ ? strftime($_, @gmtime) : $val{$_} } @destarg,343 ));344 }345 undef;346 270 } 347 271 -
trunk/soft/ObsData/ObsData/Repository.pm
- Property cvs2svn:cvs-rev changed from 1.69 to 1.70
r192 r193 506 506 } 507 507 508 =head3 find_match_data_type($label) 509 510 Check if datafile match one of the regexp associate to datatype in the 511 configuration, if yes, return the datatype and assiociate values, else 512 return nothing 513 514 =cut 515 508 516 sub match_data_type { 509 517 my ($self, $datafile) = @_; … … 517 525 } 518 526 527 =head3 build_dest_filename($datafile) 528 529 Build the destination file from original filename and optionnaly. 530 Return the datatype and the filename. If no datatype apply, 531 return undef, if destination file cannot be build, return only the datatype. 532 533 If object datatype is not defined, the function try to find the right datatype from 534 configuration. 535 536 =cut 537 538 519 539 sub build_dest_filename { 520 540 my ($self, $datafile) = @_; … … 556 576 my ($self, $datafile) = @_; 557 577 558 my ($t, $d) = $self-> {obsdata}->build_dest_filename(578 my ($t, $d) = $self->build_dest_filename( 559 579 $datafile, 560 580 $self->{datatype} -
trunk/soft/ObsData/t/O-02.t
- Property cvs2svn:cvs-rev changed from 1.18 to 1.19
r169 r193 4 4 use warnings; 5 5 6 use Test::More tests => 2 9;6 use Test::More tests => 20; 7 7 use File::Temp qw(tempdir); 8 8 use POSIX qw(strftime); … … 41 41 print STDERR join(" ", $o->list_datatype); 42 42 43 # Testing match rules44 ok($o->match_data_type('ozone', 'ozone12'), "String matching setting");45 ok(!$o->match_data_type('ozone', 'foo12'), "String no matching setting");46 47 ok($o->find_match_data_type('ozone12'), "is able to find good datatype");48 ok(!$o->find_match_data_type('foo12'), "is able to find good datatype");49 50 ok(51 eq_array(52 [ $o->build_dest_filename('ozone12') ],53 [ 'ozone', '12/dest12' ]54 ),55 "Can build dest string"56 );57 ok(58 eq_array(59 [ $o->build_dest_filename('ozone12', 'ozone') ],60 [ 'ozone', '12/dest12' ]61 ),62 "Can build dest string with datatype"63 );64 ok(65 eq_array(66 [ $o->build_dest_filename('oxygene12', 'oxygene') ],67 [ 'oxygene', strftime("%Y/dest12/oxygene12", gmtime) ]68 ),69 "Can build dest string with datatype"70 );71 ok(!defined($o->build_dest_filename('foo12')), "Return undef if no match");72 ok(!defined($o->build_dest_filename('ozone12', 'oxygene')), "Return undef if no match");73 74 43 $o = undef; # Explicit destroy
Note: See TracChangeset
for help on using the changeset viewer.