Changeset 73
- Timestamp:
- 05/08/09 01:48:26 (15 years ago)
- Location:
- LATMOS-Accounts
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
LATMOS-Accounts/bin/la-sync
r66 r73 16 16 Show configured bases: 17 17 18 la-sync [ options]18 la-sync [sync name] [options] 19 19 20 20 =cut … … 48 48 my $LA = LATMOS::Accounts->new($config); 49 49 50 my $sync = $LA->create_synchro($from, [ @to ]); 51 $sync->load_dest and return; 52 $sync->process( 50 my $sync = $LA->create_synchro( 51 $ARGV[0], 52 from => $from, 53 to => (@to ? [ @to ] : undef), 53 54 nocreate => $nocreate, 54 55 test => $test, 55 ) or warn "Sync has failed\n"; 56 ) or die "cannot create sync object\n"; 57 $sync->load_dest and return; 58 $sync->process() or warn "Sync has failed\n"; -
LATMOS-Accounts/lib/LATMOS/Accounts.pm
r56 r73 17 17 18 18 my $self = Config::IniFiles->new( 19 -file => $config 19 -file => $config, 20 '-default' => '_default_', 20 21 ); 21 22 … … 62 63 my ($self) = @_; 63 64 grep { 64 !m/^_.*_$/ 65 !m/^_.*_$/ && 66 !m/^sync:/ 65 67 } $self->Sections 66 68 } … … 77 79 } 78 80 79 sub config_sync_base { 80 my ($self, $from) = @_; 81 return split(/ /, $self->val($from, 'push', '')); 82 } 81 sub sync_from_name { 82 my ($self, $syncname) = @_; 83 return if (!$syncname); 84 $self->val("sync:$syncname", 'from', $self->default_base_name); 85 } 83 86 84 87 sub create_synchro { 85 my ($self, $ from, $to, %options) = @_;88 my ($self, $name, %options) = @_; 86 89 87 my $labfrom = $from ? $self->base($from) : $self->default_base; 90 # taking options from config 91 if ($name) { 92 foreach my $param ($self->Parameters("sync:$name")) { 93 warn "$param $options{$param}"; 94 if (!defined($options{$param})) { 95 my @args = $self->val("sync:$name", $param); 96 warn join(', ', $param, @args); 97 $options{$param} = ($args[1] || $param eq 'to') 98 ? [ @args ] 99 : $args[0]; 100 } 101 } 102 } 88 103 89 my @labto = map { $self->base($_) } 90 @{ $to || []} 91 ? @{ $to } 92 : ($self->config_sync_base($from 93 ? $from 94 : $self->default_base_name)); 104 my $labfrom = $options{from} ? $self->base($options{from}) : $self->default_base; 105 106 my @labto = map { $self->base($_) } @{ $options{to} || []} or return; 95 107 96 108 my $sync = LATMOS::Accounts::Synchro->new( 97 109 $labfrom, [ @labto ], 98 110 state_file => $self->val('_default_', 'state_file'), 111 %options, 99 112 ); 100 113 } 101 114 102 115 sub sync_access { 103 my ($self, $bases) = @_; 104 my @obases = scalar(@{ $bases || []}) 105 ? map { $self->base($_) } @{ $bases || []} 106 : ( 107 $self->default_base, 108 map { $self->base($_) } 109 $self->config_sync_base($self->default_base_name)); 116 my ($self, $name, %options) = @_; 117 118 my @obases = $name 119 ? (map { $self->base($_) } ($self->sync_from_name($name), $self->val("sync:$name", 'to'))) 120 : map { $self->base($_) } @{ $options{bases} || []}; 110 121 LATMOS::Accounts::SynchAccess->new([ @obases ]); 111 122 } -
LATMOS-Accounts/lib/LATMOS/Accounts/Synchro.pm
r68 r73 58 58 59 59 $self->{from} = $from; 60 $self->{options} = { %options }; 60 61 61 62 # allow ref and array ref of, eg … … 128 129 my %fields = map { $_ => $sobj->get_c_field($_, 'r') } @common_fields; 129 130 my $dobj = $destbase->get_object($otype, $uid); 130 $dobj->set_c_fields(%fields) unless($ options{test});131 $dobj->set_c_fields(%fields) unless($self->{options}{test}); 131 132 warn " $otype $uid: synched\n"; 132 } elsif (!$ options{nocreate}) {133 } elsif (!$self->{options}{nocreate} && !$options{nocreate}) { 133 134 my %fields = map { $_ => $sobj->get_c_field($_, 'r') } @common_fields; 134 $destbase->create_c_object($otype, $uid, %fields) unless($ options{test});135 $destbase->create_c_object($otype, $uid, %fields) unless($self->{options}{test}); 135 136 warn " $otype $uid: created\n"; 136 137 } … … 141 142 142 143 sub process { 143 my ($self , %options) = @_;144 my ($self) = @_; 144 145 145 146 $self->from->load or return; … … 170 171 grep { $fields{$_} == 2 } keys %fields; 171 172 }, 172 %options173 173 ); 174 174 $self->_traverse( … … 190 190 grep { $fields{$_} == 2 } keys %fields; 191 191 }, 192 %options,nocreate => 1,193 ) unless($ options{nocreate} || $options{test});192 nocreate => 1, 193 ) unless($self->{options}{nocreate} || $self->{options}{test}); 194 194 195 195 foreach ($self->to) { … … 198 198 } 199 199 200 $self->RewriteConfig if($self->GetFileName && !($options{nocreate} || $options{test})); 200 $self->RewriteConfig 201 if($self->GetFileName && !($self->{options}{nocreate} || $self->{options}{test})); 201 202 202 203 1;
Note: See TracChangeset
for help on using the changeset viewer.