/[cvs]/nfo/perl/libs/Data/Rap/Metadata.pm
ViewVC logotype

Diff of /nfo/perl/libs/Data/Rap/Metadata.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by joko, Thu Feb 20 20:04:35 2003 UTC revision 1.5 by joko, Sun Jun 20 23:00:23 2004 UTC
# Line 2  Line 2 
2  ##  $Id$  ##  $Id$
3  ## ----------------------------------------------------------------------  ## ----------------------------------------------------------------------
4  ##  $Log$  ##  $Log$
5    ##  Revision 1.5  2004/06/20 23:00:23  joko
6    ##  minor fix: now creates cache-file in same directory where rap.xml is
7    ##
8    ##  Revision 1.4  2004/06/20 16:12:24  joko
9    ##  + sub indexTargets
10    ##  modified getTargetDetails to use cached target details
11    ##
12    ##  Revision 1.3  2003/03/29 07:13:19  joko
13    ##  better exception handling if target was not found in xml
14    ##
15  ##  Revision 1.2  2003/02/20 20:04:35  joko  ##  Revision 1.2  2003/02/20 20:04:35  joko
16  ##  renamed methods  ##  renamed methods
17  ##  - refactored xml-specific code to Data::Storage::Handler::XML  ##  - refactored xml-specific code to Data::Storage::Handler::XML
# Line 20  use warnings; Line 30  use warnings;
30    
31  use Data::Dumper;  use Data::Dumper;
32  use DesignPattern::Object;  use DesignPattern::Object;
33    use Storable;
34    use File::Basename qw( dirname );
35    
36    
37  sub accessMetadata {  sub accessMetadata {
# Line 38  sub accessMetadata { Line 50  sub accessMetadata {
50  sub getTargetList {  sub getTargetList {
51    my $self = shift;    my $self = shift;
52    
53    $self->log( "Reading Job Database from XML.", 'notice' );    $self->log( "Reading database of targets (dot) from XML.", 'notice' );
54    
55    # prepare access to metadata (assure instantiated storage handle)    # prepare access to metadata (assure instantiated storage handle)
56    my $mdbe = $self->accessMetadata();    my $mdbe = $self->accessMetadata();
# Line 80  sub getTargetList { Line 92  sub getTargetList {
92  sub getTargetDetails {  sub getTargetDetails {
93    my $self = shift;    my $self = shift;
94    my $target = shift;    my $target = shift;
95      my $options = shift;
96      
97      # check cache and return result from there
98      if (my $result = $self->{cache}->{targets}->{$target} and not $options->{force}) {
99        return $result;
100      }
101      
102      # get metadata for single task from storage
103    my $mdbe = $self->accessMetadata();    my $mdbe = $self->accessMetadata();
104    $mdbe->sendQuery("*/target[\@name=\"$target\"]");    $mdbe->sendQuery("*/target[\@name=\"$target\"]");
105      
106      # FIXME: this is wrong behaviour! upper statement should return a proper
107      # result, which itself (already) has the method 'isEmpty' or similar...
108      if ($mdbe->isEmpty()) {
109        $self->log( "Target '$target' not found.", 'notice' );
110        return;
111      }
112      
113    my $tree = $mdbe->toEasyTree();    my $tree = $mdbe->toEasyTree();
114      
115      # trace
116      #print Dumper($tree);
117      #exit;
118      
119    return $tree;    return $tree;
120  }  }
121    
122    sub indexTargets {
123      my $self = shift;
124      my $options = shift;
125      
126      # determine filename for cache-file
127      my $filename = 'rap.xml.cache';
128      if (my $rapfile = $self->{__rap}->{filename}) {
129        if (my $path = dirname($rapfile)) {
130          $filename = $path . '/' . $filename;
131        }
132      }
133      
134      if ($options->{build}) {
135        $self->log("Building index of Targets", 'notice');
136        # clear cache
137        delete $self->{cache}->{targets};
138        my $list = $self->getTargetList();
139        foreach my $target (@$list) {
140          $self->log("Reading target: $target->{name}", 'info');
141          my $details = $self->getTargetDetails($target->{name}, { force => 1 });
142          $self->{cache}->{targets}->{$target->{name}} = $details;
143        }
144        store $self->{cache}->{targets}, $filename;
145        
146      } elsif ($options->{load}) {
147        if (not -e $filename) {
148          return;
149        }
150        if ($self->{cache}->{targets} = retrieve($filename)) {
151          return 1;
152        }
153      
154      } else {
155        $self->log("Please call with options build or load", 'warning');
156      
157      }
158    }
159    
160  1;  1;
161  __END__  __END__

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.5

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed