Changeset 333


Ignore:
Timestamp:
08/13/09 16:22:02 (15 years ago)
Author:
nanardon
Message:
  • use a more parsable format, factorize work
Location:
LATMOS-Accounts
Files:
2 edited

Legend:

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

    r313 r333  
    2121    'b|base=s'   => \my $base, 
    2222    'o|object=s' => \my $otype, 
     23    'e|empty'    => \my $empty_attr, 
     24    'o|ro'       => \my $with_ro, 
    2325    'help'       => sub { pod2usage(0) }, 
    2426) or pod2usage(); 
     
    4244Query should be performed on this objects. Default is to user 'User' object. 
    4345 
     46=item e|empty 
     47 
     48Include also unset attributes 
     49 
     50=item o|ro 
     51 
     52Include also read-only attributes as comment  
     53 
    4454=back 
    4555 
     
    5464        die "Object $otype $ouid not found\n"; 
    5565    }; 
    56     foreach ($labase->list_canonical_fields($otype, 'r')) { 
    57         my $val = $obj->get_c_field($_); 
    58         printf( 
    59             "  %s: %s\n", 
    60             $_, 
    61             ref $val ? join(', ', @$val) : ($val || 'N/A') 
    62         ); 
    63     }  
     66    $obj->text_dump(*STDOUT, 
     67        { 
     68            empty_attr => $empty_attr, 
     69            only_rw => !$with_ro, 
     70        } 
     71    ); 
    6472} else { 
    6573    foreach (sort $labase->list_objects($otype)) { 
  • LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Objects.pm

    r331 r333  
    375375} 
    376376 
     377sub text_dump { 
     378    my ($self, $handle, $options, $base) = @_; 
     379 
     380    my $otype = $self->type; 
     381    $base ||= $self->base; 
     382 
     383    foreach my $attr (sort { $a cmp $b } $base->list_canonical_fields($otype, 
     384        $options->{only_rw} ? 'rw' : 'r')) { 
     385        if (ref $self) { 
     386            my $wok = $self->get_field_name($attr, 'w'); 
     387            my $val = $self->get_c_field($attr); 
     388            if ($val || $options->{empty_attr}) { 
     389            my @vals = ref $val ? @{ $val } : $val; 
     390                foreach (@vals) { 
     391                    printf($handle "%s%s: %s\n",  
     392                        $wok ? '' : '# (ro) ', 
     393                        $attr, $_ || ''); 
     394                } 
     395            } 
     396        } 
     397    } 
     398} 
     399 
    3774001; 
    378401 
Note: See TracChangeset for help on using the changeset viewer.