print-scorm 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/print-scorm +50 -0
  3. data/lib/print-scorm.rb +156 -0
  4. metadata +85 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a227289c6807c1704f5e32f07045cbfc284023164d4e01c51eb9c6867b5c802b
4
+ data.tar.gz: 8a0541c4a75fc58ffb2df6259f9967358eb79fb199b0072de504d791befde566
5
+ SHA512:
6
+ metadata.gz: cf4a0fb7e3ceb285445e1ef3a53ed633f3e10d072bd61b6dfde44159ffcfa966966d752ccc584e29cbdb512b3c180d4c1f6e2d26a1ba660523a051cad5c05dd6
7
+ data.tar.gz: 571ebb506f44d135e01bb016dc7970efc6f53bf750a4e1af3f7f7cc77f21cee7ddb4890bce05b75d1076472bc66f97d5f1a357468c2a2ea8e3f89209b0659c9c
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require_relative "../lib/print-scorm"
4
+
5
+ output = nil
6
+ input = nil
7
+ skip_existing = false
8
+
9
+ Selenium::WebDriver::Firefox.path = "/usr/bin/firefox-beta"
10
+ OptionParser.new do |opts|
11
+ opts.banner = "Exports SCROM packages to PDF"
12
+
13
+ opts.on("-ffirefox", "--firefox=firefox", "Path to firefox binary executable") do |firefox|
14
+ unless FileTest.file?(firefox)
15
+ warn "The specified Firefox path is not a file: #{firefox}"
16
+ exit -1
17
+ end
18
+
19
+ Selenium::WebDriver::Firefox.path = firefox
20
+ end
21
+
22
+ opts.on("-oOUTPUT", "--output=OUTPUT", "Path to output PDF file") do |out|
23
+ output = out
24
+ end
25
+
26
+ opts.on("-iINPUT", "--input=INPUT", "Path to input ZIP file") do |inp|
27
+ input = inp
28
+ end
29
+
30
+ opts.on("-F", "--force", "Does not skip existing files") do |f|
31
+ skip_existing = true
32
+ end
33
+
34
+ opts.on("-h", "--help", "Prints this help") do
35
+ puts opts
36
+ exit
37
+ end
38
+ end.parse!(ARGV)
39
+
40
+ if !output || !output.end_with?(".pdf")
41
+ warn "The output file must be a PDF file: #{output}"
42
+ exit -1
43
+ end
44
+
45
+ if !input || !input.end_with?(".zip")
46
+ warn "The input file must be a valid ZIP file: #{input}"
47
+ exit -1
48
+ end
49
+
50
+ ExportSCROM.new(skip_existing).run(input, output)
@@ -0,0 +1,156 @@
1
+ require "optparse"
2
+ require "watir"
3
+ require "watir-scroll"
4
+
5
+ class ExportSCROM
6
+ MAX_SLEEPTIME = 1.1
7
+ MAX_TIMEOUT = 60
8
+ ACCORDION_ID = "ui-accordion-infoHolder-header-"
9
+
10
+ @@browser = nil
11
+
12
+ def initialize(skip_existing=true)
13
+ super()
14
+ @skip_existing = skip_existing
15
+ end
16
+
17
+ def browser
18
+ return @@browser
19
+ end
20
+
21
+ def run(zipfile, target_name)
22
+ @@browser = Watir::Browser.new :firefox unless @@browser
23
+ zipfile = File.join(Dir.pwd, zipfile) unless zipfile.start_with? "/"
24
+ directory = File.dirname(zipfile)
25
+
26
+ if @skip_existing && FileTest.exists?(target_name)
27
+ puts "Skipping the already existing `#{target_name}`"
28
+ return nil
29
+ end
30
+
31
+ tempdir = File.join(directory, "__tmp")
32
+ p tempdir
33
+ `rm -r "#{tempdir}"` if FileTest.exist? tempdir
34
+ `mkdir -p "#{tempdir}"`
35
+ `unzip "#{zipfile}" -d "#{tempdir}"`
36
+
37
+ b = @@browser
38
+ b.window.resize_to 1200, 900
39
+ b.goto "file://"+tempdir+"/scorm2004RLO.htm"
40
+ b.alert.ok #Ok to the alert
41
+
42
+ if b.html.include? "This project does not contain any pages."
43
+ return nil
44
+ end
45
+
46
+ begin
47
+ b.button(title: "Full Screen").click
48
+ rescue
49
+ puts "No fullscreen button!!"
50
+ end
51
+
52
+ sleep 1
53
+ all_screenshots = []
54
+ page_index = 0
55
+ screenshot(tempdir, page_index, b, all_screenshots)
56
+
57
+ while b.button(id: "x_nextBtn").enabled?
58
+ b.button(id: "x_nextBtn").click #fullscreen
59
+ sleep MAX_SLEEPTIME
60
+
61
+ # Wait for bullets to load
62
+ start_time = Time.now
63
+ while !all_bullets_loaded(b) && (Time.now - start_time < MAX_TIMEOUT)
64
+ sleep 1
65
+ end
66
+
67
+ page_index += 1
68
+ last_screenshot = screenshot(tempdir, page_index, b, all_screenshots)
69
+ skip_click = false
70
+ while b.button(id: "nextBtn").exists? && b.button(id: "nextBtn").enabled?
71
+ unless skip_click
72
+ b.button(id: "nextBtn").click #fullscreen
73
+ else
74
+ skip_click = false
75
+ end
76
+ sleep MAX_SLEEPTIME
77
+
78
+ page_index += 1
79
+ new_screenshot = screenshot(tempdir, page_index, b, all_screenshots)
80
+
81
+ if new_screenshot[:hash] == last_screenshot[:hash]
82
+ puts "Loop detected. Avoiding..."
83
+ page_index -= 1
84
+ all_screenshots.pop
85
+ break
86
+ else
87
+ last_screenshot = new_screenshot
88
+ end
89
+ end
90
+
91
+ accordion_id = 1
92
+ accordion_button = b.h3(id: ACCORDION_ID + accordion_id.to_s)
93
+ while accordion_button.exists?
94
+ accordion_button.click
95
+ sleep MAX_SLEEPTIME
96
+
97
+ page_index += 1
98
+ new_screenshot = screenshot(tempdir, page_index, b, all_screenshots)
99
+
100
+ accordion_id += 1
101
+ accordion_button = b.h3(id: ACCORDION_ID + accordion_id.to_s)
102
+ end
103
+
104
+ oldScroll = @@browser.execute_script("return document.getElementById('x_pageHolder').scrollTop")
105
+ i = 1
106
+ loop do
107
+ b.execute_script "document.getElementById('x_pageHolder').scrollTo(0, document.getElementById('x_pageHolder').clientHeight*#{i})"
108
+
109
+ newScroll = @@browser.execute_script("return document.getElementById('x_pageHolder').scrollTop")
110
+
111
+ break if oldScroll == newScroll
112
+
113
+ sleep 0.5
114
+ page_index += 1
115
+ screenshot(tempdir, page_index, b, all_screenshots)
116
+
117
+ oldScroll = newScroll
118
+ i += 1
119
+ end
120
+
121
+ go_ahead_buttons = b.buttons(class: "ui-button-text-only")
122
+ if go_ahead_buttons.size > 0
123
+ if b.html.include? "<h2 aria-live=\"assertive\">Sommario</h2>"
124
+ go_ahead_buttons[0].click
125
+ skip_click = true
126
+ end
127
+ end
128
+ end
129
+
130
+ `convert #{all_screenshots.join(" ")} "#{target_name}"`
131
+ `rm -r "#{tempdir}"`
132
+ end
133
+
134
+ def all_bullets_loaded(b)
135
+ all_loaded = true
136
+ b.ps(class: "bullet").map do |bullet|
137
+ all_loaded = all_loaded && bullet.visible?
138
+ end
139
+
140
+ b.lis(class: "bullet").map do |bullet|
141
+ all_loaded = all_loaded && bullet.visible?
142
+ end
143
+ return all_loaded
144
+ end
145
+
146
+ def screenshot(tempdir, page_index, b, all_screenshots)
147
+ fname = File.join(tempdir, "page#{page_index}.png")
148
+ b.screenshot.save(fname)
149
+ all_screenshots.push "\"#{fname}\""
150
+
151
+ return {
152
+ name: fname,
153
+ hash: `md5sum "#{fname}"`.split(" ")[0]
154
+ }
155
+ end
156
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: print-scorm
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Simone Scalabrino
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: watir
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 6.16.5
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 6.16.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 6.16.5
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 6.16.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: watir-scroll
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.4.0
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.4.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 0.4.0
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.4.0
53
+ description: Exports SCORM packages to PDF
54
+ email: s.scalabrino9@gmail.com
55
+ executables:
56
+ - print-scorm
57
+ extensions: []
58
+ extra_rdoc_files: []
59
+ files:
60
+ - bin/print-scorm
61
+ - lib/print-scorm.rb
62
+ homepage: https://github.com/intersimone999/print-scorm
63
+ licenses:
64
+ - GPL-3.0
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubygems_version: 3.1.2
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Exports SCORM packages to PDF
85
+ test_files: []