Changeset 73


Ignore:
Timestamp:
05/08/09 01:48:26 (15 years ago)
Author:
nanardon
Message:
  • synchronisation has now their own sections
Location:
LATMOS-Accounts
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • LATMOS-Accounts/bin/la-sync

    r66 r73  
    1616Show configured bases: 
    1717 
    18     la-sync [options] 
     18    la-sync [sync name] [options] 
    1919 
    2020=cut 
     
    4848my $LA = LATMOS::Accounts->new($config); 
    4949 
    50 my $sync = $LA->create_synchro($from, [ @to ]); 
    51 $sync->load_dest and return; 
    52 $sync->process( 
     50my $sync = $LA->create_synchro( 
     51    $ARGV[0], 
     52    from => $from, 
     53    to => (@to ? [ @to ] : undef), 
    5354    nocreate => $nocreate, 
    5455    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  
    1717 
    1818    my $self = Config::IniFiles->new( 
    19         -file => $config 
     19        -file => $config, 
     20        '-default' => '_default_', 
    2021    ); 
    2122 
     
    6263    my ($self) = @_; 
    6364    grep { 
    64         !m/^_.*_$/ 
     65        !m/^_.*_$/ && 
     66        !m/^sync:/ 
    6567    } $self->Sections 
    6668} 
     
    7779} 
    7880 
    79 sub config_sync_base { 
    80     my ($self, $from) = @_; 
    81     return split(/ /, $self->val($from, 'push', '')); 
    82 }  
     81sub sync_from_name { 
     82    my ($self, $syncname) = @_; 
     83    return if (!$syncname); 
     84    $self->val("sync:$syncname", 'from', $self->default_base_name); 
     85} 
    8386 
    8487sub create_synchro { 
    85     my ($self, $from, $to, %options) = @_; 
     88    my ($self, $name, %options) = @_; 
    8689 
    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    } 
    88103 
    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; 
    95107 
    96108    my $sync = LATMOS::Accounts::Synchro->new( 
    97109        $labfrom, [ @labto ], 
    98110        state_file => $self->val('_default_', 'state_file'), 
     111        %options, 
    99112    ); 
    100113} 
    101114 
    102115sub 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} || []}; 
    110121    LATMOS::Accounts::SynchAccess->new([ @obases ]); 
    111122} 
  • LATMOS-Accounts/lib/LATMOS/Accounts/Synchro.pm

    r68 r73  
    5858     
    5959    $self->{from} = $from; 
     60    $self->{options} = { %options }; 
    6061 
    6162    # allow ref and array ref of, eg 
     
    128129                    my %fields = map { $_ => $sobj->get_c_field($_, 'r') } @common_fields; 
    129130                    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}); 
    131132                    warn "  $otype $uid: synched\n"; 
    132                 } elsif (!$options{nocreate}) { 
     133                } elsif (!$self->{options}{nocreate} && !$options{nocreate}) { 
    133134                    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}); 
    135136                    warn "  $otype $uid: created\n"; 
    136137                } 
     
    141142 
    142143sub process { 
    143     my ($self, %options) = @_; 
     144    my ($self) = @_; 
    144145 
    145146    $self->from->load or return; 
     
    170171            grep { $fields{$_} == 2 } keys %fields; 
    171172        }, 
    172         %options 
    173173    ); 
    174174    $self->_traverse( 
     
    190190            grep { $fields{$_} == 2 } keys %fields; 
    191191        }, 
    192         %options, nocreate => 1, 
    193     ) unless($options{nocreate} || $options{test}); 
     192        nocreate => 1, 
     193    ) unless($self->{options}{nocreate} || $self->{options}{test}); 
    194194 
    195195    foreach ($self->to) { 
     
    198198    } 
    199199 
    200     $self->RewriteConfig if($self->GetFileName && !($options{nocreate} || $options{test})); 
     200    $self->RewriteConfig 
     201        if($self->GetFileName && !($self->{options}{nocreate} || $self->{options}{test})); 
    201202     
    202203    1; 
Note: See TracChangeset for help on using the changeset viewer.