/[cvs]/nfo/perl/scripts/outlook2ldap/bin/feed.pl
ViewVC logotype

Annotation of /nfo/perl/scripts/outlook2ldap/bin/feed.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Sat Jan 18 18:20:45 2003 UTC (21 years, 5 months ago) by joko
Branch: MAIN
File MIME type: text/plain
+ initial check-in

1 joko 1.1 #!/usr/bin/perl
2    
3     ## --------------------------------------------------------------------------------
4     ## $Id$
5     ## --------------------------------------------------------------------------------
6     ## $Log$
7     ## --------------------------------------------------------------------------------
8    
9    
10     package main;
11    
12     use strict;
13     use warnings;
14    
15     BEGIN {
16     use FindBin qw($Bin);
17     #require "$Bin/use_libs.pl";
18     }
19    
20    
21     use lib qw( ../libs ../etc C:\home\amo\develop\netfrag.org\nfo\perl\libs );
22     use Torus::Logger;
23     use Torus::Core;
24    
25     my $logger = Log::Dispatch::Config->instance;
26    
27     #use BizWorks::Script::Feed;
28    
29     #=pod
30     #my $context = BizWorks::RunMe->new( app => $bizWorks, process => $bizProcess, logger => $logger );
31     #my $context = BizWorks::RunMe->new();
32     my $context = BizWorks::Script::Feed->new();
33     $context->getoptions();
34     $context->{opt}->{mapping_module} = $context->{opt}->{mapping};
35     #$context->verifyoptions();
36     #$context->options2actions();
37     #$context->run();
38     #$context->suspend();
39     #$context->set( app => $bizWorks, process => $bizProcess, logger => $logger );
40     my $bizWorks;
41     $context->set(
42     app => $bizWorks,
43     process => Torus::Core->new(),
44     logger => $logger,
45     config => { mappings => { 'LdapAddress' => 'xyz' } },
46     );
47     #print Dumper($context);
48     #print Dumper($context->{process}->{bizWorks}->{backend});
49     $context->run();
50     #exit;
51     #print Dumper($context);
52     #$context->suspend();
53     #=cut
54    
55    
56     #=pod
57     #my $context = OEF::Component::Task->new( guid => 'ac65ea820a263948af8b4947f33f7719' );
58     #my $context = OEF::Component::Task->new( guid => '767ee9ab030bb4163e67ab26ab9a8894' );
59     #my $context = OEF::Component::Task->new( guid => '3a5c85995270ee8b17a8701c6f709ecf' );
60     #my $context2 = OEF::Component::Task->new( guid => $context->getGuid() );
61     #my $context2 = OEF::Component::Task->new( guid => '79d69fa4308d88181b882ef8d3433534' );
62    
63     #$context2->resume();
64     #print Dumper($context2);
65     #print Dumper($context2->{process}->{bizWorks}->{backend});
66     #$context2->{process}->{bizWorks}->{backend}->connect();
67     #$context2->run();
68     #=cut
69    
70    
71     package BizWorks::Script::Feed;
72    
73     use strict;
74     use warnings;
75    
76     use Data::Dumper;
77     use Getopt::Long;
78    
79     #use base 'OEF::Component::Task';
80     use base qw(
81     DesignPattern::Object
82     DesignPattern::Object::Logger
83     );
84    
85     sub usage {
86     my $self = shift;
87     print "\n";
88     print <<EOU;
89     usage:
90     feed.pl --source=<dbkey> --node=<node> --target=<dbkey> --action=<action> [--mapping=]
91    
92     source: dbkey links to a configuration resource representing a storage (~= database)
93     node: the name of a node on the first level below the source storage
94     target: dbkey links to a configuration resource representing a storage
95     action: <action> is issued on given dbkey as source node
96     sync FULL sync (PULL & PUSH)
97     load|save PULL or PUSH syncs
98     import|export IMPORT and EXPORT syncs
99     mapping: future use: specify name of a perl module / xml file which describes/outlines the mapping
100     EOU
101     exit;
102     }
103    
104     sub getoptions {
105     my $self = shift;
106    
107     GetOptions(
108     'source=s' => \$self->{opt}->{source},
109     'node=s' => \$self->{opt}->{node},
110     'target=s' => \$self->{opt}->{target},
111     'action=s' => \$self->{opt}->{action},
112     'mapping=s' => \$self->{opt}->{mapping},
113     'prepare' => \$self->{opt}->{prepare},
114     'fresh' => \$self->{opt}->{fresh},
115     'help' => \&usage,
116     );
117     }
118    
119     sub set {
120     my $self = shift;
121     my $data = { @_ };
122     #return bless $self, $class;
123     foreach (keys %$data) {
124     #print $_, "\n";
125     $self->{$_} = $data->{$_};
126     }
127     }
128    
129     =pod
130     sub run {
131     my $self = shift;
132     $self->{var} ||= 0;
133     print __PACKAGE__, "\n";
134     print "var: ", $self->{var}, "\n";
135     $self->{var}++;
136     }
137     =cut
138    
139     sub run {
140    
141     my $self = shift;
142    
143     #print Dumper($self->{opt});
144    
145     # TODO: move this to the synchronization (startup) somehow... (one level towards the core - just one....)
146     if ($self->{opt}->{target} eq 'testdata') {
147     #print Dumper($self->{opt});
148     $self->{logger}->info( __PACKAGE__ . "->run: Running (special handler code - no generic sync!) on '$self->{opt}->{target}' with action $self->{opt}->{action} - no NODE");
149     $self->{process}->load('Setup/Data/Test');
150     #print "2", "\n";
151     return $self->{process}->handler();
152     }
153    
154     #print Dumper($self->{opt});
155    
156     #$self->{process}->load('Setup');
157    
158     # TODO:
159     # - move this to Data::Transfer::Sync::checkOptions!!!
160     # - remove the tail of this "if" at the bottom of this block!
161     #if ($self->{app}->{config}->{databases}->{$self->{opt}->{target}}->{syncable}) {
162     my $mode = '';
163     my $erase = 0;
164     my $import = 0;
165     $mode = 'PUSH' if $self->{opt}->{action} eq 'save';
166     $mode = 'PULL' if $self->{opt}->{action} eq 'load';
167     if ($self->{opt}->{action} eq 'import') {
168     $mode = 'PULL';
169     $erase = 1;
170     $import = 1;
171     }
172     if ($self->{opt}->{action} eq 'export') {
173     $mode = 'PUSH';
174     $erase = 1;
175     #$import = 1;
176     }
177     $self->{process}->startSync({
178     source => $self->{opt}->{source},
179     source_node => $self->{opt}->{node},
180     target => $self->{opt}->{target},
181     mode => $mode,
182     erase => $erase,
183     import => $import,
184     mapping => $self->{opt}->{mapping},
185     prepare => $self->{opt}->{prepare},
186     });
187    
188     =pod
189     } else {
190     #print "\n", "Target is not syncable", "\n";
191     print "\n", "Target is not syncable", "\n";
192     $self->usage();
193     }
194     =cut
195    
196     #$self->{process}->{outlook}->disconnect();
197     return;
198    
199     if ($self->{opt}->{action} eq 'load') {
200     if ($self->{opt}->{target} eq 'resources') {
201     fillResources();
202     } elsif ($self->{opt}->{target} eq 'testdata') {
203     fillTestData();
204     } else {
205     $self->usage();
206     }
207    
208     } elsif ($self->{opt}->{action} eq 'save') {
209     if ($self->{opt}->{target} eq 'resources') {
210     $self->{process}->backupResources();
211     } elsif ($self->{opt}->{target} eq 'testdata') {
212     print "could not save $self->{opt}->{resource}, it's stored inside a perl module", "\n";
213     } else {
214     $self->usage();
215     }
216    
217     } elsif ($self->{opt}->{action} eq 'import') {
218     if (!$self->{opt}->{node}) { print "option \"--action=import\" requires option \"--node\"", "\n"; $self->usage(); }
219    
220     } else {
221     $self->usage();
222     }
223    
224     $self->{process}->{storage}->disconnect();
225    
226     }
227    
228     1;
229    
230    
231     package BizWorks::RunMe;
232    
233     use strict;
234     use warnings;
235    
236     #use base 'OEF::Component::Task';
237     use base qw(
238     DesignPattern::Object
239     DesignPattern::Object::Logger
240     );
241    
242     use Getopt::Long;
243     #use BizWorks::Boot qw( $bizWorks $bizProcess );
244     use Data::Dumper;
245     use Getopt::Long;
246     use Carp;
247    
248    
249    
250    
251     sub getoptions {
252     my $self = shift;
253    
254     $self->{'opt'}->{'source'} = 'backend';
255     $self->{'opt'}->{'target'} = 'testdata';
256     $self->{'opt'}->{'action'} = 'load';
257    
258     # TODO: use some core function/method (e.g. 'init_hash($hashref, $value, $force = 0)')
259     $self->{opt}->{source} ||= '';
260     $self->{opt}->{node} ||= '';
261     $self->{opt}->{target} ||= '';
262     $self->{opt}->{action} ||= '';
263     $self->{opt}->{mapping} ||= '';
264     $self->{opt}->{prepare} ||= '';
265     $self->{opt}->{fresh} ||= '';
266    
267     }
268    
269    
270     sub run {
271    
272     my $self = shift;
273    
274     #print Dumper($self->{opt});
275    
276     # TODO: move this to the synchroninzation (startup) somehow... (one level towards the core - just one....)
277     if ($self->{opt}->{target} eq 'testdata') {
278     #print Dumper($self->{opt});
279     $self->{logger}->info( __PACKAGE__ . "->run: Running (special handler code - no generic sync!) on '$self->{opt}->{target}' with action $self->{opt}->{action} - no NODE");
280     $self->{process}->load('Setup/Data/Test');
281     #print "2", "\n";
282     return $self->{process}->handler();
283     }
284    
285     #print Dumper($self->{opt});
286    
287     #$self->{process}->load('Setup');
288    
289     # TODO:
290     # - move this to Data::Transfer::Sync::checkOptions!!!
291     # - remove the tail of this "if" at the bottom of this block!
292     #if ($self->{app}->{config}->{databases}->{$self->{opt}->{target}}->{syncable}) {
293     my $mode = '';
294     my $erase = 0;
295     my $import = 0;
296     $mode = 'PUSH' if $self->{opt}->{action} eq 'save';
297     $mode = 'PULL' if $self->{opt}->{action} eq 'load';
298     if ($self->{opt}->{action} eq 'import') {
299     $mode = 'PULL';
300     $erase = 1;
301     $import = 1;
302     }
303     if ($self->{opt}->{action} eq 'export') {
304     $mode = 'PUSH';
305     $erase = 1;
306     #$import = 1;
307     }
308     $self->{process}->startSync({
309     source => $self->{opt}->{source},
310     source_node => $self->{opt}->{node},
311     target => $self->{opt}->{target},
312     mode => $mode,
313     erase => $erase,
314     import => $import,
315     mapping => $self->{opt}->{mapping},
316     prepare => $self->{opt}->{prepare},
317     });
318    
319     =pod
320     } else {
321     #print "\n", "Target is not syncable", "\n";
322     print "\n", "Target is not syncable", "\n";
323     $self->usage();
324     }
325     =cut
326    
327     $self->{process}->{storage}->disconnect();
328     return;
329    
330     if ($self->{opt}->{action} eq 'load') {
331     if ($self->{opt}->{target} eq 'resources') {
332     fillResources();
333     } elsif ($self->{opt}->{target} eq 'testdata') {
334     fillTestData();
335     } else {
336     $self->usage();
337     }
338    
339     } elsif ($self->{opt}->{action} eq 'save') {
340     if ($self->{opt}->{target} eq 'resources') {
341     $self->{process}->backupResources();
342     } elsif ($self->{opt}->{target} eq 'testdata') {
343     print "could not save $self->{opt}->{resource}, it's stored inside a perl module", "\n";
344     } else {
345     $self->usage();
346     }
347    
348     } elsif ($self->{opt}->{action} eq 'import') {
349     if (!$self->{opt}->{node}) { print "option \"--action=import\" requires option \"--node\"", "\n"; $self->usage(); }
350    
351     } else {
352     $self->usage();
353     }
354    
355     $self->{process}->{storage}->disconnect();
356    
357     }
358    
359    
360     1;

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