-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepubcheck_list
67 lines (56 loc) · 2.07 KB
/
epubcheck_list
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
#!/usr/bin/env ruby
# frozen_string_literal: true
# Script takes a list of EPUBs, determines the list of
# CSS stylesheets and outputs info about each, and
# possibly replaces stylesheets
require 'optparse'
require 'ostruct'
require 'os'
# Determine the root directory of the code base.
script_dir = File.expand_path(File.dirname(__FILE__))
root_dir = File.dirname(script_dir)
require_relative File.join(root_dir, "lib", "logger")
require_relative File.join(root_dir, 'lib', 'epubcheck')
script_logger = UMPTG::Logger.create(logger_fp: STDOUT)
# Process the script parameters.
options = OpenStruct.new
options.version = UMPTG::EPUBCheck.versions_default
option_parser = OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename(__FILE__)} [-v #{UMPTG::EPUBCheck.versions_str}] <epub_file|epub_dir> [<epub_file|epub_dir>..]"
opts.on('-v', "--version #{UMPTG::EPUBCheck.versions_str}", "Versions available") do |ver|
options.version = ver.downcase
end
opts.on_tail('-h', '--help', 'Print this help message') do
script_logger.info(option_parser.help)
exit 0
end
end
option_parser.parse!(ARGV)
if ARGV.count < 1
script_logger.info(option_parser.help)
exit 0
end
epub_file_list = ARGV
unless UMPTG::EPUBCheck.versions.include?(options.version)
script_logger.error("invalid version #{options.version}")
script_logger.info(option_parser.help)
exit(1)
end
epub_file_list.each do |epub_file|
epub_file = File.expand_path(epub_file)
unless File.file?(epub_file)
script_logger.error("invalid EPUB file path #{epub_file}.")
next
end
script_logger.info("*** processing #{File.basename(epub_file)} ***")
STDOUT.flush
log_file = File.join(File.dirname(epub_file), File.basename(epub_file, ".*") + "_epubcheck.xml")
#log_file = File.join(File.dirname(epub_file), \
# File.basename(epub_file, ".*") +"_epubcheck_v" + options.version.gsub(/\./, '_') + ".xml")
UMPTG::EPUBCheck.check_file(
epub_file: epub_file,
logfile: log_file,
version: options.version
)
script_logger.info("Log saved in file #{File.basename(log_file)}")
end