forked from eprints/eprints
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_views
executable file
·262 lines (172 loc) · 6.29 KB
/
generate_views
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
251
252
253
254
255
256
257
258
259
260
261
#!/usr/bin/perl -w
use FindBin;
use lib "$FindBin::Bin/../perl_lib";
######################################################################
#
#
######################################################################
=pod
=for Pod2Wiki
=head1 NAME
B<generate_views> - Generate static browse pages for an EPrint repository
=head1 SYNOPSIS
B<generate_views> I<repository_id> [B<options>]
=head1 DESCRIPTION
This script creates some or all of the pages used in the /view/ section of the website. Since 3.1 these pages update themselves if they are older than a certain age, but this can cause delays for the viewer, so this script is still provided to pre-prepare them to provide a smoother experience.
Note: Since EPrints 3.1 it is not essential to run generate_views periodically, but it is still recommended.
For each view configured in $c->{browse_views}, (see: ~/archives/ARCHIVEID/cfg/cfg.d/views.pl) a static web page is created for each value of that field, and index pages to navigate to them.
For example, if we make "year" view then this script will generate one page for each unique value of the year field. A user can then view the 1995 page and see links to all the 1995 eprints.
Advantages of this are that this puts less load on the database than user searches, assuming you pick two or three sensible fields to make views with.
On large repositories some views may take considerable time to generate. These views could be regenerated daily or weekly. Appropriate values for B<max_menu_age> and B<max_list_age> should be defined for the view in this case.
The more eprints the longer it will take to run. The rough length of time to run this is of the order of O( B<languages> * B<eprints> * B<browsable fields> ). You can automate running this with the B<cron> system.
If the 'view' option is set, only that view is updated (the option can be repeated). This can be useful if some views need updating more often then others. The top /view/ page which links to each view is always updated.
=head1 ARGUMENTS
=over 8
=item B<repository_id>
The ID of the eprint repository to use.
=back
=head1 OPTIONS
=over 8
=item B<--generate menus>
Only generate the menu pages, not the pages with links to records.
=item B<--generate lists>
Only generate the pages with lists of records, not the menu pages.
=item B<--view> I<view_id>
Generate only the view with this ID.
May be repeated B<--view> I<viewid_1> B<--view> I<viewid_2>
=item B<--lang> I<lang_id>
Generate only pages for the language with this ID.
=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 File::Copy;
use strict;
use Getopt::Long;
use Pod::Usage;
my $version = 0;
my $verbose = 0;
my $quiet = 0;
my $help = 0;
my $man = 0;
my $generate_opt;
my @view_opts;
my $lang_opt;
Getopt::Long::Configure("permute");
GetOptions(
'help|?' => \$help,
'man' => \$man,
'version' => \$version,
'verbose+' => \$verbose,
'silent' => \$quiet,
'quiet' => \$quiet,
'generate=s' => \$generate_opt,
'view=s' => \@view_opts,
'lang=s' => \$lang_opt,
) || pod2usage( 2 );
EPrints::Utils::cmd_version( "generate_views" ) if $version;
pod2usage( 1 ) if $help;
pod2usage( -exitstatus => 0, -verbose => 2 ) if $man;
pod2usage( 2 ) if( scalar @ARGV != 1 );
my $noise = 1;
$noise = 0 if( $quiet );
$noise = 1+$verbose if( $verbose );
my $do_menus = 1;
my $do_lists = 1;
if( defined $generate_opt )
{
if( $generate_opt eq "menus" ) { $do_lists = 0; }
elsif( $generate_opt eq "lists" ) { $do_menus = 0; }
else
{
print STDERR "--generate must be either menus or lists.\n";
exit 1;
}
}
my $PATH = "view";
# Set STDOUT to auto flush (without needing a \n)
$|=1;
binmode( STDOUT, ":utf8" );
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;
}
$session->cache_subjects;
my $repository = $session->get_repository;
my $views = $repository->get_conf( "browse_views" );
my $ds = $repository->get_dataset( "archive" );
if( @view_opts )
{
foreach my $view_opt (@view_opts){
my $ok = 0;
foreach my $view ( @{$views} )
{
$ok = 1 if( $view->{id} eq $view_opt );
}
if( !$ok )
{
EPrints::abort( "Unknown view: $view_opt" );
}
}
}
LANGUAGE: foreach my $langid ( @{$repository->get_conf( "languages" )} )
{
next LANGUAGE if( defined $lang_opt && $langid ne $lang_opt );
$session->change_lang( $langid );
my @files = ();
my $dir = $repository->get_conf( "htdocs_path" )."/".$langid."/view";
VIEW: foreach my $view ( @{$views} )
{
next VIEW if( @view_opts && !grep( /$view->{id}/, @view_opts ) );
$view = EPrints::Update::Views->new(
repository => $session,
view => $view
);
$view->update_view_by_path(
on_write => sub { print "Wrote: $_[0]\n" if $noise > 1 },
langid => $langid,
do_menus => $do_menus,
do_lists => $do_lists );
}
if( $do_menus )
{
my $target = join "/", $session->config( "htdocs_path" ), $langid, "view", "index";
# make views index page
EPrints::Update::Views::update_browse_view_list( $session, $target, $langid );
print "Wrote: $target\n" if( $noise > 1 );
}
# TODO: remove any pages we didn't create.0l
print "done\n" if( $noise > 1 );
}
$session->terminate();
exit;
=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