-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathepub_meta
70 lines (60 loc) · 1.96 KB
/
epub_meta
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
#!/usr/bin/env ruby
# frozen_string_literal: true
# Script takes a list of EPUBs and displays its
# metadata.
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)
# Process the script parameters.
options = OpenStruct.new
options.fulcrum_host = nil
option_parser = OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename(__FILE__)} [-f production|preview|staging] epub_file [epub_file...]"
opts.on('-f', '--fulcrum_host host', 'Fulcrum environment') do |fulcrum_host|
options.fulcrum_host = fulcrum_host
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
epub_file_list = ARGV
require_relative File.join(root_dir, 'lib', 'fulcrum')
# Create the serivce for retrieving the manifest.
service = UMPTG::Services::Heliotrope.new(
:fulcrum_host => options.fulcrum_host
)
# Travese the list of EPUB files to update.
epub_file_list.each do |epub_file|
epub_file = File.expand_path(epub_file)
unless File.exist?(epub_file)
script_logger.error("invalid EPUB file path #{epub_file}.")
next
end
script_logger.info("*** processing #{File.basename(epub_file)} ***")
epub = UMPTG::EPUB::Archive.new(epub_file: epub_file)
epub.metadata.each {|k,v| script_logger.info("#{k}:#{v}") }
=begin
src = epub.metadata['source']
result = service.monograph_export(identifier: src)
result.each do |id,mlist|
mlist.each do |m|
manifest = UMPTG::Fulcrum::Manifest::Document.new(
csv_body: m
)
script_logger.info("press:#{manifest.monograph_row['press']}")
end
end
=end
STDOUT.flush
end