Changeset 2397


Ignore:
Timestamp:
06/13/20 18:55:38 (4 years ago)
Author:
nanardon
Message:

Replace print by ->print()

Location:
trunk/LATMOS-Accounts/lib/LATMOS/Accounts
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli.pm

    r2394 r2397  
    4848            my $res = $labase->create_c_object($otype, $objname, %attr); 
    4949            if($res) { 
    50                 print "Changes applied\n"; 
     50                $self->print("Changes applied\n"); 
    5151                $labase->commit; 
    5252                return 1; 
     
    7676 
    7777    my $labase = $self->base; 
    78     my $OUT = $self->Context->Out; 
    7978 
    8079    $self->add_func('ls', { 
     
    9594 
    9695                my $otype = $args[0] or do { 
    97                     print $OUT "Object type missing\n"; 
     96                    $self->print("Object type missing\n"); 
    9897                    return 1; 
    9998                }; 
     
    114113                    foreach ($env->base->list_objects($otype)) { 
    115114                        my $obj = $env->base->get_object($otype, $_) or next; 
    116                         print $OUT $obj->queryformat($fmt); 
     115                        $self->print($obj->queryformat($fmt)); 
    117116                    } 
    118                     print $OUT "\n"; 
    119                 } else { 
    120                     print $OUT map { "$_\n" } $env->base->list_objects($otype); 
     117                    $self->print("\n"); 
     118                } else { 
     119                    $self->print(map { "$_\n" } $env->base->list_objects($otype)); 
    121120                } 
    122121            }, 
     
    138137                if ($_[1]) { 
    139138                    my @res = $self->base->search_objects(@args); 
    140                     print $OUT map { "$_\n" } @res; 
     139                    $self->print(map { "$_\n" } @res); 
    141140                    $self->{_lastsearch} = \@res; 
    142141                    $self->{_lastsearchtype} = $args[0]; 
    143142                } else { 
    144                     print $OUT "Object type missing\n"; 
     143                    $self->print("Object type missing\n"); 
    145144                } 
    146145            }, 
     
    151150            my ($self, $expire) = @_; 
    152151            my @users = $self->base->find_expired_users($expire); 
    153             print $OUT map { "$_\n" } @users; 
     152            $self->print(map { "$_\n" } @users); 
    154153            $self->{_lastsearchtype} = 'user'; 
    155154            $self->{_lastsearch} = \@users; 
     
    161160            my ($self, $expire) = @_; 
    162161            my @users = $self->base->find_next_expire_users($expire); 
    163             print $OUT map { "$_\n" } @users; 
     162            $self->print(map { "$_\n" } @users); 
    164163            $self->{_lastsearchtype} = 'user'; 
    165164            $self->{_lastsearch} = \@users; 
     
    183182                        @ids = @{$self->{_lastsearch}}; 
    184183                    } else { 
    185                         print $OUT "No results store from previous search\n"; 
     184                        $self->print("No results store from previous search\n"); 
    186185                        return; 
    187186                    } 
    188187                } 
    189188                if (!@ids) { 
    190                     print $OUT 'not enough arguments' . "\n"; 
     189                    $self->print('not enough arguments' . "\n"); 
    191190                    return; 
    192191                } 
    193192                foreach (@ids) { 
    194193                    my $obj = $self->base->get_object($otype, $_) or do { 
    195                         print $OUT "Cannot get $otype $_\n"; 
     194                        $self->print("Cannot get $otype $_\n"); 
    196195                        return; 
    197196                    }; 
    198197                    push(@objs, $obj); 
    199198                } 
    200                 print $OUT "Selecting $otype " . join(', ', @ids) . "\n"; 
     199                $self->print("Selecting $otype " . join(', ', @ids) . "\n"); 
    201200                LATMOS::Accounts::Cli::Object->new( 
    202201                    Parent  => $self, 
     
    228227                        if ($status ne 'NEEDINFO') { 
    229228                            if ($status eq 'CREATED') { 
    230                                 print $OUT "Object created\n"; 
     229                                $self->print("Object created\n"); 
    231230                                $self->commit; 
    232231                            } else { 
    233                                 print $OUT "Nothing done\n"; 
     232                                $self->print("Nothing done\n"); 
    234233                                $self->rollback; 
    235234                            } 
     
    309308                    grep { $_ && $_ =~ /\d+\.\d+\.\d+\.\d+/ } @args; 
    310309                if (!$ip2) { 
    311                     print $OUT "Need two ip to exchange\n"; 
     310                    $self->print("Need two ip to exchange\n"); 
    312311                    return; 
    313312                } 
    314313                if ($self->base->nethost_exchange_ip($ip1, $ip2)) { 
    315                     print $OUT "$ip1 and $ip2 get exchange\n"; 
     314                    $self->print("$ip1 and $ip2 get exchange\n"); 
    316315                    $self->commit; 
    317316                } else { 
     
    375374                foreach (@ids) { 
    376375                    my $obj = $self->base->get_object($otype, $_) or do { 
    377                         print $OUT "Cannot get $otype $_\n"; 
     376                        $self->print("Cannot get $otype $_\n"); 
    378377                        return; 
    379378                    }; 
     
    381380                } 
    382381 
    383                 print $OUT "Selecting $otype " . join(', ', @ids) . "\n"; 
     382                $self->print("Selecting $otype " . join(', ', @ids) . "\n"); 
    384383                LATMOS::Accounts::Cli::Object->new( 
    385384                    Parent  => $self, 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Base.pm

    r2396 r2397  
    4242    my $self = shift; 
    4343 
    44     my $OUT = $self->Context->Out; 
    45  
    4644=head3 help 
    4745 
     
    9088            my ($self, $cmd, @args) = @_; 
    9189            if (!$cmd) { 
    92                 print $OUT "No command given"; 
     90                $self->print("No command given\n"); 
    9391            } elsif ($cmd eq 'objects') { 
    9492                if ( $args[0] ) { 
     
    9694                    foreach(sort $labase->list_canonical_fields($args[0], 'a')) { 
    9795                        my $attr = $labase->attribute($args[0], $_); 
    98                         printf $OUT "%s   %s\n", ($attr ? ($attr->ro ? 'r ' : 'rw') : '  '), $_; 
     96                        $self->printf("%s   %s\n", ($attr ? ($attr->ro ? 'r ' : 'rw') : '  '), $_); 
    9997                    } 
    10098                } else { 
    101                     print $OUT "Supported objects type: "; 
    102                     print $OUT join(', ', $self->base->list_supported_objects); 
    103                     print $OUT "\n"; 
     99                    $self->print("Supported objects type: "); 
     100                    $self->print(join(', ', $self->base->list_supported_objects)); 
     101                    $self->print("\n"); 
    104102                } 
    105103            } else { 
    106                 print $OUT "wrong argument\n"; 
     104                $self->print("wrong argument\n"); 
    107105            } 
    108106        }, 
     
    126124            my ($self, $arg) = @_; 
    127125            if (!$arg) { 
    128                 print $OUT "Unexported objects is" . ($self->base->unexported ? 
    129                 "enable" : "disable") . "\n"; 
     126                $self->print( "Unexported objects is" .  
     127                    ($self->base->unexported ? "enable" : "disable") . "\n" 
     128                ); 
    130129            } elsif ($arg eq 'yes') { 
    131130                $self->base->unexported(1); 
    132                 print $OUT "Unexported are now show\n"; 
     131                $self->print("Unexported are now show\n"); 
    133132            } elsif ($arg eq 'no') { 
    134133                $self->base->unexported(0); 
    135                 print $OUT "Unexported are no longer show\n"; 
     134                $self->print("Unexported are no longer show\n"); 
    136135            } elsif ($arg eq 'show') { 
    137                 print $OUT "Unexported objects is" . ($self->base->unexported ? 
    138                 "enable" : "disable") . "\n"; 
     136                $self->print("Unexported objects is" . 
     137                    ($self->base->unexported ? "enable" : "disable") . "\n" 
     138                ); 
    139139            } else { 
    140                 print $OUT "wrong argument\n"; 
     140                $self->print("wrong argument\n"); 
    141141            } 
    142142        }, 
     
    150150 
    151151    $self->add_func('quit', { 
    152             code => sub { print "\n"; exit(0) }, }); 
     152            code => sub { $self->print("\n"); exit(0) }, }); 
    153153 
    154154=head3 exit 
     
    394394                    my ($self, $otype, $name, $for) = @_; 
    395395                    if ($self->base->CreateAlias($otype, $name, $for)) { 
    396                         print $OUT "Alias $otype/$name Created\n"; 
     396                        $self->print( "Alias $otype/$name Created\n" ); 
    397397                        $self->commit; 
    398398                    } 
     
    423423                    my ($self, $otype, $name) = @_; 
    424424                    if ($self->base->RemoveAlias($otype, $name)) { 
    425                         print $OUT "Alias $otype/$name Removed\n"; 
     425                        $self->print("Alias $otype/$name Removed\n"); 
    426426                        $self->commit; 
    427427                    } 
     
    450450                    my ($self, $otype, $name, $for) = @_; 
    451451                    my $obj = $self->base->GetAlias($otype, $name) or do { 
    452                         print $OUT "No alias $otype/$name found"; 
     452                        $self->print( "No alias $otype/$name found" ); 
    453453                        return; 
    454454                    }; 
    455455                    if ($obj->set_c_fields(oalias => $for)) { 
    456                         print $OUT "Alias $otype/$name Updated\n"; 
     456                        $self->print( "Alias $otype/$name Updated\n" ); 
    457457                        $self->commit; 
    458458                    } 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Context.pm

    r2391 r2397  
    6868 
    6969sub print { 
     70    my ( $self, @args ) = @_; 
     71    my $out = $self->Out; 
     72 
     73    print $out @args; 
     74} 
     75 
     76=head2 printf 
     77 
     78=cut 
     79 
     80sub printf { 
    7081    my ( $self, $str, @args ) = @_; 
    7182    my $out = $self->Out; 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Object.pm

    r2394 r2397  
    4242 
    4343    my $labase = $self->base; 
    44     my $OUT = $self->Context->Out; 
    4544 
    4645    $self->{_otype} = $self->otype; 
     
    7271                push(@{$env->{_objects}}, $o); 
    7372            } 
    74             printf $OUT "select is now %s: %s\n", $env->{_otype}, join(', ', map { 
    75                 $_->id } @{$env->{_objects}}); 
     73            $self->printf("select is now %s: %s\n", $env->{_otype}, join(', ', map { 
     74                $_->id } @{$env->{_objects}})); 
    7675        }, 
    7776        completion => sub { 
     
    9998 
    10099            if (!@newobjs) { 
    101                 print $OUT "This would remove all objects from the list...\n"; 
     100                $self->print( "This would remove all objects from the list...\n" ); 
    102101                return; 
    103102            } else { 
    104103                @{$env->{_objects}} = @newobjs; 
    105104            } 
    106             printf $OUT "select is now %s: %s\n", $env->{_otype}, join(', ', map { 
    107                 $_->id } @{$env->{_objects}}); 
     105            $self->printf( "select is now %s: %s\n", $env->{_otype}, join(', ', map { 
     106                $_->id } @{$env->{_objects}})); 
    108107        }, 
    109108        completion => sub { 
     
    126125            if ($_[1]) { 
    127126                my @res = $self->base->search_objects($self->{_otype}, @args); 
    128                 print $OUT map { "$_\n" } @res; 
     127                $self->print( map { "$_\n" } @res ); 
    129128                $self->{_lastsearch} = \@res; 
    130129                $self->{_lastsearchtype} = $self->{_otype}; 
    131130            } else { 
    132                 print $OUT "Object type missing\n"; 
     131                $self->print( "Object type missing\n" ); 
    133132            } 
    134133        }, 
     
    146145                my %ids = map { $_->id => 1 } @{$self->{_objects}}; 
    147146                my @res = grep { $ids{ $_ } } $self->base->search_objects($self->{_otype}, @args); 
    148                 print $OUT map { "$_\n" } @res; 
     147                $self->print( map { "$_\n" } @res ); 
    149148                $self->{_lastsearch} = \@res; 
    150149                $self->{_lastsearchtype} = $self->{_otype}; 
    151150            } else { 
    152                 print $OUT "Object type missing\n"; 
     151                $self->print( "Object type missing\n" ); 
    153152            } 
    154153        }, 
     
    170169            } 
    171170 
    172             printf $OUT "select is now %s: %s\n", $env->{_otype}, join(', ', map { 
    173                 $_->id } @{$env->{_objects}}); 
     171            $self->printf("select is now %s: %s\n", $env->{_otype}, join(', ', map { 
     172                $_->id } @{$env->{_objects}})); 
    174173        }, 
    175174        completion => sub { 
     
    196195            } 
    197196 
    198             printf $OUT "select is now %s: %s\n", $env->{_otype}, join(', ', map { 
    199                 $_->id } @{$env->{_objects}}); 
     197            $self->printf( "select is now %s: %s\n", $env->{_otype}, join(', ', map { 
     198                $_->id } @{$env->{_objects}})); 
    200199        }, 
    201200        completion => sub { 
     
    222221            } 
    223222 
    224             printf $OUT "select is now %s: %s\n", $env->{_otype}, join(', ', map { 
    225                 $_->id } @{$env->{_objects}}); 
     223            $self->printf( "select is now %s: %s\n", $env->{_otype}, join(', ', map { 
     224                $_->id } @{$env->{_objects}}) ); 
    226225        }, 
    227226        completion => sub { 
     
    248247            } 
    249248 
    250             printf $OUT "select is now %s: %s\n", $env->{_otype}, join(', ', map { 
    251                 $_->id } @{$env->{_objects}}); 
     249            $self->printf( "select is now %s: %s\n", $env->{_otype}, join(', ', map { 
     250                $_->id } @{$env->{_objects}}) ); 
    252251        }, 
    253252        completion => sub { 
     
    274273            if (!$attr) { 
    275274                foreach (@{$env->{_objects}}) { 
    276                     print $OUT $_->dump; 
     275                    $self->print( $_->dump ); 
    277276                } 
    278277            } else { 
    279278                foreach my $u (@{$env->{_objects}}) { 
    280                     print $OUT sort map { $u->id . ': ' .($_ || '') . "\n" } $u->get_attributes($attr); 
     279                    $self->print( sort map { $u->id . ': ' .($_ || '') . "\n" } $u->get_attributes($attr) ); 
    281280                } 
    282281            } 
     
    294293            my ($env, $fmt) = @_; 
    295294            if (!defined($fmt)) { 
    296                 print $OUT "no format given"; 
     295                $self->print( "no format given" ); 
    297296                return; 
    298297            } 
    299298            foreach (@{$env->{_objects}}) { 
    300                 print $OUT $_->queryformat($fmt) . "\n"; 
     299                $self->print( $_->queryformat($fmt) . "\n" ); 
    301300            } 
    302301        }, 
     
    307306            my ($env, $attr) = @_; 
    308307            $attr or do { 
    309                 print $OUT "Attributes must be specified"; 
     308                $self->print( "Attributes must be specified" ); 
    310309                return; 
    311310            }; 
    312311            foreach (@{$env->{_objects}}) { 
    313312                defined $_->set_c_fields($attr => undef) or do { 
    314                     print $OUT "cannot unset attributes $attr for " . $_->id . 
    315                     "\n"; 
     313                    $self->print( "cannot unset attributes $attr for " . $_->id . "\n"); 
    316314                    return; 
    317315                }; 
    318316            } 
    319317            $env->commit; 
    320             print $OUT "Changes applied\n"; 
     318            $self->print( "Changes applied\n" ); 
    321319        }, 
    322320        completion => sub { 
     
    332330            my ($env, $attr, @value) = @_; 
    333331            @value or do { 
    334                 print $OUT "attribute and value must be specified\n"; 
     332                $self->print( "attribute and value must be specified\n" ); 
    335333                return; 
    336334            }; 
     
    339337                    \@value) or do { 
    340338                    $_->base->rollback; 
    341                     printf $OUT "Cannot set $attr to %s for %s\n", join(', ', 
    342                         @value), $_->id; 
     339                    $self->printf ("Cannot set $attr to %s for %s\n", join(', ', 
     340                        @value), $_->id); 
    343341                    return; 
    344342                }; 
    345343            } 
    346344            $env->commit; 
    347             print $OUT "Done.\n"; 
     345            $self->print( "Done.\n" ); 
    348346        }, 
    349347        completion => sub { 
     
    367365            my ($env, $attr, @value) = @_; 
    368366            @value or do { 
    369                 print $OUT "attribute and value must be specified\n"; 
     367                $self->print( "attribute and value must be specified\n" ); 
    370368                return; 
    371369            }; 
     
    374372                defined $_->set_c_fields($attr => [ @attrv, @value ]) or do { 
    375373                    $_->base->rollback; 
    376                     printf $OUT "Cannot set $attr to %s for %s\n", join(', ', 
    377                         @value), $_->id; 
     374                    $self->printf( "Cannot set $attr to %s for %s\n", join(', ', 
     375                        @value), $_->id ); 
    378376                    return; 
    379377                }; 
    380378            } 
    381379            $env->commit; 
    382             print $OUT "done\n"; 
     380            $self->print( "done\n" ); 
    383381        }, 
    384382        completion => sub { 
     
    404402            my ($env, $attr, @value) = @_; 
    405403            @value or do { 
    406                 print $OUT "attribute and value must be specified\n"; 
     404                $self->print( "attribute and value must be specified\n" ); 
    407405                return; 
    408406            }; 
     
    414412                defined $_->set_c_fields($attr => @attrv ? [ @attrv ] : undef) or do { 
    415413                    $_->rollback; 
    416                     printf $OUT "Cannot set $attr to %s for %s\n", join(', ', 
    417                         @value), $_->id; 
     414                    $self->printf( "Cannot set $attr to %s for %s\n", join(', ', 
     415                        @value), $_->id ); 
    418416                    return; 
    419417                }; 
    420418            } 
    421419            $env->commit; 
    422             print $OUT "done\n"; 
     420            $self->print( "done\n" ); 
    423421        }, 
    424422        completion => sub { 
     
    460458            if ($fmt) { 
    461459                foreach (@{$env->{_objects}}) { 
    462                     print $OUT $_->queryformat($fmt); 
    463                 } 
    464                 print $OUT "\n"; 
    465             } else { 
    466                 printf $OUT "%s: %s\n", $env->{_otype}, join(', ', map { $_->id } @{$env->{_objects}}); 
     460                    $self->print( $_->queryformat($fmt) ); 
     461                } 
     462                $self->print( "\n" ); 
     463            } else { 
     464                $self->printf("%s: %s\n", $env->{_otype}, join(', ', map { $_->id } @{$env->{_objects}})); 
    467465            } 
    468466        } 
     
    479477                if ($id) { 
    480478                    $obj = grep { $_->id = $id } @{$env->{_objects}} or do { 
    481                         print $OUT "$id is not part of selected objects\n"; 
     479                        $self->print( "$id is not part of selected objects\n" ); 
    482480                        return; 
    483481                    }; 
     
    485483                    $obj = $env->{_objects}[0] 
    486484                } else { 
    487                     print $OUT "multiple objects selected but can edit only one," 
    488                     . "please specify which one\n"; 
     485                    $self->print( "multiple objects selected but can edit only one," 
     486                    . "please specify which one\n" ); 
    489487                    return; 
    490488                } 
     
    504502                        my $res = $obj->set_c_fields(%attr); 
    505503                        if ($res) { 
    506                             print $OUT "Changes applied\n"; 
     504                            $self->print( "Changes applied\n" ); 
    507505                            $env->commit; 
    508506                        } 
    509                         else { print $OUT "Error applying changes\n" } 
     507                        else { $self->print( "Error applying changes\n" ) } 
    510508                        return $res ? 1 : 0; 
    511509                    } 
     
    517515        code => sub { 
    518516            my ($env) = @_; 
    519             printf $OUT "%s: %s\ndelete selected objects ? (yes/NO)\n", 
    520             $env->{_otype}, join(', ', map { $_->id } @{$env->{_objects}}); 
     517            $self->printf("%s: %s\ndelete selected objects ? (yes/NO)\n", 
     518            $env->{_otype}, join(', ', map { $_->id } @{$env->{_objects}})); 
    521519            my $reply = <STDIN> || ''; chomp($reply); 
    522520            if ($reply eq 'yes') { 
    523521                foreach (@{$env->{_objects}}) { 
    524522                    $env->base->delete_object($env->{_otype}, $_->id) or do { 
    525                         print $OUT "Cannot delete " . $_->id . "\n"; 
     523                        $self->print( "Cannot delete " . $_->id . "\n" ); 
    526524                        return; 
    527525                    }; 
     
    530528                return "EXIT"; 
    531529            } else { 
    532                 print $OUT "cancel !\n" 
     530                $self->print( "cancel !\n" ); 
    533531            } 
    534532        }, 
     
    550548                        $attrname 
    551549                    ) or do { 
    552                         print $OUT "No attribute $attrname"; 
     550                        $self->print( "No attribute $attrname" ); 
    553551                        return; 
    554552                    }; 
     
    566564                my @objs = (grep { $_ } map { $env->base->get_object($totype, $_) } @objects); 
    567565                return if (!@objs); 
    568                 print $OUT "Selecting $totype " . join(', ', map { $_->id } @objs) . "\n"; 
     566                $self->print( "Selecting $totype " . join(', ', map { $_->id } @objs) . "\n" ); 
    569567                LATMOS::Accounts::Cli::Object->new( 
    570568                    Parent  => $self, 
     
    607605                            my $gobj = $env->base->get_object('group', $gid) or 
    608606                            do { 
    609                                 print $OUT "Cannot find group $gid\n"; 
     607                                $self->print( "Cannot find group $gid\n" ); 
    610608                                return; 
    611609                            }; 
     
    623621                            delete($gr{$_}) foreach(@groups); 
    624622                        } else { 
    625                             print $OUT 'invalid action' . "\n"; 
     623                            $self->print( 'invalid action' . "\n" ); 
    626624                            return; 
    627625                        } 
    628626                        defined $obj->set_c_fields('memberOf' => [ keys %gr ]) or do { 
    629                             print $OUT "cannot set memberOf attributes for " . 
    630                             $obj->id . "\n"; 
     627                            $self->print( "cannot set memberOf attributes for " . 
     628                            $obj->id . "\n" ); 
    631629                            return; 
    632630                        }; 
     
    753751                if (!($password || $random)) { 
    754752                    ReadMode('noecho'); 
    755                     print "Enter password: "; 
     753                    $self->print( "Enter password: " ); 
    756754                    $password = ReadLine(0); 
    757755                    ReadMode 0; 
    758                     print "\n"; 
     756                    $self->print( "\n" ); 
    759757                    chomp($password); 
    760758                } 
     
    783781                    if ($sobj->set_password($password)) { 
    784782                        $resPasswd{$obj->id} = $password; 
    785                         print "Password succefully changed\n"; 
     783                        $self->print( "Password succefully changed\n" ); 
    786784                        $env->commit; 
    787785                        return 1; 
     
    815813                    print $obj->id . "\n"; 
    816814                    foreach my $emp ($obj->EmploymentSummary) { 
    817                         printf("    %s - %s %s\n", 
     815                        $self->printf( ("    %s - %s %s\n", 
    818816                            $emp->{firstday}, 
    819817                            $emp->{lastday} || '        ', 
    820818                            $emp->{contratType} 
    821                         ); 
     819                        ) ); 
    822820                    } 
    823821                } 
     
    849847                        delete($gr{$_}) foreach(@groups); 
    850848                    } else { 
    851                         print $OUT 'invalid action' . "\n"; 
     849                        $self->print( 'invalid action' . "\n" ); 
    852850                        return; 
    853851                    } 
    854852                    defined $obj->set_c_fields('memberUID' => [ keys %gr ]) or do { 
    855                         print $OUT "cannot set memberUID attributes for " . 
    856                         $obj->id . "\n"; 
     853                        $self->print( "cannot set memberUID attributes for " . 
     854                        $obj->id . "\n" ); 
    857855                        return; 
    858856                    }; 
     
    883881                my ($env, $action) = @_; 
    884882                foreach my $obj (sort @{$env->{_objects}}) { 
    885                     print $OUT $obj->dump({ recur => 1 }); 
     883                    $self->print( $obj->dump({ recur => 1 }) ); 
    886884                } 
    887885                $env->rollback; 
Note: See TracChangeset for help on using the changeset viewer.