-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgenerate_abstracts
executable file
·181 lines (125 loc) · 3.85 KB
/
generate_abstracts
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
#!/usr/bin/perl -w
use FindBin;
use lib "$FindBin::Bin/../perl_lib";
######################################################################
#
#
######################################################################
=pod
=for Pod2Wiki
=head1 NAME
B<generate_abstracts> - Regenerate all the static abstract pages for an EPrint repository
=head1 SYNOPSIS
B<generate_abstracts> I<repository_id> [B<options>] [I<eprintid>]
=head1 DESCRIPTION
This script recreates every static abstract page for an eprints repository. To save load on the database, as archived data should not change, EPrints creates static webpages containing the summary of each eprint. If you change the way the abstracts are rendered or change the site template then you will want to run this script.
=head1 ARGUMENTS
=over 8
=item B<repository_id>
The ID of the eprint repository to use.
=item B<eprintid>
An optional integer indicating that only the abstract page for record I<eprintid> should be updated. Handy for testing new configurations.
=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 suppress all output unless an error occurs.
=item B<--verbose>
Explain in detail what is going on.
May be repeated for greater effect.
=item B<--version>
Output version information and exit.
=back
=cut
use EPrints;
use strict;
use Getopt::Long;
use Pod::Usage;
my $version = 0;
my $verbose = 0;
my $quiet = 0;
my $help = 0;
my $man = 0;
Getopt::Long::Configure("permute");
GetOptions(
'help|?' => \$help,
'man' => \$man,
'version' => \$version,
'verbose+' => \$verbose,
'silent' => \$quiet,
'quiet' => \$quiet
) || pod2usage( 2 );
EPrints::Utils::cmd_version( "generate_abstracts" ) if $version;
pod2usage( 1 ) if $help;
pod2usage( -exitstatus => 0, -verbose => 2 ) if $man;
pod2usage( 2 ) if( scalar @ARGV != 1 && scalar @ARGV != 2 );
our $noise = 1;
$noise = 0 if( $quiet );
$noise = 1+$verbose if( $verbose );
# Set STDOUT to auto flush (without needing a \n)
$|=1;
my $repoid = $ARGV[0];
my $session = new EPrints::Session( 1 , $repoid , $noise );
if( !defined $session )
{
print STDERR "Failed to load repository: $repoid\n";
exit 1;
}
if( defined $ARGV[1] )
{
my $eprint = EPrints::DataObj::EPrint->new( $session, $ARGV[1] );
if( !defined $eprint )
{
$session->get_repository->log(
"EPrint #".$ARGV[1]." not found. Can't write abstract." );
}
else
{
make_static( $session, $eprint->get_dataset, $eprint, {} );
print "Wrote abstract #$ARGV[1]\n" if( $noise > 0);
}
}
else
{
print "Writing abstracts\n" if( $noise > 0);
my $dataset = $session->dataset( "eprint" );
my $info = { count=>0 };
$dataset->map( $session , \&make_static, $info );
if( $noise > 0)
{
print "Done writing ".$info->{count}." abstracts\n";
}
}
$session->terminate();
exit;
sub make_static
{
my( $session, $dataset, $eprint, $info ) = @_;
$eprint->generate_static();
if( $noise > 1 )
{
print "Generated ".$eprint->get_value( "eprintid" )."\n";
}
$info->{count}++;
}
=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