forked from eprints/eprints
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoolbox
executable file
·251 lines (169 loc) · 5.2 KB
/
toolbox
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#!/usr/bin/perl -w
use FindBin;
use lib "$FindBin::Bin/../perl_lib";
######################################################################
#
#
######################################################################
=pod
=head1 NAME
B<toolbox> - EPrints Toolbox
=head1 SYNOPSIS
B<toolbox> I<repository_id> [B<options>] getEprint --eprint B<eprintid>
B<toolbox> I<repository_id> [B<options>] getEprintField --eprint B<eprintid> --field B<fieldname>
B<toolbox> I<repository_id> [B<options>] createEprint < B<data>
B<toolbox> I<repository_id> [B<options>] modifyEprint --eprint B<eprintid> < B<data>
B<toolbox> I<repository_id> [B<options>] removeEprint --eprint B<eprintid>
B<toolbox> I<repository_id> [B<options>] addDocument --eprint B<eprintid> < B<data>
B<toolbox> I<repository_id> [B<options>] modifyDocument --document B<documentid> < B<data>
B<toolbox> I<repository_id> [B<options>] removeDocument --document B<documentid>
B<toolbox> I<repository_id> [B<options>] getFile --document B<documentid> --filename B<filename>
B<toolbox> I<repository_id> [B<options>] addFile --document B<documentid> --filename B<filename> < B<data>
B<toolbox> I<repository_id> [B<options>] removeFile --document B<documentid> --filename B<filename>
B<toolbox> I<repository_id> [B<options>] idSearchEprints < B<data>
B<toolbox> I<repository_id> [B<options>] xmlSearchEprints < B<data>
=head1 DESCRIPTION
This command provides some remote access to read and write to the EPrints repository. Be careful, there are no safety checks!
=head1 ARGUMENTS
=over 8
=item I<repository_id>
The ID of the EPrint repository to use.
=back
=head1 OPTIONS
=over 8
=item B<--help>
Print a brief help message and exit.
=item B<--man>
Print the full manual page and then exit.
=item B<--quiet>
Be vewwy vewwy quiet. This option will supress all output unless an error occurs.
=item B<--verbose>
Explain in detail what is going on.
May be repeated for greater effect.
Shows why a plugin is disabled.
=item B<--version>
Output version information and exit.
=back
=cut
use Getopt::Long;
use Pod::Usage;
use strict;
use EPrints;
use EPrints::Toolbox;
my $version = 0;
my $verbose = 0;
my $quiet = 0;
my $help = 0;
my $man = 0;
my $eprintid = undef;
my $docid = undef;
my $filename = undef;
my $field = undef;
my $cuserid = undef;
my $format = undef;
Getopt::Long::Configure("permute");
GetOptions(
'help|?' => \$help,
'man' => \$man,
'version' => \$version,
'verbose+' => \$verbose,
'silent' => \$quiet,
'quiet' => \$quiet,
'eprint=i' => \$eprintid,
'document=i' => \$docid,
'filename=s' => \$filename,
'field=s' => \$field,
'cuser=s' => \$cuserid,
'format=s' => \$format,
) || pod2usage( 2 );
EPrints::Utils::cmd_version( "export_xml" ) if $version;
pod2usage( 1 ) if $help;
pod2usage( -exitstatus => 0, -verbose => 2 ) if $man;
pod2usage( 2 ) if( scalar @ARGV < 2 );
my $noise = 1;
$noise = 0 if( $quiet );
$noise = 1+$verbose if( $verbose );
# Set STDOUT to auto flush (without needing a \n)
$|=1;
my $repoid = shift @ARGV;
my $cmd = shift @ARGV;
my $session = new EPrints::Session( 1, $repoid, $noise );
if( !defined $session )
{
print STDERR "Failed to load repository: $repoid\n";
exit 1;
}
$session->get_repository->{config}->{enable_web_imports} = 1;
$session->get_repository->{config}->{enable_file_imports} = 1;
my %opts = ();
if( defined $cuserid )
{
$session->{current_user} = EPrints::DataObj::User->new( $session, $cuserid );
if( !$session->{current_user} )
{
toolbox_fail( "Could not find user $cuserid" );
}
}
$opts{format} = $format;
$opts{filename} = $filename;
$opts{field} = $field;
if( defined $eprintid )
{
$opts{eprint} = EPrints::DataObj::EPrint->new( $session, $eprintid );
if( !defined $opts{eprint} )
{
toolbox_fail( "Could not find eprint $eprintid" );
}
}
if( defined $docid )
{
$opts{document} = EPrints::DataObj::Document->new( $session, $docid );
if( !defined $opts{document} )
{
toolbox_fail( "Could not find document $docid" );
}
}
$opts{session} = $session;
my $fn_name = "EPrints::Toolbox::tool_".$cmd;
my( $rc, $output ) = eval "$fn_name( \%opts )";
if( $@ )
{
toolbox_fail( "Command '$cmd' failed.", [$@] );
}
if( $rc )
{
toolbox_fail( "Command Failed", $output );
}
print $output;
$session->terminate();
exit;
sub toolbox_fail
{
my( $msg, $problems ) = @_;
print STDERR "ERROR: $msg\n";
if( defined $problems )
{
foreach my $problem ( @{$problems} )
{
print STDERR "* $problem\n";
}
}
exit 1;
}
=head1 COPYRIGHT
=for COPYRIGHT BEGIN
Copyright 2000-2011 University of Southampton.
=for COPYRIGHT END
=for LICENSE BEGIN
This file is part of EPrints L<http://www.eprints.org/>.
EPrints is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
EPrints is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU General Public License
along with EPrints. If not, see L<http://www.gnu.org/licenses/>.
=for LICENSE END