1b5ac580a1fc07b2f7de49d8e108b9533ac9a806
[software/sisu] / lib / sisu / develop / hub.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** hub
8
9 ** Author: Ralph Amissah
10 <ralph@amissah.com>
11 <ralph.amissah@gmail.com>
12
13 ** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
14 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah,
15 All Rights Reserved.
16
17 ** License: GPL 3 or later:
18
19 SiSU, a framework for document structuring, publishing and search
20
21 Copyright (C) Ralph Amissah
22
23 This program is free software: you can redistribute it and/or modify it
24 under the terms of the GNU General Public License as published by the Free
25 Software Foundation, either version 3 of the License, or (at your option)
26 any later version.
27
28 This program is distributed in the hope that it will be useful, but WITHOUT
29 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
30 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
31 more details.
32
33 You should have received a copy of the GNU General Public License along with
34 this program. If not, see <http://www.gnu.org/licenses/>.
35
36 If you have Internet connection, the latest version of the GPL should be
37 available at these locations:
38 <http://www.fsf.org/licensing/licenses/gpl.html>
39 <http://www.gnu.org/licenses/gpl.html>
40
41 <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html>
42
43 ** SiSU uses:
44 * Standard SiSU markup syntax,
45 * Standard SiSU meta-markup syntax, and the
46 * Standard SiSU object citation numbering and system
47
48 ** Hompages:
49 <http://www.jus.uio.no/sisu>
50 <http://www.sisudoc.org>
51
52 ** Git
53 <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary>
54 <http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/develop/hub.rb;hb=HEAD>
55
56 =end
57 module SiSU
58 require_relative 'constants' # constants.rb
59 require_relative 'se' # se.rb
60 include SiSU_Env
61 include SiSU_Screen
62 require_relative 'hub_actions' # hub_actions.rb
63 require_relative 'hub_loop_markup_files' # hub_loop_markup_files.rb
64 require_relative 'hub_options' # hub_options.rb
65 require_relative 'dp' # dp.rb
66 include SiSU_Param
67 require_relative 'utils' # utils.rb
68 begin
69 require 'uri'
70 rescue LoadError
71 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
72 error('uri NOT FOUND (LoadError)')
73 end
74 class HubMaster
75 def initialize(argv,call_path)
76 begin
77 opt=SiSU_Commandline::Options.new(argv,call_path)
78 SiSU::Processing.new(opt).actions_without_files
79 SiSU::Processing.new(opt).actions_on_files
80 SiSU::Processing.new(opt).actions_without_files_post
81 rescue
82 selection=(opt ? opt.selections.src : '')
83 SiSU_Screen::Ansi.new(selection,$!,$@).rescue do
84 __LINE__.to_s + ':' + __FILE__
85 end
86 ensure
87 Dir.chdir(call_path)
88 end
89 end
90 end
91 class Processing
92 begin
93 require 'fileutils'
94 include FileUtils
95 rescue LoadError
96 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
97 error('fileutils NOT FOUND (LoadError)')
98 end
99 @@env=nil
100 attr_accessor :op
101 def initialize(opt)
102 @opt=opt
103 @@env=@env=SiSU_Env::InfoEnv.new
104 @msg,@msgs='',nil
105 @tell=lambda {
106 SiSU_Screen::Ansi.new(
107 @opt.selections.str,
108 @msg,
109 "#{@msgs.inspect if @msgs}"
110 )
111 }
112 end
113 def remove_skipped_files_if_any_from_processing_files_array
114 if @remove_faulty_markup_files_array.length > 0
115 @opt.files = (@opt.files - @remove_faulty_markup_files_array)
116 end
117 end
118 def print_error_message_if_files_skipped
119 if @remove_faulty_markup_files_array.length > 0
120 puts '---'
121 STDERR.puts 'ERROR with file(s), did not process: ' +
122 @remove_faulty_markup_files_array.join(',')
123 end
124 end
125 def do_each_file_loop_check_and_perform_selected_actions(opt)
126 actions=SiSU_Hub_Actions::HubActions.new(opt)
127 actions.outputs.each_file.abstract_objects?
128 actions.outputs.each_file.qrcode?
129 actions.outputs.each_file.hash_digests?
130 actions.outputs.each_file.text?
131 actions.outputs.each_file.html?
132 actions.outputs.each_file.xhtml?
133 actions.outputs.each_file.xml?
134 actions.outputs.each_file.pdf?
135 actions.outputs.each_file.man_or_info?
136 actions.outputs.each_file.po4a_make?
137 actions.outputs.each_file.sqlite_discrete?
138 actions.outputs.each_file.manifest?
139 end
140 def do_each_file_loop_options
141 if @opt.files.length > 0
142 @opt.files.each_with_index do |fno,i|
143 @opt.fno=fno
144 @opt.fns=fno.
145 gsub(/(?:https?|file):\/\/\S+\/(\S+)\.sst$/,'\1.-sst').
146 gsub(/\.ssm$/,'.ssm.sst')
147 @opt.f_pth=@opt.f_pths[i]
148 if @opt.fns !~/\.-sst$/
149 @opt.pth=@opt.f_pths[i][:pth]
150 @opt.lng=@opt.f_pths[i][:lng]
151 else
152 @opt.pth=Dir.pwd
153 @opt.lng='en'
154 end
155 unless @opt.pth.nil?
156 @@pwd=@opt.pth
157 Dir.chdir(@opt.pth) #watch
158 end
159 #@env=SiSU_Env::InfoEnv.new(@opt.fns)
160 do_each_file_loop_check_and_perform_selected_actions(@opt)
161 end
162 else
163 do_each_file_loop_check_and_perform_selected_actions(@opt)
164 end
165 end
166 def do_loop_files_on_given_option_pre
167 begin
168 if @opt.act[:zap][:set]==:on #% --zap, -Z
169 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).loop_files_on_given_option do
170 require_relative 'zap'
171 SiSU_Zap::Source.new(@opt).read # -Z zap.rb
172 end
173 end
174 ensure
175 end
176 end
177 def do_loop_files_on_given_option_post
178 actions=SiSU_Hub_Actions::HubActions.new(@opt)
179 if defined? actions.outputs.loop_files.share_source?
180 actions.outputs.loop_files.share_source?
181 end
182 if defined? actions.outputs.loop_files.run_termsheet?
183 actions.outputs.loop_files.run_termsheet?
184 end
185 if defined? actions.outputs.loop_files.po4a_setup?
186 actions.outputs.loop_files.po4a_setup?
187 end
188 if defined? actions.outputs.loop_files.sql?
189 actions.outputs.loop_files.sql?
190 end
191 SiSU_Hub_Actions::Operations.new.counter
192 if defined? actions.outputs.loop_files.manifest?
193 actions.outputs.loop_files.manifest?
194 end
195 if defined? actions.outputs.loop_files.sitemaps?
196 actions.outputs.loop_files.sitemaps?
197 end
198 if defined? actions.outputs.loop_files.urls?
199 actions.outputs.loop_files.urls?
200 end
201 end
202 def actions_without_files
203 actions=SiSU_Hub_Actions::HubActions.new(@opt)
204 actions.report.version_info?
205 actions.report.version_dir?
206 actions.prepare.site?
207 actions.prepare.sql?
208 end
209 def actions_without_files_post
210 actions=SiSU_Hub_Actions::HubActions.new(@opt)
211 actions.prepare.remote_site?
212 actions.prepare.search_form?
213 actions.prepare.webrick?
214 end
215 def actions_on_files
216 if @opt.act[:profile][:set]==:on
217 begin
218 require 'profile'
219 rescue LoadError
220 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
221 error('profile NOT FOUND (LoadError)')
222 end
223 end
224 actions=SiSU_Hub_Actions::HubActions.new(@opt)
225 actions.outputs.each_file.harvest?
226 actions.outputs.init?
227 do_loop_files_on_given_option_pre
228 do_each_file_loop_options
229 #remove_skipped_files_if_any_from_processing_files_array # NEEDS WORK
230 do_loop_files_on_given_option_post
231 #print_error_message_if_files_skipped
232 if (@opt.act[:verbose][:set]==:on \
233 || @opt.act[:verbose_plus][:set]==:on \
234 || @opt.act[:maintenance][:set]==:on)
235 @msg,@msgs="\tsisu -W [to start ruby web-server on output directory]\n",nil
236 end
237 if (@opt.act[:verbose][:set]==:on \
238 || @opt.act[:verbose_plus][:set]==:on \
239 || @opt.act[:maintenance][:set]==:on \
240 || @opt.act[:urls_selected][:set]==:on \
241 || @opt.act[:urls_all][:set]==:on)
242 @tell.call.print_brown unless @opt.files.join.empty?
243 end
244 if defined? @@env.processing_path.processing \
245 and @@env.user \
246 and FileTest.directory?(@@env.processing_path.processing) \
247 and @@env.processing_path.processing =~/#{@@env.user}$/
248 #clean tmp processing dir of content as is located in public area
249 if @@env.processing_path.processing_base_tmp =~/^\/tmp\/\S+/
250 FileUtils::cd(@@env.processing_path.processing_base_tmp) do
251 FileUtils::rm_rf('.') unless @opt.act[:maintenance][:set] ==:on
252 end
253 end
254 end
255 end
256 end
257 class HubClose
258 def initialize(call_path,argv)
259 begin
260 env=SiSU_Env::InfoEnv.new
261 rescue
262 ensure
263 if FileTest.directory?(env.processing_path.processing) \
264 and FileTest.directory?(env.processing_path.processing_base_tmp) \
265 and env.processing_path.processing_base_tmp =~/#{env.processing_path.processing}/ \
266 and env.processing_path.processing_base_tmp =~/^\/tmp\/\S+/ \
267 and not argv.inspect =~/"--maintenance"|"-M"/
268 FileUtils::cd(env.processing_path.processing_base_tmp) do
269 FileUtils::rm_rf('.')
270 end
271 end
272 Dir.chdir(call_path)
273 end
274 end
275 end
276 end
277 __END__