/[cvs]/nfo/perl/libs/OEF/Script/AbstractFeeder.pm
ViewVC logotype

Annotation of /nfo/perl/libs/OEF/Script/AbstractFeeder.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations)
Thu Feb 20 21:11:15 2003 UTC (21 years, 4 months ago) by joko
Branch: MAIN
Changes since 1.3: +15 -5 lines
renamed module
modified runtime namespace hierarchy

1 joko 1.1 #!/usr/bin/perl
2    
3     ## --------------------------------------------------------------------------------
4 joko 1.4 ## $Id: AbstractFeeder.pm,v 1.3 2003/02/14 14:18:36 joko Exp $
5 joko 1.1 ## --------------------------------------------------------------------------------
6 joko 1.2 ## $Log: AbstractFeeder.pm,v $
7 joko 1.4 ## Revision 1.3 2003/02/14 14:18:36 joko
8     ## + new get-/setter-methods
9     ##
10 joko 1.3 ## Revision 1.2 2003/02/11 09:48:57 joko
11     ## - moved notice output out of this module
12     ## + some fixes
13     ##
14 joko 1.2 ## Revision 1.1 2003/02/09 16:27:06 joko
15     ## + initial commit
16     ##
17 joko 1.1 ## --------------------------------------------------------------------------------
18    
19    
20     package OEF::Script::AbstractFeeder;
21    
22     use strict;
23     use warnings;
24    
25     #use base 'OEF::Component::Task';
26     use base qw(
27     DesignPattern::Object
28 joko 1.4 DesignPattern::Logger
29 joko 1.1 );
30    
31    
32     use Data::Dumper;
33     use Getopt::Long;
34 joko 1.3 use Data::Transfer::Sync;
35 joko 1.1
36    
37     # get logger instance
38     my $logger = Log::Dispatch::Config->instance;
39    
40     sub usage {
41     my $self = shift;
42     print "\n";
43     print <<EOU;
44     usage:
45     feed.pl --source=<dbkey> --node=<node> --target=<dbkey> --action=<action> [--mapping=]
46    
47     source: dbkey links to a configuration resource representing a storage (~= database)
48     node: the name of a node on the first level below the source storage
49     target: dbkey links to a configuration resource representing a storage
50     action: <action> is issued on given dbkey as source node
51     sync FULL sync (PULL & PUSH)
52     load|save PULL or PUSH syncs
53     import|export IMPORT and EXPORT syncs
54     mapping: future use: specify name of a perl module / xml file which describes/outlines the mapping
55     EOU
56     exit;
57     }
58    
59 joko 1.3 sub readoptions {
60 joko 1.1 my $self = shift;
61    
62     GetOptions(
63     'source=s' => \$self->{opt}->{source},
64     'source-type=s' => \$self->{opt}->{'source-type'},
65     'source-node=s' => \$self->{opt}->{'source-node'},
66     'target=s' => \$self->{opt}->{target},
67     'target-node=s' => \$self->{opt}->{'target-node'},
68     'action=s' => \$self->{opt}->{action},
69     'mapping-module=s' => \$self->{opt}->{'mapping-module'},
70     'prepare' => \$self->{opt}->{prepare},
71     'fresh' => \$self->{opt}->{fresh},
72     'help' => \&usage,
73     # v1-API-spec backward compatibility
74     'node=s' => \$self->{opt}->{'node'},
75     );
76     }
77 joko 1.3
78     sub getoptions {
79     my $self = shift;
80     return $self->{opt};
81     }
82    
83     sub setoptions {
84     my $self = shift;
85     my $options = shift;
86     # FIXME: is this really true?
87     $self->{opt} = $options;
88     }
89 joko 1.1
90     sub getoptions_old {
91     my $self = shift;
92     GetOptions(
93     'source=s' => \$self->{opt}->{source},
94     'node=s' => \$self->{opt}->{node},
95     'target=s' => \$self->{opt}->{target},
96     'action=s' => \$self->{opt}->{action},
97     'mapping=s' => \$self->{opt}->{mapping},
98     'prepare' => \$self->{opt}->{prepare},
99     'fresh' => \$self->{opt}->{fresh},
100     );
101    
102     # TODO: use some core function/method (e.g. 'init_hash($hashref, $value, $force = 0)')
103     $self->{opt}->{source} ||= '';
104     $self->{opt}->{node} ||= '';
105     $self->{opt}->{target} ||= '';
106     $self->{opt}->{action} ||= '';
107     $self->{opt}->{mapping} ||= '';
108     $self->{opt}->{prepare} ||= '';
109     $self->{opt}->{fresh} ||= '';
110    
111     }
112    
113    
114     sub set {
115     my $self = shift;
116     my $data = { @_ };
117     #return bless $self, $class;
118     foreach (keys %$data) {
119     #print $_, "\n";
120     $self->{$_} = $data->{$_};
121     }
122     }
123    
124     sub run {
125     my $self = shift;
126     $self->_before_run();
127     $self->prepare();
128 joko 1.2 #$self->tellWhatIAmDoing();
129 joko 1.1 $self->sync();
130     }
131    
132     sub prepare {
133     my $self = shift;
134    
135     # TODO:
136     # - move this to Data::Transfer::Sync::checkOptions!!!
137     # - use 'syncable'???
138    
139     #if ($self->{app}->{config}->{databases}->{$self->{opt}->{target}}->{syncable}) {
140    
141     my $mode = '';
142     my $erase = 0;
143     my $import = 0;
144     $mode = 'PUSH' if $self->{opt}->{action} eq 'save';
145     $mode = 'PULL' if $self->{opt}->{action} eq 'load';
146     if ($self->{opt}->{action} eq 'import') {
147     $mode = 'PULL';
148     $erase = 1;
149     $import = 1;
150     }
151     if ($self->{opt}->{action} eq 'export') {
152     $mode = 'PUSH';
153     $erase = 1;
154     #$import = 1;
155     }
156     $self->{opt}->{mode} = $mode;
157     $self->{opt}->{erase} = $erase;
158     $self->{opt}->{import} = $import;
159    
160     }
161    
162     sub sync {
163     my $self = shift;
164    
165     # trace
166     #print Dumper($self);
167     #print Dumper($self->{opt});
168     #exit;
169    
170     # proposal to introduce full backward-compatibility mechanism
171     # "just" have many APIs with different versions accessing the very same core ...
172     # is api-version specified?
173     my $sync_version = $self->{opt}->{sv};
174     $sync_version ||= 'V1';
175    
176     # create a new synchronization object
177 joko 1.2 my $sync = Data::Transfer::Sync->new( 'sync_version' => $sync_version, __parent => $self );
178 joko 1.1
179     # trace
180     #print Dumper($self);
181 joko 1.2 #print Dumper($self);
182     #exit;
183 joko 1.4
184     # checks
185     if (!$self->{app}->{storage}->{$self->{opt}->{source}}) {
186     $logger->critical("Sync source storage handle undefined!");
187     }
188     if (!$self->{app}->{storage}->{$self->{opt}->{target}}) {
189     $logger->critical("Sync target storage handle undefined!");
190     }
191 joko 1.1
192     # configure the synchronization-object
193     $sync->configure(
194     source => {
195     storage => {
196     #handle => $mapiStorage,
197 joko 1.4 handle => $self->{app}->{storage}->{$self->{opt}->{source}},
198 joko 1.2 #isIdentAuthority => $self->{app}->{config}->{{$self->{opt}->{source}},
199     #isChecksumAuthority => 1,
200     #writeProtected => 1,
201 joko 1.1 },
202     },
203     target => {
204     storage => {
205     #handle => $ldapStorage,
206 joko 1.4 handle => $self->{app}->{storage}->{$self->{opt}->{target}},
207 joko 1.2 #idAuthority => 1,
208     #isChecksumAuthority => 1,
209     #isWriteProtected => 0,
210 joko 1.1 },
211     },
212     verbose => 1,
213     );
214 joko 1.2
215     # TODO:
216     =pod
217     $sync->configure(
218     'source.storage.handle' => ...,
219     'target.storage.handle' => ...,
220     );
221     =cut
222 joko 1.1
223     # trace
224     #print Dumper($sync);
225     #exit;
226    
227     # read, mungle & check the options
228     $sync->setArguments($self->{opt});
229     $sync->readArguments();
230    
231     # trace
232     #print Dumper($sync);
233    
234     # finally, run the sync ...
235     $sync->syncNodes();
236    
237     }
238    
239    
240     1;

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