1#!/usr/local/bin/perl -w 2 3use strict; 4 5use XMLTV::Version '$Id: tv_validate_grabber.in,v 1.5 2015/07/12 00:46:37 knowledgejunkie Exp $'; 6use XMLTV::ValidateFile qw/LoadDtd/; 7use XMLTV::ValidateGrabber qw/ValidateGrabber ConfigureGrabber/; 8 9use File::Temp qw/tmpnam/; 10use Getopt::Long; 11 12=pod 13 14=head1 NAME 15 16tv_validate_grabber - Validate that an xmltv grabber works correctly 17 18=head1 SYNOPSIS 19 20tv_validate_grabber --help 21 22tv_validate_grabber [--config-file <configfile>] [--keep-files] <cmd> 23 24=head1 DESCRIPTION 25 26tv_validate_grabber runs a grabber through a series of test to determine 27if it follows the recommendations described at 28L<http://wiki.xmltv.org/index.php/XmltvCapabilities> 29 30tv_validate_grabber does not assume that the grabber is written in perl. 31The command does not have to be a single executable, it can also be a complete 32command-line: 33 34tv_validate_grabber "perl -I lib grab/new/tv_grab_new" 35 36=head1 OPTIONS 37 38B<--config-file <configfile>> Use the specified file as configuration file 39for the grabber. If the file does not exist, 40the grabber is run with --configure to 41create it. Default is to always run the grabber 42with --configure first and store the configuration 43in a temporary file. 44 45B<--keep-files> Do not delete the output-files generated during 46the validation. 47 48 49=head1 AUTHOR 50 51Mattias Holmlund, mattias -at- holmlund -dot- se. 52 53=cut 54 55my $opt = { "dtd-file" => undef, 56 "config-file" => undef, 57 "keep-files" => 0, 58 help => 0, 59 }; 60 61my $res = GetOptions( $opt, qw/ 62 dtd-file=s 63 config-file=s 64 keep-files 65 help|h 66 / ); 67 68if( (not $res) or $opt->{help} or scalar( @ARGV ) != 1 ) { 69 print << "EOHELP"; 70Usage: $0 [options] <grabbercommand> 71 72EOHELP 73 74 exit 1; 75} 76 77my( $cmd ) = @ARGV; 78 79my $opdir = tmpnam(); 80mkdir $opdir; 81 82my $cfg; 83if (defined( $opt->{'config-file'} )) { 84 $cfg = $opt->{'config-file'}; 85} 86else { 87 $cfg = "$opdir/conf"; 88} 89 90if( not -e $cfg ) { 91 ConfigureGrabber( $cmd, $cfg ); 92} 93 94if( defined( $opt->{'dtd-file'}) ) { 95 if (not LoadDtd( $opt->{'dtd-file'} )) { 96 print STDERR "Failed to load dtd from $opt->{'dtd-file'}.\n" . 97 "Use the --dtd-file option to specify another path to the dtd.\n"; 98 exit 1; 99 } 100} 101 102my $errors = ValidateGrabber( "Grabber", $cmd, $cfg, "$opdir/t_", undef, 0 ); 103 104if ($opt->{'keep-files'}) { 105 print "Saving output files in $opdir\n"; 106} 107else { 108 unlink <$opdir/t_*>; 109 unlink "$opdir/conf"; 110 rmdir $opdir; 111} 112 113if ($errors) { 114 print "$errors errors found.\n"; 115 exit 1; 116} 117else { 118 print "Validated ok.\n"; 119 exit 0; 120} 121 122=head1 COPYRIGHT 123 124Copyright (C) 2005 Mattias Holmlund. 125 126This program is free software; you can redistribute it and/or 127modify it under the terms of the GNU General Public License 128as published by the Free Software Foundation; either version 2 129of the License, or (at your option) any later version. 130 131This program is distributed in the hope that it will be useful, 132but WITHOUT ANY WARRANTY; without even the implied warranty of 133MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 134GNU General Public License for more details. 135 136You should have received a copy of the GNU General Public License 137along with this program; if not, write to the Free Software 138Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 139 140=cut 141 142### Setup indentation in Emacs 143## Local Variables: 144## perl-indent-level: 4 145## perl-continued-statement-offset: 4 146## perl-continued-brace-offset: 0 147## perl-brace-offset: -4 148## perl-brace-imaginary-offset: 0 149## perl-label-offset: -2 150## cperl-indent-level: 4 151## cperl-brace-offset: 0 152## cperl-continued-brace-offset: 0 153## cperl-label-offset: -2 154## cperl-extra-newline-before-brace: t 155## cperl-merge-trailing-else: nil 156## cperl-continued-statement-offset: 2 157## indent-tabs-mode: t 158## End: 159