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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Fri Feb 14 14:18:36 2003 UTC (21 years, 4 months ago) by joko
Branch: MAIN
Changes since 1.2: +19 -2 lines
+ new get-/setter-methods

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

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