forked from USGCRP/gcis-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete-uris.pl
More file actions
executable file
·82 lines (57 loc) · 1.4 KB
/
delete-uris.pl
File metadata and controls
executable file
·82 lines (57 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env perl
=head1 NAME
delete-uris.pl -- Delete a list of uris from GCIS.
=head1 SYNOPSIS
./delete-uris.pl [OPTIONS]
=head1 OPTIONS
=over
=item B<--url>
GCIS url, e.g. http://data-stage.globalchange.gov
=item <stdin>
List of uris to delete (one per line)
Note: use "#" at start of line to denote a commment (not deleted)
=item B<--dry_run> or B<--n>
Dry run
=back
=head1 EXAMPLES
# delete a set of uris from a list
./detete-uris.pl -u http://data-stage.globalchange.gov < uri_list.txt
=cut
use Gcis::Client;
use Gcis::Exim;
use Getopt::Long qw/GetOptions/;
use Pod::Usage;
use strict;
use v5.14;
GetOptions(
'url=s' => \(my $url),
'dry_run|n' => \(my $dry_run),
'help|?' => sub { pod2usage(verbose => 2) },
) or die pos2usage(verbose => 1);
pod2usage(msg => "missing url", verbose => 1) unless $url;
{
my $a = Exim->new($url, 'update');
say " deleting uris";
say " url : $url";
say " dry run" if $dry_run;
while (<>) {
chomp;
if ($_ =~ /^# /) {
say " skipping uri : $_";
next;
}
say " uri : $_";
if (!$a->{gcis}->get($_)) {
say " - does not exist";
next;
}
if ($dry_run) {
say " - would delete";
next;
}
$a->{gcis}->delete($_) or say " ** delete error **";
say " - deleted";
}
say " done";
}
1;