/[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.6 - (hide annotations)
Sat Jun 19 01:49:07 2004 UTC (20 years ago) by joko
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +6 -2 lines
enabled verbosing with Data::Transfer::Sync
minor patch to option processing

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

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