- Timestamp:
- 02/22/19 02:06:49 (5 years ago)
- Location:
- trunk/LATMOS-Accounts
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/bin/la-sql-log
r1311 r2218 6 6 use Getopt::Long; 7 7 use Pod::Usage; 8 use LATMOS::Accounts::Cli::Context; 9 use LATMOS::Accounts::Cli; 8 10 9 11 =head1 NAME … … 17 19 =cut 18 20 21 Getopt::Long::Configure("pass_through"); 19 22 GetOptions( 20 23 'c|config=s' => \my $config, 21 24 'b|base=s' => \my $base, 22 'o|object=s' => \my $otype,23 25 'help' => sub { pod2usage(0) }, 24 26 ) or pod2usage(); 25 26 $otype ||= 'user';27 27 28 28 =head1 OPTIONS … … 51 51 $labase->wexported(1); 52 52 53 my @logs = $ARGV[0] 54 ? $labase->getobjectlogs($otype, $ARGV[0]) 55 : $labase->getlogs(); 53 my $Env = LATMOS::Accounts::Cli->new( 54 Context => LATMOS::Accounts::Cli::Context->new( 55 base => $labase, 56 ), 57 ); 56 58 57 foreach(@logs) { 58 printf("%s (%d), %s: %s/%s (%d) %s\n", 59 $_->{logdate}, 60 $_->{irev} || -1, 61 $_->{username}, 62 $_->{otype}, 63 $_->{name}, 64 $_->{ikey}, 65 $_->{message}, 66 ); 59 if (@ARGV) { 60 $Env->run('log', @ARGV); 61 } else { 62 $Env->run('log'); 67 63 } 64 -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm
r2210 r2218 1119 1119 } 1120 1120 1121 =head2 getobjectlogs($otype, $name)1121 =head2 getobjectlogs($otype, @names) 1122 1122 1123 1123 Return logs for object type C<$otype> having C<$name>. … … 1126 1126 1127 1127 sub getobjectlogs { 1128 my ($self, $otype, $name) = @_;1128 my ($self, $otype, @names) = @_; 1129 1129 1130 1130 my $sth = $self->db->prepare(q{ … … 1133 1133 group by ikey 1134 1134 }); 1135 $sth->execute($otype, $name);1136 1135 my @ids; 1137 while (my $res = $sth->fetchrow_hashref) { 1138 push(@ids, $res->{ikey}); 1136 foreach my $name (@names) { 1137 $sth->execute($otype, $name); 1138 while (my $res = $sth->fetchrow_hashref) { 1139 push(@ids, $res->{ikey}); 1140 } 1139 1141 } 1140 1142 @ids or return; -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Cli/Base.pm
r2217 r2218 79 79 ); 80 80 } 81 if ($self->base->can('CreateAlias')) {82 $self->add_func(83 'newalias', {84 help => 'Create an alias object',85 code => sub {86 my ($self, $otype, $name, $for) = @_;87 if ($self->base->CreateAlias($otype, $name, $for)) {88 print $OUT "Alias $otype/$name Created\n";89 $self->commit;90 }91 },92 completion => sub {93 if ($_[3]) {94 return $_[0]->base->list_objects($_[2]);95 } elsif (!$_[2]) {96 return $_[0]->base->list_supported_objects;97 } else {98 return;99 }100 }101 },102 );103 $self->add_func(104 'rmalias', {105 help => 'Remove an alias object',106 code => sub {107 my ($self, $otype, $name) = @_;108 if ($self->base->RemoveAlias($otype, $name)) {109 print $OUT "Alias $otype/$name Removed\n";110 $self->commit;111 }112 },113 completion => sub {114 if (!$_[2]) {115 return $_[0]->base->list_supported_objects;116 } else {117 return $_[0]->base->search_objects($_[2], 'oalias=*');118 }119 }120 },121 );122 $self->add_func(123 'updalias', {124 help => 'Update an alias object',125 code => sub {126 my ($self, $otype, $name, $for) = @_;127 my $obj = $self->base->GetAlias($otype, $name) or do {128 print $OUT "No alias $otype/$name found";129 return;130 };131 if ($obj->set_c_fields(oalias => $for)) {132 print $OUT "Alias $otype/$name Updated\n";133 $self->commit;134 }135 },136 completion => sub {137 if ($_[3]) {138 return $_[0]->base->list_objects($_[2]);139 } elsif($_[2]) {140 return $_[0]->base->search_objects($_[2], 'oalias=*');141 } else {142 return $_[0]->base->list_supported_objects;143 }144 }145 },146 );147 }148 81 $self->add_func('quit', { help => 'quit - exit the tool', 149 82 code => sub { print "\n"; exit(0) }, }); 150 83 $self->add_func('exit', { help => "exit current mode", 151 84 code => sub { return "EXIT" }, }); 85 $self->add_func('!', { 86 code => sub { 87 my ($env, $name, @args) = @_; 88 if ($name) { 89 system('/bin/bash', '-ic', $env->Context->{_line}); 90 } else { 91 system('/bin/bash', '-i'); 92 } 93 }, 94 } ); 152 95 153 96 … … 222 165 =head2 log 223 166 224 log [[-o otype ] object ]167 log [[-o otype ] object [object [...]]] 225 168 226 169 Show global log or log for the object given in arguments … … 238 181 $otype ||= 'user'; 239 182 183 if (!@args && $env->Context->{objs}) { 184 @args = map { $_->id } @{ $env->Context->{objs} }; 185 $otype = $env->Context->{objs}[0]->type; 186 } 187 240 188 my @logs = @args 241 ? $self->base->getobjectlogs($otype, $args[0])189 ? $self->base->getobjectlogs($otype, @args) 242 190 : $self->base->getlogs(); 243 191 … … 255 203 } 256 204 }, 257 } ); 258 205 } ) if ($self->base->can('getobjectlogs')); 206 207 if ($self->base->can('CreateAlias')) { 208 $self->add_func( 209 'newalias', { 210 help => 'Create an alias object', 211 code => sub { 212 my ($self, $otype, $name, $for) = @_; 213 if ($self->base->CreateAlias($otype, $name, $for)) { 214 print $OUT "Alias $otype/$name Created\n"; 215 $self->commit; 216 } 217 }, 218 completion => sub { 219 if ($_[3]) { 220 return $_[0]->base->list_objects($_[2]); 221 } elsif (!$_[2]) { 222 return $_[0]->base->list_supported_objects; 223 } else { 224 return; 225 } 226 } 227 }, 228 ); 229 $self->add_func( 230 'rmalias', { 231 help => 'Remove an alias object', 232 code => sub { 233 my ($self, $otype, $name) = @_; 234 if ($self->base->RemoveAlias($otype, $name)) { 235 print $OUT "Alias $otype/$name Removed\n"; 236 $self->commit; 237 } 238 }, 239 completion => sub { 240 if (!$_[2]) { 241 return $_[0]->base->list_supported_objects; 242 } else { 243 return $_[0]->base->search_objects($_[2], 'oalias=*'); 244 } 245 } 246 }, 247 ); 248 $self->add_func( 249 'updalias', { 250 help => 'Update an alias object', 251 code => sub { 252 my ($self, $otype, $name, $for) = @_; 253 my $obj = $self->base->GetAlias($otype, $name) or do { 254 print $OUT "No alias $otype/$name found"; 255 return; 256 }; 257 if ($obj->set_c_fields(oalias => $for)) { 258 print $OUT "Alias $otype/$name Updated\n"; 259 $self->commit; 260 } 261 }, 262 completion => sub { 263 if ($_[3]) { 264 return $_[0]->base->list_objects($_[2]); 265 } elsif($_[2]) { 266 return $_[0]->base->search_objects($_[2], 'oalias=*'); 267 } else { 268 return $_[0]->base->list_supported_objects; 269 } 270 } 271 }, 272 ); 273 } 259 274 } 260 275 … … 298 313 return; 299 314 }; 315 $_[0]->Context->{_line} = $line; 300 316 $term->addhistory($line); 301 317 my $res = $self->run(shellwords($line)); … … 390 406 my ($self, $lastw, $name, @args) = @_; 391 407 if (!$name) { 408 $lastw ||= ''; # avoid undef warning 392 409 if ($lastw =~ m!^(\.\./*)(.*)$!) { 393 410 if ($self->Parent) { 394 return map { "$1/$_" } $self->Parent->complete($2, $name, @args); 411 my $dot = $1; 412 $dot .= '/' unless($dot =~ m!/$!); 413 return map { "$dot$_" } $self->Parent->complete($2, $name, @args); 395 414 } else { 396 415 return ();
Note: See TracChangeset
for help on using the changeset viewer.