Changeset 2397
- Timestamp:
- 06/13/20 18:55:38 (4 years ago)
- Location:
- trunk/LATMOS-Accounts/lib/LATMOS/Accounts
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli.pm
r2394 r2397 48 48 my $res = $labase->create_c_object($otype, $objname, %attr); 49 49 if($res) { 50 print "Changes applied\n";50 $self->print("Changes applied\n"); 51 51 $labase->commit; 52 52 return 1; … … 76 76 77 77 my $labase = $self->base; 78 my $OUT = $self->Context->Out;79 78 80 79 $self->add_func('ls', { … … 95 94 96 95 my $otype = $args[0] or do { 97 print $OUT "Object type missing\n";96 $self->print("Object type missing\n"); 98 97 return 1; 99 98 }; … … 114 113 foreach ($env->base->list_objects($otype)) { 115 114 my $obj = $env->base->get_object($otype, $_) or next; 116 print $OUT $obj->queryformat($fmt);115 $self->print($obj->queryformat($fmt)); 117 116 } 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)); 121 120 } 122 121 }, … … 138 137 if ($_[1]) { 139 138 my @res = $self->base->search_objects(@args); 140 print $OUT map { "$_\n" } @res;139 $self->print(map { "$_\n" } @res); 141 140 $self->{_lastsearch} = \@res; 142 141 $self->{_lastsearchtype} = $args[0]; 143 142 } else { 144 print $OUT "Object type missing\n";143 $self->print("Object type missing\n"); 145 144 } 146 145 }, … … 151 150 my ($self, $expire) = @_; 152 151 my @users = $self->base->find_expired_users($expire); 153 print $OUT map { "$_\n" } @users;152 $self->print(map { "$_\n" } @users); 154 153 $self->{_lastsearchtype} = 'user'; 155 154 $self->{_lastsearch} = \@users; … … 161 160 my ($self, $expire) = @_; 162 161 my @users = $self->base->find_next_expire_users($expire); 163 print $OUT map { "$_\n" } @users;162 $self->print(map { "$_\n" } @users); 164 163 $self->{_lastsearchtype} = 'user'; 165 164 $self->{_lastsearch} = \@users; … … 183 182 @ids = @{$self->{_lastsearch}}; 184 183 } else { 185 print $OUT "No results store from previous search\n";184 $self->print("No results store from previous search\n"); 186 185 return; 187 186 } 188 187 } 189 188 if (!@ids) { 190 print $OUT 'not enough arguments' . "\n";189 $self->print('not enough arguments' . "\n"); 191 190 return; 192 191 } 193 192 foreach (@ids) { 194 193 my $obj = $self->base->get_object($otype, $_) or do { 195 print $OUT "Cannot get $otype $_\n";194 $self->print("Cannot get $otype $_\n"); 196 195 return; 197 196 }; 198 197 push(@objs, $obj); 199 198 } 200 print $OUT "Selecting $otype " . join(', ', @ids) . "\n";199 $self->print("Selecting $otype " . join(', ', @ids) . "\n"); 201 200 LATMOS::Accounts::Cli::Object->new( 202 201 Parent => $self, … … 228 227 if ($status ne 'NEEDINFO') { 229 228 if ($status eq 'CREATED') { 230 print $OUT "Object created\n";229 $self->print("Object created\n"); 231 230 $self->commit; 232 231 } else { 233 print $OUT "Nothing done\n";232 $self->print("Nothing done\n"); 234 233 $self->rollback; 235 234 } … … 309 308 grep { $_ && $_ =~ /\d+\.\d+\.\d+\.\d+/ } @args; 310 309 if (!$ip2) { 311 print $OUT "Need two ip to exchange\n";310 $self->print("Need two ip to exchange\n"); 312 311 return; 313 312 } 314 313 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"); 316 315 $self->commit; 317 316 } else { … … 375 374 foreach (@ids) { 376 375 my $obj = $self->base->get_object($otype, $_) or do { 377 print $OUT "Cannot get $otype $_\n";376 $self->print("Cannot get $otype $_\n"); 378 377 return; 379 378 }; … … 381 380 } 382 381 383 print $OUT "Selecting $otype " . join(', ', @ids) . "\n";382 $self->print("Selecting $otype " . join(', ', @ids) . "\n"); 384 383 LATMOS::Accounts::Cli::Object->new( 385 384 Parent => $self, -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Base.pm
r2396 r2397 42 42 my $self = shift; 43 43 44 my $OUT = $self->Context->Out;45 46 44 =head3 help 47 45 … … 90 88 my ($self, $cmd, @args) = @_; 91 89 if (!$cmd) { 92 print $OUT "No command given";90 $self->print("No command given\n"); 93 91 } elsif ($cmd eq 'objects') { 94 92 if ( $args[0] ) { … … 96 94 foreach(sort $labase->list_canonical_fields($args[0], 'a')) { 97 95 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') : ' '), $_); 99 97 } 100 98 } 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"); 104 102 } 105 103 } else { 106 print $OUT "wrong argument\n";104 $self->print("wrong argument\n"); 107 105 } 108 106 }, … … 126 124 my ($self, $arg) = @_; 127 125 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 ); 130 129 } elsif ($arg eq 'yes') { 131 130 $self->base->unexported(1); 132 print $OUT "Unexported are now show\n";131 $self->print("Unexported are now show\n"); 133 132 } elsif ($arg eq 'no') { 134 133 $self->base->unexported(0); 135 print $OUT "Unexported are no longer show\n";134 $self->print("Unexported are no longer show\n"); 136 135 } 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 ); 139 139 } else { 140 print $OUT "wrong argument\n";140 $self->print("wrong argument\n"); 141 141 } 142 142 }, … … 150 150 151 151 $self->add_func('quit', { 152 code => sub { print "\n"; exit(0) }, });152 code => sub { $self->print("\n"); exit(0) }, }); 153 153 154 154 =head3 exit … … 394 394 my ($self, $otype, $name, $for) = @_; 395 395 if ($self->base->CreateAlias($otype, $name, $for)) { 396 print $OUT "Alias $otype/$name Created\n";396 $self->print( "Alias $otype/$name Created\n" ); 397 397 $self->commit; 398 398 } … … 423 423 my ($self, $otype, $name) = @_; 424 424 if ($self->base->RemoveAlias($otype, $name)) { 425 print $OUT "Alias $otype/$name Removed\n";425 $self->print("Alias $otype/$name Removed\n"); 426 426 $self->commit; 427 427 } … … 450 450 my ($self, $otype, $name, $for) = @_; 451 451 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" ); 453 453 return; 454 454 }; 455 455 if ($obj->set_c_fields(oalias => $for)) { 456 print $OUT "Alias $otype/$name Updated\n";456 $self->print( "Alias $otype/$name Updated\n" ); 457 457 $self->commit; 458 458 } -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Context.pm
r2391 r2397 68 68 69 69 sub print { 70 my ( $self, @args ) = @_; 71 my $out = $self->Out; 72 73 print $out @args; 74 } 75 76 =head2 printf 77 78 =cut 79 80 sub printf { 70 81 my ( $self, $str, @args ) = @_; 71 82 my $out = $self->Out; -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Object.pm
r2394 r2397 42 42 43 43 my $labase = $self->base; 44 my $OUT = $self->Context->Out;45 44 46 45 $self->{_otype} = $self->otype; … … 72 71 push(@{$env->{_objects}}, $o); 73 72 } 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}})); 76 75 }, 77 76 completion => sub { … … 99 98 100 99 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" ); 102 101 return; 103 102 } else { 104 103 @{$env->{_objects}} = @newobjs; 105 104 } 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}})); 108 107 }, 109 108 completion => sub { … … 126 125 if ($_[1]) { 127 126 my @res = $self->base->search_objects($self->{_otype}, @args); 128 print $OUT map { "$_\n" } @res;127 $self->print( map { "$_\n" } @res ); 129 128 $self->{_lastsearch} = \@res; 130 129 $self->{_lastsearchtype} = $self->{_otype}; 131 130 } else { 132 print $OUT "Object type missing\n";131 $self->print( "Object type missing\n" ); 133 132 } 134 133 }, … … 146 145 my %ids = map { $_->id => 1 } @{$self->{_objects}}; 147 146 my @res = grep { $ids{ $_ } } $self->base->search_objects($self->{_otype}, @args); 148 print $OUT map { "$_\n" } @res;147 $self->print( map { "$_\n" } @res ); 149 148 $self->{_lastsearch} = \@res; 150 149 $self->{_lastsearchtype} = $self->{_otype}; 151 150 } else { 152 print $OUT "Object type missing\n";151 $self->print( "Object type missing\n" ); 153 152 } 154 153 }, … … 170 169 } 171 170 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}})); 174 173 }, 175 174 completion => sub { … … 196 195 } 197 196 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}})); 200 199 }, 201 200 completion => sub { … … 222 221 } 223 222 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}}) ); 226 225 }, 227 226 completion => sub { … … 248 247 } 249 248 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}}) ); 252 251 }, 253 252 completion => sub { … … 274 273 if (!$attr) { 275 274 foreach (@{$env->{_objects}}) { 276 print $OUT $_->dump;275 $self->print( $_->dump ); 277 276 } 278 277 } else { 279 278 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) ); 281 280 } 282 281 } … … 294 293 my ($env, $fmt) = @_; 295 294 if (!defined($fmt)) { 296 print $OUT "no format given";295 $self->print( "no format given" ); 297 296 return; 298 297 } 299 298 foreach (@{$env->{_objects}}) { 300 print $OUT $_->queryformat($fmt) . "\n";299 $self->print( $_->queryformat($fmt) . "\n" ); 301 300 } 302 301 }, … … 307 306 my ($env, $attr) = @_; 308 307 $attr or do { 309 print $OUT "Attributes must be specified";308 $self->print( "Attributes must be specified" ); 310 309 return; 311 310 }; 312 311 foreach (@{$env->{_objects}}) { 313 312 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"); 316 314 return; 317 315 }; 318 316 } 319 317 $env->commit; 320 print $OUT "Changes applied\n";318 $self->print( "Changes applied\n" ); 321 319 }, 322 320 completion => sub { … … 332 330 my ($env, $attr, @value) = @_; 333 331 @value or do { 334 print $OUT "attribute and value must be specified\n";332 $self->print( "attribute and value must be specified\n" ); 335 333 return; 336 334 }; … … 339 337 \@value) or do { 340 338 $_->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); 343 341 return; 344 342 }; 345 343 } 346 344 $env->commit; 347 print $OUT "Done.\n";345 $self->print( "Done.\n" ); 348 346 }, 349 347 completion => sub { … … 367 365 my ($env, $attr, @value) = @_; 368 366 @value or do { 369 print $OUT "attribute and value must be specified\n";367 $self->print( "attribute and value must be specified\n" ); 370 368 return; 371 369 }; … … 374 372 defined $_->set_c_fields($attr => [ @attrv, @value ]) or do { 375 373 $_->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 ); 378 376 return; 379 377 }; 380 378 } 381 379 $env->commit; 382 print $OUT "done\n";380 $self->print( "done\n" ); 383 381 }, 384 382 completion => sub { … … 404 402 my ($env, $attr, @value) = @_; 405 403 @value or do { 406 print $OUT "attribute and value must be specified\n";404 $self->print( "attribute and value must be specified\n" ); 407 405 return; 408 406 }; … … 414 412 defined $_->set_c_fields($attr => @attrv ? [ @attrv ] : undef) or do { 415 413 $_->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 ); 418 416 return; 419 417 }; 420 418 } 421 419 $env->commit; 422 print $OUT "done\n";420 $self->print( "done\n" ); 423 421 }, 424 422 completion => sub { … … 460 458 if ($fmt) { 461 459 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}})); 467 465 } 468 466 } … … 479 477 if ($id) { 480 478 $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" ); 482 480 return; 483 481 }; … … 485 483 $obj = $env->{_objects}[0] 486 484 } 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" ); 489 487 return; 490 488 } … … 504 502 my $res = $obj->set_c_fields(%attr); 505 503 if ($res) { 506 print $OUT "Changes applied\n";504 $self->print( "Changes applied\n" ); 507 505 $env->commit; 508 506 } 509 else { print $OUT "Error applying changes\n"}507 else { $self->print( "Error applying changes\n" ) } 510 508 return $res ? 1 : 0; 511 509 } … … 517 515 code => sub { 518 516 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}})); 521 519 my $reply = <STDIN> || ''; chomp($reply); 522 520 if ($reply eq 'yes') { 523 521 foreach (@{$env->{_objects}}) { 524 522 $env->base->delete_object($env->{_otype}, $_->id) or do { 525 print $OUT "Cannot delete " . $_->id . "\n";523 $self->print( "Cannot delete " . $_->id . "\n" ); 526 524 return; 527 525 }; … … 530 528 return "EXIT"; 531 529 } else { 532 print $OUT "cancel !\n"530 $self->print( "cancel !\n" ); 533 531 } 534 532 }, … … 550 548 $attrname 551 549 ) or do { 552 print $OUT "No attribute $attrname";550 $self->print( "No attribute $attrname" ); 553 551 return; 554 552 }; … … 566 564 my @objs = (grep { $_ } map { $env->base->get_object($totype, $_) } @objects); 567 565 return if (!@objs); 568 print $OUT "Selecting $totype " . join(', ', map { $_->id } @objs) . "\n";566 $self->print( "Selecting $totype " . join(', ', map { $_->id } @objs) . "\n" ); 569 567 LATMOS::Accounts::Cli::Object->new( 570 568 Parent => $self, … … 607 605 my $gobj = $env->base->get_object('group', $gid) or 608 606 do { 609 print $OUT "Cannot find group $gid\n";607 $self->print( "Cannot find group $gid\n" ); 610 608 return; 611 609 }; … … 623 621 delete($gr{$_}) foreach(@groups); 624 622 } else { 625 print $OUT 'invalid action' . "\n";623 $self->print( 'invalid action' . "\n" ); 626 624 return; 627 625 } 628 626 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" ); 631 629 return; 632 630 }; … … 753 751 if (!($password || $random)) { 754 752 ReadMode('noecho'); 755 print "Enter password: ";753 $self->print( "Enter password: " ); 756 754 $password = ReadLine(0); 757 755 ReadMode 0; 758 print "\n";756 $self->print( "\n" ); 759 757 chomp($password); 760 758 } … … 783 781 if ($sobj->set_password($password)) { 784 782 $resPasswd{$obj->id} = $password; 785 print "Password succefully changed\n";783 $self->print( "Password succefully changed\n" ); 786 784 $env->commit; 787 785 return 1; … … 815 813 print $obj->id . "\n"; 816 814 foreach my $emp ($obj->EmploymentSummary) { 817 printf(" %s - %s %s\n",815 $self->printf( (" %s - %s %s\n", 818 816 $emp->{firstday}, 819 817 $emp->{lastday} || ' ', 820 818 $emp->{contratType} 821 ) ;819 ) ); 822 820 } 823 821 } … … 849 847 delete($gr{$_}) foreach(@groups); 850 848 } else { 851 print $OUT 'invalid action' . "\n";849 $self->print( 'invalid action' . "\n" ); 852 850 return; 853 851 } 854 852 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" ); 857 855 return; 858 856 }; … … 883 881 my ($env, $action) = @_; 884 882 foreach my $obj (sort @{$env->{_objects}}) { 885 print $OUT $obj->dump({ recur => 1 });883 $self->print( $obj->dump({ recur => 1 }) ); 886 884 } 887 885 $env->rollback;
Note: See TracChangeset
for help on using the changeset viewer.