-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreview_monograph
88 lines (73 loc) · 2.76 KB
/
review_monograph
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
#!/usr/bin/env ruby
# frozen_string_literal: true
# Script operates on a monograph directory found the Fulcrum
# shared drive.
#
# Review specified monograph for Fulcrum compliance
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")
script_logger = UMPTG::Logger.create(logger_fp: STDOUT)
require_relative File.join(root_dir, "lib", "fulcrum")
# Process the script parameters.
options = OpenStruct.new
options.publisher_dir = File.join(UMPTG::Fulcrum.DEFAULT_DIR, UMPTG::Fulcrum.DEFAULT_PUBLISHER)
options.normalize = false
options.normalize_caption_class = false
options.update_css = false
option_parser = OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename(__FILE__)} [-d <publisher_dir>] [-f production|preview|staging] [-n] [-c] [-u] <monograph_id> [<monograph_id>...]"
opts.on('-c', '--normalize_caption_class', 'Normalize caption class attribute') do |normalize|
options.normalize_caption_class = true
end
opts.on('-d', '--publisher_directory [DIRECTORY]', 'Publisher site directory') do |publisher_dir|
options.publisher_dir = publisher_dir
end
opts.on('-f', '--fulcrum_host [production|preview|staging]', 'Fulcrum environment') do |fulcrum_host|
options.fulcrum_host = fulcrum_host
end
opts.on('-n', '--normalize', 'Normalize EPUB') do |normalize|
options.normalize = true
end
opts.on('-u', '--update_css', 'Update CSS') do |update_css|
options.update_css = true
end
opts.on_tail('-h', '--help', 'Print this help message') do
script_logger.info(opts)
exit 0
end
end
option_parser.parse!(ARGV)
if ARGV.count < 1
script_logger.info(option_parser.help)
return
end
# Process the command line parameters.
monograph_id_list = ARGV
require 'fileutils'
require_relative File.join(root_dir, "lib", "review")
monograph_id_list.each do |monograph_id|
script_logger.info("*" * 10 + " #{monograph_id} " + "*" * 10)
monograph_dir = UMPTG::Fulcrum::MonographDir.new(
publisher_dir: options.publisher_dir,
fulcrum_host: options.fulcrum_host,
monograph_id: monograph_id
)
if monograph_dir.monograph_dir.nil? or !Dir.exist?(monograph_dir.monograph_dir)
script_logger.error("invalid monograph directory #{monograph_dir.monograph_dir}.")
next
end
reviewer = UMPTG::Review::MonographDirReviewer.new(
monograph_dir: monograph_dir
)
reviewer.review(
normalize_epub: options.normalize,
normalize_caption_class: options.normalize_caption_class,
update_css: options.update_css,
review_resources: true
)
end