IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 30, 2010, 9:31:50 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20100621/Nebulous/bin/neb-ls

    r24346 r28794  
    11#!/usr/bin/env perl
    22
    3 # Copyright (C) 2007-2009  Joshua Hoblitt
     3# Copyright (C) 2007-2009  Joshua Hoblitt, 2010 Chris Waters
    44
    55use strict;
     
    1616my (
    1717    $server,
    18     $long,
    19 #    $recursive,
     18    $path,
     19    $ls,
     20    $column,
    2021);
    2122
    2223$server = $ENV{'NEB_SERVER'} unless $server;
    2324
    24 # make --long the default
    25 $long = 1;
    2625
    2726GetOptions(
    2827    'server|s=s'    => \$server,
    29 #    'recursive|r'   => \$recursive,
    30     'l|1'           => \$long,
     28    'path|p'        => \$path,
     29    'l'             => \$ls,
     30    'column|c'      => \$column,
    3131) || pod2usage( 2 );
     32
     33# twiddle column so that it does it by default.
     34
     35$column = not $column;
    3236
    3337my $pattern = shift;
     
    4751$pattern ||= "/";
    4852
    49 #if ($recursive) {
    50 #    $pattern = "^" . $pattern . ".*";
    51 #} else {
    52 #    $pattern = "^" . $pattern . "\$";
    53 #}
     53my $keys = $neb->find_objects_wildcard($pattern);
    5454
    55 my $keys = $neb->find_objects($pattern);
    56 
     55if ($path) {
     56    my @files;
     57    foreach my $key (@{ $keys }) {
     58        my $uris = $neb->find_instances($key);
     59        if (defined $uris) {
     60            push @files, URI->new(@$uris[0])->file;
     61        }
     62    }
     63    @{ $keys } = @files;
     64}
     65if ($ls) {
     66    my @files;
     67    foreach my $key (@{ $keys }) {
     68        my $uris = `ls -al $key`;
     69        chomp($uris);
     70        if (defined $uris) {
     71            push @files, $uris;
     72        }
     73    }
     74    @{ $keys } = @files;
     75}   
    5776if ($keys) {
    58     if ($long) {
    59         print join("\n", @{ $keys }), "\n";
    60     } else {
    61         print join(" ", @{ $keys }), "\n";
     77    if ($column) {
     78        open(COLUMN,"|column") || die "Cannot open column command.";
     79        print COLUMN join("\n", @{ $keys }), "\n";
     80        close(COLUMN);
     81    }
     82    else {
     83        print join("\n", @{ $keys }), "\n";
    6284    }
    6385}
     86
    6487
    6588__END__
     
    7396=head1 SYNOPSIS
    7497
    75     neb-ls [--server <URL>] [-l|-1] [--recursive] <pattern>
     98    neb-ls [--server <URL>] [-c] [-p] <pattern>
    7699
    77100=head1 DESCRIPTION
    78101
    79102This program list Nebulous keys matched by C<<pattern>>.  Call it with no
    80 arguments is equivalanet to searching with the pattern C<.*>.  Where
    81 C<<pattern>> is a POSIX 1003.2 compatable regular repression.
     103arguments is equivalent to searching with the pattern C<neb://>.  SQL like
     104wildcards are supported to select out certain files.
    82105
    83106=head1 OPTIONS
     
    85108=over 4
    86109
    87 =item * -l|-1
     110=item * --path|-p
    88111
    89 Use a long listing format.
     112Find the disk files corresponding to the keys found.
     113
     114=item * --column|-c
     115
     116Disable column formatting, and output results one to a line.
    90117
    91118Optional
    92119
    93 =cut
    94 #=item * --recursive|-r
    95 #
    96 #By default C<neb-ls> will only try to match the exact string provided to it.
    97 #With this option set all keys which match C<<pattern>> as a REGEX or substring
    98 #will be returned.
    99 #
    100 #Optional
    101 #
    102120=item * --server|-s <URL>
    103121
     
    122140=back
    123141
    124 =head1 CREDITS
    125 
    126 Just me, myself, and I.
    127 
    128142=head1 SUPPORT
    129143
     
    132146=head1 AUTHOR
    133147
    134 Joshua Hoblitt <jhoblitt@cpan.org>
     148Joshua Hoblitt <jhoblitt@cpan.org>, Chris Waters
    135149
    136150=head1 COPYRIGHT
    137151
    138 Copyright (C) 2007-2009  Joshua Hoblitt.  All rights reserved.
     152Copyright (C) 2007-2010  Joshua Hoblitt / Chris Waters.  All rights reserved.
    139153
    140154This program is free software; you can redistribute it and/or modify it under
Note: See TracChangeset for help on using the changeset viewer.