/[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.5 - (hide annotations)
Sat Feb 22 16:53:42 2003 UTC (21 years, 4 months ago) by joko
Branch: MAIN
Changes since 1.4: +12 -1 lines
minor update: debugging

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

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