Debian Codegraph @

script/ecaccess-file-mdelete

raw
1 #!/usr/bin/perl -w
2 #
3 # ecaccess-file-mdelete: Delete Multiple ECaccess Files at once
4 #
5 # [email protected] - 2010-10-15
6
7 use ECMWF::ECaccess;
8 use Getopt::Long;
9 use Pod::Usage;
10 use MIME::Base64;
11 use Term::Prompt;
12 use Number::Bytes::Human qw(format_bytes);
13
14 my %opt = ( force => 0, version => 0, help => 0, manual => 0, retry => 0, debug => 0 );
15
16 pod2usage( -noperldoc => 1, -exit => 1, verbose => 1 ) if !GetOptions(
17 \%opt,
18 qw(
19 force
20 version
21 help|?
22 manual
23 retry=i
24 debug
25 )
26 );
27
28 # Display version if requested
29 die ECMWF::ECaccess->VERSION . "\n" if ( $opt{version} );
30
31 pod2usage( -noperldoc => 1, -exit => 1, verbose => 1 ) if ( $opt{help} );
32 pod2usage( -noperldoc => 1, -exit => 1, verbose => 2 ) if ( $opt{manual} );
33 pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "No target-ecaccess-files specified!\n" ) if not(@ARGV);
34
35 # Create the ECaccess Controler
36 my $ecaccess = ECMWF::ECaccess->new( $opt{retry}, $opt{debug});
37
38 # Get the Token (using the Certificate in $HOME)
39 my $token = $ecaccess->getToken();
40
41 # Get the Control Channel
42 my $controlChannel = $ecaccess->getControlChannel();
43
44 # Process all source Files from the command-line
45 foreach (@ARGV) {
46 my $sourceFiles = $_;
47
48 # Get the list of Files to download
49 my $files = $controlChannel->getDirList( $token, $sourceFiles );
50
51 # Delete each File
52 foreach my $file ( $files->valueof('//getDirListResponse/return') ) {
53
54 # Set source filename
55 my $source = $file->{domain} . "/" . $file->{name};
56
57 # Do we delete this file? (don't process directories and symbolic links)
58 if ( not( substr( $file->{permissions}, 0, 1 ) eq 'd' )
59 && not( substr( $file->{permissions}, 0, 1 ) eq 'l' )
60 && $file->{size} >= '0' && ( $opt{force} || &prompt( "y", "Delete " . $source, "y/n", "y" ) ) )
61 {
62 print "Deleting " . $source . " (" . ( format_bytes( $file->{size} ) ) . ") ...\n";
63
64 # Delete the source file
65 $controlChannel->deleteFile( $token, $source, SOAP::Data->type( boolean => 'true' ) );
66 }
67 }
68 }
69
70 # Logout
71 END {
72 $ecaccess->releaseToken($token) if ($token);
73 }
74
75 __END__
76
77 =head1 NAME
78
79 ecaccess-file-mdelete - Delete Multiple ECaccess Files at once
80
81 =head1 SYNOPSIS
82
83 B<ecaccess-file-mdelete -version|-help|-manual>
84
85 B<ecaccess-file-mdelete [-debug] [-force]> I<target-ecaccess-file> B<[>I<...>B<]>
86
87 =head1 DESCRIPTION
88
89 Allow deleting Multiple ECaccess Files at once.
90
91 Each I<target-ecaccess-file> is in the form [domain:][/user-id/]path. Please read the "Shell commands -> File Management"
92 section of the "ecaccess" guide for more information on the ECaccess File System.
93
94 =head1 ARGUMENTS
95
96 =over 8
97
98 =item I<target-ecaccess-file> B<[>I<...>B<]>
99
100 The name(s) of the ECaccess File(s) to delete.
101
102 =back
103
104 =head1 OPTIONS
105
106 =over 8
107
108 =item B<-force>
109
110 Overrides the interactive mode and delete each file without prompting.
111
112 =item B<-version>
113
114 Display version number and exits.
115
116 =item B<-help>
117
118 Print a brief help message and exits.
119
120 =item B<-manual>
121
122 Prints the manual page and exits.
123
124 =item B<-retry> I<count>
125
126 Number of SSL connection retries per 5s to ECMWF. This parameter only apply to the
127 initial SSL connection initiated by the command to the ECMWF server. It does not
128 apply to all the subsequent requests made afteward as it is mainly targeting errors
129 that can happen from time to time during the SSL handshake. Default is no retry.
130
131 =item B<-debug>
132
133 Display the SOAP and SSL messages exchanged.
134
135 =back
136
137 =head1 EXAMPLES
138
139 B<ecaccess-file-mdelete -force> I<'home:/xyz/bin/*.bin'>
140
141 Delete the I<*.bin> Files in the $HOME/bin directory of the user xyz without prompting.
142
143 =head1 SEE ALSO
144
145 B<ecaccess-file-delete>, B<ecaccess-file-get>, B<ecaccess-file-mget>, B<ecaccess-file-modtime>, B<ecaccess-file-mput>,
146 B<ecaccess-file-rmdir>, B<ecaccess-file-copy>, B<ecaccess-file-dir>, B<ecaccess-file-chmod>, B<ecaccess-file-mkdir>,
147 B<ecaccess-file-move>, B<ecaccess-file-put>, B<ecaccess-file-size> and B<ecaccess>.
148
149 =cut