6b0832ebbf83082b90948e4e34143affe4405310
[software/sisu] / lib / sisu / current / 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/current/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.sqlite_discrete?
137 actions.outputs.each_file.manifest?
138 end
139 def do_each_file_loop_options
140 if @opt.files.length > 0
141 @opt.files.each_with_index do |fno,i|
142 @opt.fno=fno
143 @opt.fns=fno.
144 gsub(/(?:https?|file):\/\/\S+\/(\S+)\.sst$/,'\1.-sst').
145 gsub(/\.ssm$/,'.ssm.sst')
146 @opt.f_pth=@opt.f_pths[i]
147 if @opt.fns !~/\.-sst$/
148 @opt.pth=@opt.f_pths[i][:pth]
149 @opt.lng=@opt.f_pths[i][:lng]
150 else
151 @opt.pth=Dir.pwd
152 @opt.lng='en'
153 end
154 unless @opt.pth.nil?
155 @@pwd=@opt.pth
156 Dir.chdir(@opt.pth) #watch
157 end
158 #@env=SiSU_Env::InfoEnv.new(@opt.fns)
159 do_each_file_loop_check_and_perform_selected_actions(@opt)
160 end
161 else
162 do_each_file_loop_check_and_perform_selected_actions(@opt)
163 end
164 end
165 def do_loop_files_on_given_option_pre
166 begin
167 if @opt.act[:zap][:set]==:on #% --zap, -Z
168 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).loop_files_on_given_option do
169 require_relative 'zap'
170 SiSU_Zap::Source.new(@opt).read # -Z zap.rb
171 end
172 end
173 ensure
174 end
175 end
176 def do_loop_files_on_given_option_post
177 actions=SiSU_Hub_Actions::HubActions.new(@opt)
178 if defined? actions.outputs.loop_files.share_source?
179 actions.outputs.loop_files.share_source?
180 end
181 if defined? actions.outputs.loop_files.run_termsheet?
182 actions.outputs.loop_files.run_termsheet?
183 end
184 if defined? actions.outputs.loop_files.sql?
185 actions.outputs.loop_files.sql?
186 end
187 SiSU_Hub_Actions::Operations.new.counter
188 if defined? actions.outputs.loop_files.manifest?
189 actions.outputs.loop_files.manifest?
190 end
191 if defined? actions.outputs.loop_files.sitemaps?
192 actions.outputs.loop_files.sitemaps?
193 end
194 if defined? actions.outputs.loop_files.urls?
195 actions.outputs.loop_files.urls?
196 end
197 end
198 def actions_without_files
199 actions=SiSU_Hub_Actions::HubActions.new(@opt)
200 actions.report.version_info?
201 actions.report.version_dir?
202 actions.prepare.site?
203 actions.prepare.sql?
204 end
205 def actions_without_files_post
206 actions=SiSU_Hub_Actions::HubActions.new(@opt)
207 actions.prepare.remote_site?
208 actions.prepare.search_form?
209 actions.prepare.webrick?
210 end
211 def actions_on_files
212 if @opt.act[:profile][:set]==:on
213 begin
214 require 'profile'
215 rescue LoadError
216 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
217 error('profile NOT FOUND (LoadError)')
218 end
219 end
220 actions=SiSU_Hub_Actions::HubActions.new(@opt)
221 actions.outputs.each_file.harvest?
222 actions.outputs.init?
223 do_loop_files_on_given_option_pre
224 do_each_file_loop_options
225 #remove_skipped_files_if_any_from_processing_files_array # NEEDS WORK
226 do_loop_files_on_given_option_post
227 #print_error_message_if_files_skipped
228 if (@opt.act[:verbose][:set]==:on \
229 || @opt.act[:verbose_plus][:set]==:on \
230 || @opt.act[:maintenance][:set]==:on)
231 @msg,@msgs="\tsisu -W [to start ruby web-server on output directory]\n",nil
232 end
233 if (@opt.act[:verbose][:set]==:on \
234 || @opt.act[:verbose_plus][:set]==:on \
235 || @opt.act[:maintenance][:set]==:on \
236 || @opt.act[:urls_selected][:set]==:on \
237 || @opt.act[:urls_all][:set]==:on)
238 @tell.call.print_brown unless @opt.files.join.empty?
239 end
240 if defined? @@env.processing_path.processing \
241 and @@env.user \
242 and FileTest.directory?(@@env.processing_path.processing) \
243 and @@env.processing_path.processing =~/#{@@env.user}$/
244 #clean tmp processing dir of content as is located in public area
245 if @@env.processing_path.processing_base_tmp =~/^\/tmp\/\S+/
246 FileUtils::cd(@@env.processing_path.processing_base_tmp) do
247 FileUtils::rm_rf('.') unless @opt.act[:maintenance][:set] ==:on
248 end
249 end
250 end
251 end
252 end
253 class HubClose
254 def initialize(call_path,argv)
255 begin
256 env=SiSU_Env::InfoEnv.new
257 rescue
258 ensure
259 if FileTest.directory?(env.processing_path.processing) \
260 and FileTest.directory?(env.processing_path.processing_base_tmp) \
261 and env.processing_path.processing_base_tmp =~/#{env.processing_path.processing}/ \
262 and env.processing_path.processing_base_tmp =~/^\/tmp\/\S+/ \
263 and not argv.inspect =~/"--maintenance"|"-M"/
264 FileUtils::cd(env.processing_path.processing_base_tmp) do
265 FileUtils::rm_rf('.')
266 end
267 end
268 Dir.chdir(call_path)
269 end
270 end
271 end
272 end
273 __END__