json, an output representation, first pass
[software/sisu] / lib / sisu / hub_actions.rb
1 # encoding: utf-8
2 =begin
3
4 * Name: SiSU
5
6 ** Description: documents, structuring, processing, publishing, search
7 *** hub, perform selected actions
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, 2016 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 ** SiSU uses:
42 * Standard SiSU markup syntax,
43 * Standard SiSU meta-markup syntax, and the
44 * Standard SiSU object citation numbering and system
45
46 ** Hompages:
47 [http://www.jus.uio.no/sisu]
48 [http://www.sisudoc.org]
49
50 ** Git
51 [http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary]
52 [http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/hub_actions.rb;hb=HEAD]
53
54 =end
55 module SiSU_Hub_Actions
56 class HubActions
57 require_relative 'utils_composite' # utils_composite.rb
58 include SiSU_Composite_Doc_Utils # composite doc, .ssm, extract all related insert files, array of filenames test
59 def initialize(opt)
60 @opt=opt
61 end
62 def report
63 def version_info?
64 if @opt.act[:version_info][:set]==:on
65 SiSU_Env::InfoAbout.new(@opt).sisu_version
66 end
67 end
68 def version_number_git?
69 if @opt.act[:version_info][:set]==:on \
70 || @opt.act[:verbose][:set]==:on \
71 || @opt.act[:verbose_plus][:set]==:on \
72 || @opt.act[:maintenance][:set]==:on
73 SiSU_Screen::Ansi.new(
74 @opt.act[:color_state][:set],
75 ' ' + SiSU_is.git_version_info?
76 ).grey
77 end
78 end
79 def version_dir?
80 if @opt.act[:version_info][:set]==:on \
81 || @opt.act[:verbose][:set]==:on \
82 || @opt.act[:verbose_plus][:set]==:on \
83 || @opt.act[:maintenance][:set]==:on
84 SiSU_Screen::Ansi.new(
85 @opt.act[:color_state][:set],
86 ' ' + File.dirname(__FILE__)
87 ).grey
88 end
89 end
90 def version_info_extra?
91 if @opt.act[:version_info][:set]==:on \
92 || @opt.act[:verbose][:set]==:on \
93 || @opt.act[:verbose_plus][:set]==:on \
94 || @opt.act[:maintenance][:set]==:on
95 if SiSU_is.git_version_info?
96 SiSU_Screen::Ansi.new(
97 @opt.act[:color_state][:set],
98 ' ' + File.dirname(__FILE__) + \
99 ' vcr: ' + SiSU_is.git_version_info?
100 ).grey
101 else
102 SiSU_Screen::Ansi.new(
103 @opt.act[:color_state][:set],
104 ' ' + File.dirname(__FILE__)
105 ).grey
106 end
107 end
108 end
109 self
110 end
111 def prepare
112 def site?
113 if @opt.act[:site_init][:set]==:on #% --init-site, -C initialize/configure
114 require_relative 'conf' #% --init-site, -C initialize/configure
115 SiSU_Initialize::Source.new(@opt).read
116 if @opt.act[:rsync][:set]==:on
117 if @opt.selections.str =~/--init(?:ialize)?=site/ \
118 and @opt.selections.str =~/RZ/
119 SiSU_Hub_Actions::Operations.new(@opt).remote_put_base_site_rsync_match
120 else SiSU_Hub_Actions::Operations.new(@opt).remote_put_base_site_rsync
121 end
122 elsif @opt.act[:scp][:set]==:on
123 if @opt.selections.str =~/--init(?:ialize)?=site/ \
124 and @opt.selections.str =~/CCr/
125 SiSU_Hub_Actions::Operations.new(@opt).remote_put_base_site_all
126 else SiSU_Hub_Actions::Operations.new(@opt).remote_put_base_site
127 end
128 end
129 end
130 end
131 def remote_site?
132 if @opt.act[:site_init][:set]==:on
133 if @opt.act[:site_init][:set]==:on #% --init-site, -C initialize/configure
134 #require_relative 'conf' #% --init-site, -C initialize/configure
135 #SiSU_Initialize::Source.new(@opt).read
136 #if @opt.act[:rsync][:set]==:on
137 # if @opt.selections.str =~/--init(?:ialize)?=site/ \
138 # and @opt.selection =~/RZ/
139 # SiSU_Hub_Actions::Operations.new(@opt).remote_put_base_site_rsync_match
140 # else SiSU_Hub_Actions::Operations.new(@opt).remote_put_base_site_rsync
141 # end
142 #elsif @opt.act[:scp][:set]==:on
143 # if @opt.selections.str =~/--init(?:ialize)?=site/ \
144 # and @opt.selection =~/CCr/
145 # SiSU_Hub_Actions::Operations.new(@opt).remote_put_base_site_all
146 # else SiSU_Hub_Actions::Operations.new(@opt).remote_put_base_site
147 # end
148 #end
149 end
150 end
151 end
152 def sql?
153 if @opt.act[:psql_createdb][:set]==:on \
154 or @opt.act[:psql_create][:set]==:on \
155 or @opt.act[:psql_drop][:set]==:on
156 done=:ok
157 if @opt.act[:psql][:set]==:on
158 require_relative 'dbi'
159 SiSU_DBI::SQL.new(@opt).connect
160 end
161 end
162 if @opt.act[:sqlite_createdb][:set]==:on \
163 or @opt.act[:sqlite_create][:set]==:on \
164 or @opt.act[:sqlite_drop][:set]==:on
165 done=:ok
166 if @opt.act[:sqlite][:set]==:on
167 require_relative 'dbi'
168 SiSU_DBI::SQL.new(@opt).connect
169 end
170 end
171 end
172 def search_form?
173 if @opt.act[:sample_search_form][:set]==:on #% --sample-search-form, -F cgi sample search form
174 SiSU_Hub_Actions::Operations.new(@opt).cgi
175 end
176 end
177 def webrick?
178 if @opt.act[:webrick][:set]==:on #% --webrick, -W webrick
179 SiSU_Hub_Actions::Operations.new(@opt).webrick
180 end
181 end
182 self
183 end
184 def outputs
185 def each_file
186 def abstract_objects?
187 if @opt.act[:ao][:set]==:on #% --ao --dal, -m
188 if @opt.f_pths.length > 0
189 unless @opt.act[:po4a_shelf][:set]==:on # --po4a-shelf
190 if @opt.fno =~ /\.ssm$/
191 require_relative 'ao_composite' # ao_composite.rb #pre-processing
192 SiSU_Assemble::Composite.new(@opt).read
193 end
194 require_relative 'ao' # ao.rb
195 SiSU_AO::Source.new(@opt).read
196 end
197 else
198 msg='document abstraction request requires sisu markup files'
199 if (@opt.act[:verbose_plus][:set]==:on \
200 || @opt.act[:maintenance][:set]==:on)
201 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
202 mark(msg)
203 else puts msg
204 end
205 end
206 end
207 end
208 def qrcode?
209 if @opt.act[:qrcode][:set]==:on #% --qrcode, -Q
210 if @opt.f_pths.length > 0
211 require_relative 'qrcode' # qrcode.rb
212 SiSU_QRcode::Source.new(@opt).read
213 else
214 msg='qrcode request requires sisu markup files'
215 if (@opt.act[:verbose_plus][:set]==:on \
216 || @opt.act[:maintenance][:set]==:on)
217 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
218 mark(msg)
219 else puts msg
220 end
221 end
222 end
223 end
224 def hash_digests?
225 if @opt.act[:hash_digests][:set]==:on #% --hash-digests, -N digest tree
226 if @opt.f_pths.length > 0
227 require_relative 'digests' # digests.rb
228 SiSU_DigestView::Source.new(@opt).read
229 else
230 msg='hash digest request requires sisu markup files'
231 if (@opt.act[:verbose_plus][:set]==:on \
232 || @opt.act[:maintenance][:set]==:on)
233 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
234 mark(msg)
235 else puts msg
236 end
237 end
238 end
239 end
240 def text?
241 if @opt.act[:txt][:set]==:on #% --txt, -t -a
242 if @opt.f_pths.length > 0
243 require_relative 'txt_plain' # txt_plain.rb
244 SiSU_Txt_Plain::Source.new(@opt).read
245 else
246 msg='text request requires sisu markup files'
247 if (@opt.act[:verbose_plus][:set]==:on \
248 || @opt.act[:maintenance][:set]==:on)
249 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
250 mark(msg)
251 else puts msg
252 end
253 end
254 end
255 if @opt.act[:txt_textile][:set]==:on #% --textile
256 if @opt.f_pths.length > 0
257 require_relative 'txt_textile' #txt_textile.rb
258 SiSU_Txt_Textile::Source.new(@opt).read
259 else
260 msg='textile request requires sisu markup files'
261 if (@opt.act[:verbose_plus][:set]==:on \
262 || @opt.act[:maintenance][:set]==:on)
263 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
264 mark(msg)
265 else puts msg
266 end
267 end
268 end
269 if @opt.act[:txt_asciidoc][:set]==:on #% --asciidoc
270 if @opt.f_pths.length > 0
271 require_relative 'txt_asciidoc' # txt_asciidoc.rb
272 SiSU_Txt_AsciiDoc::Source.new(@opt).read
273 else
274 msg='asciidoc request requires sisu markup files'
275 if (@opt.act[:verbose_plus][:set]==:on \
276 || @opt.act[:maintenance][:set]==:on)
277 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
278 mark(msg)
279 else puts msg
280 end
281 end
282 end
283 if @opt.act[:txt_markdown][:set]==:on #% --markdown
284 if @opt.f_pths.length > 0
285 require_relative 'txt_markdown' # txt_markdown.rb
286 SiSU_Txt_Markdown::Source.new(@opt).read
287 else
288 msg='markdown request requires sisu markup files'
289 if (@opt.act[:verbose_plus][:set]==:on \
290 || @opt.act[:maintenance][:set]==:on)
291 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
292 mark(msg)
293 else puts msg
294 end
295 end
296 end
297 if @opt.act[:txt_rst][:set]==:on #% --rst, --rest
298 if @opt.f_pths.length > 0
299 require_relative 'txt_rst' # txt_rst.rb
300 SiSU_Txt_rST::Source.new(@opt).read
301 else
302 msg='rst request requires sisu markup files'
303 if (@opt.act[:verbose_plus][:set]==:on \
304 || @opt.act[:maintenance][:set]==:on)
305 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
306 mark(msg)
307 else puts msg
308 end
309 end
310 end
311 if @opt.act[:txt_orgmode][:set]==:on #% --orgmode
312 if @opt.f_pths.length > 0
313 require_relative 'txt_orgmode' # txt_orgmode.rb
314 SiSU_Txt_OrgMode::Source.new(@opt).read
315 else
316 msg='orgmode request requires sisu markup files'
317 if (@opt.act[:verbose_plus][:set]==:on \
318 || @opt.act[:maintenance][:set]==:on)
319 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
320 mark(msg)
321 else puts msg
322 end
323 end
324 end
325 end
326 def html?
327 if @opt.act[:html][:set]==:on #% --html, -h
328 if @opt.f_pths.length > 0
329 require_relative 'html' # html.rb
330 SiSU_HTML::Source.new(@opt).read
331 else
332 msg='html request requires sisu markup files'
333 if (@opt.act[:verbose_plus][:set]==:on \
334 || @opt.act[:maintenance][:set]==:on)
335 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
336 mark(msg)
337 else puts msg
338 end
339 end
340 else
341 if @opt.act[:html_seg][:set]==:on #% --html-seg
342 if @opt.f_pths.length > 0
343 require_relative 'html' # html.rb
344 SiSU_HTML::Source.new(@opt).read
345 else
346 msg='html seg request requires sisu markup files'
347 if (@opt.act[:verbose_plus][:set]==:on \
348 || @opt.act[:maintenance][:set]==:on)
349 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
350 mark(msg)
351 else puts msg
352 end
353 end
354 end
355 if @opt.act[:html_scroll][:set]==:on #% --html-scroll
356 if @opt.f_pths.length > 0
357 require_relative 'html' # html.rb
358 SiSU_HTML::Source.new(@opt).read
359 else
360 msg='html scroll request requires sisu markup files'
361 if (@opt.act[:verbose_plus][:set]==:on \
362 || @opt.act[:maintenance][:set]==:on)
363 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
364 mark(msg)
365 else puts msg
366 end
367 end
368 end
369 end
370 if @opt.act[:concordance][:set]==:on #% --concordance, -w
371 if @opt.f_pths.length > 0
372 require_relative 'html_concordance' # html_concordance.rb
373 SiSU_Concordance::Source.new(@opt).read
374 else
375 msg='concordance request requires sisu markup files'
376 if (@opt.act[:verbose_plus][:set]==:on \
377 || @opt.act[:maintenance][:set]==:on)
378 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
379 mark(msg)
380 else puts msg
381 end
382 end
383 end
384 end
385 def json?
386 if @opt.act[:json][:set]==:on #% --js, -J
387 if @opt.f_pths.length > 0
388 require_relative 'json' # json.rb
389 SiSU_JSON::Source.new(@opt).read
390 else
391 msg='json request requires sisu markup files'
392 if (@opt.act[:verbose_plus][:set]==:on \
393 || @opt.act[:maintenance][:set]==:on)
394 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
395 mark(msg)
396 else puts msg
397 end
398 end
399 end
400 end
401 def xhtml?
402 if @opt.act[:xhtml][:set]==:on #% --xhtml, -b
403 if @opt.f_pths.length > 0
404 require_relative 'xhtml' # xhtml.rb
405 SiSU_XHTML::Source.new(@opt).read
406 else
407 msg='xhtml request requires sisu markup files'
408 if (@opt.act[:verbose_plus][:set]==:on \
409 || @opt.act[:maintenance][:set]==:on)
410 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
411 mark(msg)
412 else puts msg
413 end
414 end
415 end
416 if @opt.act[:epub][:set]==:on #% --epub, -e
417 if @opt.f_pths.length > 0
418 require_relative 'xhtml_epub2' # xhtml_epub2.rb
419 SiSU_XHTML_EPUB2::Source.new(@opt).read
420 else
421 msg='epub request requires sisu markup files'
422 if (@opt.act[:verbose_plus][:set]==:on \
423 || @opt.act[:maintenance][:set]==:on)
424 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
425 mark(msg)
426 else puts msg
427 end
428 end
429 end
430 end
431 def xml?
432 if @opt.act[:odt][:set]==:on #% --odt, -o
433 if @opt.f_pths.length > 0
434 require_relative 'xml_odf_odt' # xml_odf_odt.rb
435 SiSU_XML_ODF_ODT::Source.new(@opt).read
436 else
437 msg='odt request requires sisu markup files'
438 if (@opt.act[:verbose_plus][:set]==:on \
439 || @opt.act[:maintenance][:set]==:on)
440 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
441 mark(msg)
442 else puts msg
443 end
444 end
445 end
446 if @opt.act[:xml_scaffold_structure_sisu][:set]==:on #% --xml-scaffold --xml-scaffold-sisu
447 if @opt.f_pths.length > 0
448 require_relative 'xml_scaffold_structure_sisu' # xml_scaffold_structure_sisu.rb
449 SiSU_XML_Scaffold_Structure_Sisu::Source.new(@opt).read
450 else
451 msg='xml scaffold request requires sisu markup files'
452 if (@opt.act[:verbose_plus][:set]==:on \
453 || @opt.act[:maintenance][:set]==:on)
454 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
455 mark(msg)
456 else puts msg
457 end
458 end
459 end
460 if @opt.act[:xml_scaffold_structure_collapse][:set]==:on #% --xml-scaffold-collapse
461 if @opt.f_pths.length > 0
462 require_relative 'xml_scaffold_structure_collapsed' # xml_scaffold_structure_collapsed.rb
463 SiSU_XML_Scaffold_Structure_Collapse::Source.new(@opt).read
464 else
465 msg='xml scaffold request requires sisu markup files'
466 if (@opt.act[:verbose_plus][:set]==:on \
467 || @opt.act[:maintenance][:set]==:on)
468 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
469 mark(msg)
470 else puts msg
471 end
472 end
473 end
474 if @opt.act[:xml_docbook_book][:set]==:on #% --xml-docbook
475 if @opt.f_pths.length > 0
476 require_relative 'xml_docbook5' # xml_docbook5.rb
477 SiSU_XML_Docbook_Book::Source.new(@opt).read
478 else
479 msg='docbook request requires sisu markup files'
480 if (@opt.act[:verbose_plus][:set]==:on \
481 || @opt.act[:maintenance][:set]==:on)
482 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
483 mark(msg)
484 else puts msg
485 end
486 end
487 end
488 if @opt.act[:xml_fictionbook][:set]==:on #% --xml-fictionbook
489 if @opt.f_pths.length > 0
490 require_relative 'xml_fictionbook2' # xml_fictionbook2.rb
491 SiSU_XML_Fictionbook::Source.new(@opt).read
492 else
493 msg='fictionbook request requires sisu markup files'
494 if (@opt.act[:verbose_plus][:set]==:on \
495 || @opt.act[:maintenance][:set]==:on)
496 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
497 mark(msg)
498 else puts msg
499 end
500 end
501 end
502 if @opt.act[:xml_sax][:set]==:on #% --xml-sax, -x
503 if @opt.f_pths.length > 0
504 require_relative 'xml_sax' # xml_sax.rb
505 SiSU_XML_SAX::Source.new(@opt).read
506 else
507 msg='xml sax request requires sisu markup files'
508 if (@opt.act[:verbose_plus][:set]==:on \
509 || @opt.act[:maintenance][:set]==:on)
510 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
511 mark(msg)
512 else puts msg
513 end
514 end
515 end
516 if @opt.act[:xml_dom][:set]==:on #% --xml-dom, -X
517 if @opt.f_pths.length > 0
518 require_relative 'xml_dom' # xml_dom.rb
519 SiSU_XML_DOM::Source.new(@opt).read
520 else
521 msg='xml dom request requires sisu markup files'
522 if (@opt.act[:verbose_plus][:set]==:on \
523 || @opt.act[:maintenance][:set]==:on)
524 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
525 mark(msg)
526 else puts msg
527 end
528 end
529 end
530 end
531 def pdf?
532 if @opt.act[:pdf][:set]==:on \
533 or @opt.act[:pdf_p][:set]==:on \
534 or @opt.act[:pdf_l][:set]==:on #% --pdf-l --pdf, -p
535 if @opt.f_pths.length > 0
536 require_relative 'texpdf' # texpdf.rb
537 SiSU_TeX::Source.new(@opt).read
538 else
539 msg='pdf request requires sisu markup files'
540 if (@opt.act[:verbose_plus][:set]==:on \
541 || @opt.act[:maintenance][:set]==:on)
542 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
543 mark(msg)
544 else puts msg
545 end
546 end
547 end
548 end
549 def man_or_info?
550 if @opt.act[:manpage][:set]==:on #% --manpage, -i
551 if @opt.f_pths.length > 0
552 require_relative 'manpage' # manpage.rb
553 SiSU_Manpage::Source.new(@opt).read
554 else
555 msg='manpage request requires sisu markup files'
556 if (@opt.act[:verbose_plus][:set]==:on \
557 || @opt.act[:maintenance][:set]==:on)
558 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
559 mark(msg)
560 else puts msg
561 end
562 end
563 end
564 if @opt.act[:texinfo][:set]==:on #% --texinfo, -I
565 if @opt.f_pths.length > 0
566 require_relative 'texinfo' # texinfo.rb
567 SiSU_TexInfo::Source.new(@opt).read
568 else
569 msg='texinfo request requires sisu markup files'
570 if (@opt.act[:verbose_plus][:set]==:on \
571 || @opt.act[:maintenance][:set]==:on)
572 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
573 mark(msg)
574 else puts msg
575 end
576 end
577 end
578 end
579 def sqlite_discrete?
580 if @opt.act[:sqlite_discrete][:set]==:on #% --sqlite, -d
581 if @opt.f_pths.length > 0
582 require_relative 'dbi_discrete' # dbi_discrete.rb
583 SiSU_DBI_Discrete::SQL.new(@opt).build
584 else
585 msg='sqlite (discrete) request requires sisu markup files'
586 if (@opt.act[:verbose_plus][:set]==:on \
587 || @opt.act[:maintenance][:set]==:on)
588 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
589 mark(msg)
590 else puts msg
591 end
592 end
593 end
594 end
595 def po4a_make?
596 if @opt.act[:po4a_sst_ao_sst][:set]==:on #% --po4a-ao
597 if @opt.f_pths.length > 0
598 require_relative 'src_po4a_sst_ao_sst'
599 SiSU_SStm_AO_SStm::Source.new(@opt).read_process_src_files # src_po4a_sst_ao_sst.rb
600 else
601 msg='sst request requires sisu markup files'
602 if (@opt.act[:verbose_plus][:set]==:on \
603 || @opt.act[:maintenance][:set]==:on)
604 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:cyan).
605 mark(msg)
606 else puts msg
607 end
608 end
609 end
610 end
611 def elasticsearch?
612 if @opt.act[:elasticsearch][:set]==:on #% --elastic, -x
613 if @opt.f_pths.length > 0
614 require_relative 'json_elastic' # json_elastic.rb
615 SiSU_Elastic::Source.new(@opt).read
616 else
617 msg='easticsearch request requires sisu markup files'
618 if (@opt.act[:verbose_plus][:set]==:on \
619 || @opt.act[:maintenance][:set]==:on)
620 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
621 mark(msg)
622 else puts msg
623 end
624 end
625 end
626 end
627 def manifest?
628 if @opt.act[:manifest][:set]==:on #% --manifest, -y
629 if @opt.f_pths.length > 0
630 begin
631 require_relative 'html_manifest' # html_manifest.rb
632 ((@opt.act[:sisupod][:set]==:on \
633 || @opt.act[:share_source][:set]==:on \
634 || @opt.act[:po4a_sstm][:set]==:on) \
635 && @opt.f_pths.length < 2 ) \
636 ? nil
637 : SiSU_Manifest::Source.new(@opt).read
638 rescue
639 end
640 else
641 msg='manifest request requires sisu markup files'
642 if (@opt.act[:verbose_plus][:set]==:on \
643 || @opt.act[:maintenance][:set]==:on)
644 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
645 mark(msg)
646 else puts msg
647 end
648 end
649 end
650 end
651 def harvest?
652 if @opt.act[:harvest][:set]==:on #% --harvest
653 if @opt.f_pths.length > 0
654 require_relative 'html_harvest' # html_harvest.rb
655 SiSU_Harvest::Source.new(@opt).read
656 else
657 msg='harvest request requires sisu markup files'
658 if (@opt.act[:verbose_plus][:set]==:on \
659 || @opt.act[:maintenance][:set]==:on)
660 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:yellow).
661 mark(msg)
662 else puts msg
663 end
664 end
665 end
666 end
667 self
668 end
669 def loop_files
670 def share_source?
671 if @opt.act[:sisupod][:set]==:on \
672 or @opt.act[:share_source][:set]==:on \
673 or @opt.act[:po4a_sstm][:set]==:on \
674 or @opt.act[:git][:set]==:on
675 begin
676 if @opt.f_pths.length > 0
677 require_relative 'src_shared'
678 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).
679 loop_files_on_given_option do
680 SiSU_Source::SiSUpodSource.new(@opt).read
681 end
682 else
683 msg='share markup source request requires sisu markup files'
684 if (@opt.act[:verbose_plus][:set]==:on \
685 || @opt.act[:maintenance][:set]==:on)
686 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:cyan).
687 mark(msg)
688 else puts msg
689 end
690 end
691 if @opt.act[:sisupod][:set]==:on #% --sisupod, -S
692 if @opt.f_pths.length > 0
693 require_relative 'src_sisupod_make' # src_sisupod_make.rb
694 begin
695 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).
696 loop_files_on_given_option_bundle do
697 SiSU_Doc::Source.new(@opt).sisupod_tar_xz
698 end
699 ensure
700 end
701 else
702 msg='sisupod (share markup source) request requires sisu markup files'
703 if (@opt.act[:verbose_plus][:set]==:on \
704 || @opt.act[:maintenance][:set]==:on)
705 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:cyan).
706 mark(msg)
707 else puts msg
708 end
709 end
710 end
711 if @opt.act[:git][:set]==:on #% --git, -g
712 if @opt.f_pths.length > 0
713 require_relative 'git' # git.rb
714 begin
715 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).
716 loop_files_on_given_option do
717 SiSU_Git::Source.new(@opt).read
718 end
719 ensure
720 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).
721 loop_files_on_given_option_bundle do
722 SiSU_Git::Source.new(@opt).git_commit
723 end
724 end
725 else
726 msg='git request requires sisu markup files'
727 if (@opt.act[:verbose_plus][:set]==:on \
728 || @opt.act[:maintenance][:set]==:on)
729 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:cyan).
730 mark(msg)
731 else puts msg
732 end
733 end
734 end
735 if (@opt.act[:sisupod][:set]==:on \
736 || @opt.act[:share_source][:set]==:on \
737 || @opt.act[:po4a_sstm][:set]==:on) \
738 and @opt.act[:manifest][:set]==:on #% --manifest, -y
739 if @opt.f_pths.length > 0
740 require_relative 'html_manifest' # html_manifest.rb
741 begin
742 ensure
743 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).
744 loop_files_on_given_option_bundle do
745 SiSU_Manifest::Source.new(@opt).read
746 end
747 end
748 else
749 msg='manifest request requires sisu markup files'
750 if (@opt.act[:verbose_plus][:set]==:on \
751 || @opt.act[:maintenance][:set]==:on)
752 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:cyan).
753 mark(msg)
754 else puts msg
755 end
756 end
757 end
758 ensure
759 if @opt.f_pths.length > 0
760 env=SiSU_Env::InfoEnv.new(@opt.fns)
761 path_pod=env.processing_path.processing_sisupod(@opt).paths
762 unless @opt.act[:maintenance][:set]==:on
763 FileUtils::rm_rf("#{path_pod[:sisupod]}/*") \
764 if FileTest.directory?(path_pod[:sisupod])
765 end
766 else
767 #SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:cyan).
768 # mark('*** request requires sisu markup files')
769 end
770 end
771 end
772 if @opt.act[:share_source][:set]==:on
773 if @opt.f_pths.length > 0
774 require_relative 'src_sisupod_sstm' # src_sisupod_sstm.rb
775 begin
776 ensure
777 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).
778 loop_files_on_given_option_bundle do
779 SiSU_Markup::Source_Sisupod.new(@opt).read
780 end
781 end
782 else
783 msg='share markup source request requires sisu markup files'
784 if (@opt.act[:verbose_plus][:set]==:on \
785 || @opt.act[:maintenance][:set]==:on)
786 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:cyan).
787 mark(msg)
788 else puts msg
789 end
790 end
791 end
792 if @opt.act[:po4a_sstm][:set]==:on #% --po4a-sst
793 if @opt.f_pths.length > 0
794 require_relative 'src_po4a_sstm'
795 begin
796 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).
797 loop_files_on_given_option do
798 SiSU_Markup::Source_Po4a.new(@opt).read # src_po4a_sstm.rb
799 end
800 ensure
801 end
802 else
803 msg='sst request requires sisu markup files'
804 if (@opt.act[:verbose_plus][:set]==:on \
805 || @opt.act[:maintenance][:set]==:on)
806 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:cyan).
807 mark(msg)
808 else puts msg
809 end
810 end
811 end
812 if @opt.act[:po4a_sst_ao_sst][:set]==:on #% --po4a-ao
813 if @opt.f_pths.length > 0
814 require_relative 'src_po4a_sst_ao_sst'
815 begin
816 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).
817 loop_files_on_given_option do
818 SiSU_SStm_AO_SStm::Source.new(@opt).read_setup # src_po4a_sst_ao_sst.rb
819 end
820 ensure
821 end
822 else
823 msg='sst request requires sisu markup files'
824 if (@opt.act[:verbose_plus][:set]==:on \
825 || @opt.act[:maintenance][:set]==:on)
826 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:cyan).
827 mark(msg)
828 else puts msg
829 end
830 end
831 end
832 if @opt.act[:po4a_shelf][:set]==:on #% --po4a-shelf
833 if @opt.f_pths.length > 0
834 require_relative 'src_po4a_shelf'
835 begin
836 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).
837 loop_files_on_given_option do
838 SiSU_Po4a::Source.new(@opt).read # src_po4a_shelf.rb
839 end
840 ensure
841 end
842 else
843 msg='src_po4a_shelf request requires sisu markup files'
844 if (@opt.act[:verbose_plus][:set]==:on \
845 || @opt.act[:maintenance][:set]==:on)
846 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:cyan).
847 mark(msg)
848 else puts msg
849 end
850 end
851 end
852 if @opt.act[:images][:set]==:on #% --images, -j
853 if @opt.f_pths.length > 0
854 require_relative 'shared_images'
855 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).
856 loop_files_on_given_option do
857 SiSU_Images::Source.new(@opt).read # shared_images.rb
858 end
859 else
860 msg='place images request requires sisu markup files'
861 if (@opt.act[:verbose_plus][:set]==:on \
862 || @opt.act[:maintenance][:set]==:on)
863 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:cyan).
864 mark(msg)
865 else puts msg
866 end
867 end
868 end
869 end
870 def run_termsheet? #broken, revisit later
871 if @opt.selections.str =~/--termsheet/ #% -T termsheet/standard form #fix later
872 if @opt.f_pths.length > 0
873 @opt.files.each do |fns|
874 if FileTest.file?(fns)
875 @opt.fns=fns
876 case @opt.fns
877 when /\.(termsheet.rb)$/
878 SiSU_Hub_Actions::Operations.new(@opt).termsheet
879 else #print "not processed --> ", fns, "\n"
880 end
881 else SiSU_Hub_Actions::Operations.new(@opt).not_found
882 end
883 end
884 else
885 msg='process termsheet request requires sisu markup files'
886 if (@opt.act[:verbose_plus][:set]==:on \
887 || @opt.act[:maintenance][:set]==:on)
888 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:cyan).
889 mark(msg)
890 else puts msg
891 end
892 end
893 end
894 end
895 def sql?
896 if @opt.act[:psql][:set]==:on #% --pg, -D
897 if @opt.f_pths.length > 0
898 require_relative 'dbi'
899 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).
900 loop_files_on_given_option do
901 SiSU_DBI::SQL.new(@opt).connect # dbi.rb
902 end
903 else
904 msg='pgsql request requires sisu markup files'
905 if (@opt.act[:verbose_plus][:set]==:on \
906 || @opt.act[:maintenance][:set]==:on)
907 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:cyan).
908 mark(msg)
909 else puts msg
910 end
911 end
912 end
913 if @opt.act[:sqlite][:set]==:on #% --sqlite, -d
914 if @opt.f_pths.length > 0
915 require_relative 'dbi'
916 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).
917 loop_files_on_given_option do
918 SiSU_DBI::SQL.new(@opt).connect # dbi.rb
919 end
920 else
921 msg='sqlite request requires sisu markup files'
922 if (@opt.act[:verbose_plus][:set]==:on \
923 || @opt.act[:maintenance][:set]==:on)
924 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:cyan).
925 mark(msg)
926 else puts msg
927 end
928 end
929 end
930 end
931 def manifest?
932 if @opt.act[:manifest][:set]==:on #% --manifest, -y
933 if @opt.f_pths.length > 1
934 require_relative 'html_manifest'
935 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).manifest_on_files_translated do
936 SiSU_Manifest::Source.new(@opt).read # html_manifest.rb
937 end
938 end
939 end
940 end
941 def sitemaps?
942 if @opt.act[:sitemap][:set]==:on #% --sitemap, -Y
943 if @opt.f_pths.length > 0
944 require_relative 'sitemaps'
945 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).
946 loop_files_on_given_option do
947 SiSU_Sitemaps::Source.new(@opt).read # sitemaps.rb
948 end
949 end
950 end
951 end
952 def remote_placement?
953 if @opt.act[:harvest][:set] !=:on
954 if @opt.act[:scp][:set]==:on #% -r copy to remote server
955 if @opt.f_pths.length > 0
956 require_relative 'remote' # remote.rb
957 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).
958 loop_files_on_given_option do
959 SiSU_Remote::Put.new(@opt).scp
960 end
961 end
962 end
963 if @opt.act[:rsync][:set]==:on #% -R copy to remote server
964 if @opt.f_pths.length > 0
965 require_relative 'remote' # remote.rb
966 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).
967 loop_files_on_given_option do
968 SiSU_Remote::Put.new(@opt).rsync
969 end
970 end
971 end
972 else
973 end
974 end
975 def urls?
976 if @opt.act[:urls_selected][:set]==:on #% --urls
977 if @opt.f_pths.length > 0
978 require_relative 'urls'
979 SiSU_Hub_Loops::OptionLoopFiles.new(@opt).
980 loop_files_on_given_option do
981 SiSU_Urls::Source.new(@opt).read #% urls.rb
982 end
983 else
984 msg='urls request requires sisu markup files'
985 if (@opt.act[:verbose_plus][:set]==:on \
986 || @opt.act[:maintenance][:set]==:on)
987 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:cyan).
988 mark(msg)
989 else puts msg
990 end
991 end
992 end
993 end
994 self
995 end
996 def init?
997 SiSU_Env::InfoProcessingFlag.new
998 if @opt.act[:ao][:set]==:on \
999 or @opt.act[:maintenance][:set]==:on #% --maintenance, -M
1000 env=SiSU_Env::InfoEnv.new(@opt.fns)
1001 path={}
1002 path[:css]=env.path.output + '/_sisu/css'
1003 path[:xml]=env.path.output + '/_sisu/xml'
1004 path[:xsd]=path[:xml] + '/xsd'
1005 path[:xsd]=path[:xml] + '/rnc'
1006 path[:xsd]=path[:xml] + '/rng'
1007 re_p3=/(sisupod(?:\.txz)?|\S+?\.ss[mt]\.txz|[^\/]+?\.ssp)$/
1008 unless @opt.files.join(',') =~ re_p3 #do not mix pods with source markup files in command line
1009 if @opt.act[:maintenance][:set] ==:on
1010 $VERBOSE=false #debug $VERBOSE=true
1011 end
1012 end
1013 re_p2=/(sisupod(?:\.zip)?|\S+?\.ss[mt]\.zip)$/
1014 unless @opt.files.join(',') =~ re_p2 #do not mix pods with source markup files in command line
1015 if @opt.act[:maintenance][:set] ==:on
1016 $VERBOSE=false #debug $VERBOSE=true
1017 end
1018 end
1019 end
1020 if @opt.act[:ao][:set]==:on
1021 @retry_count= -1
1022 begin
1023 @get_s,@get_p,@get_pl=[],[],[]
1024 re_s=/(\S+?\.-sst)$/
1025 re_p3=/((?:https?|file):\/\/\S+?(?:\/\S+?\.ss[mt]\.txz|sisupod(?:\.txz)?|\.ssp))/
1026 re_pl3=/^(\/\S+?\.ss[mt]\.txz)/
1027 @opt.files.each do |fns|
1028 if fns =~re_s
1029 @get_s << @opt.f_pths[0][:url]
1030 end
1031 if fns =~re_p3
1032 @get_p << re_p3.match(fns)[1] if re_p3
1033 end
1034 if fns =~re_pl3
1035 @get_pl << re_pl3.match(fns)[1] if re_p3
1036 end
1037 end
1038 if @get_s.length > 0 #% remote markup file .sst
1039 require_relative 'remote' # remote.rb
1040 SiSU_Remote::Get.new(@opt,@get_s).fns
1041 SiSU_Hub_Actions::Operations.new.counter
1042 end
1043 if @get_p.length > 0 #% remote sisupod
1044 require_relative 'remote' # remote.rb
1045 SiSU_Remote::Get.new(@opt,@get_p).sisupod
1046 end
1047 rescue
1048 SiSU_Errors::Rescued.new($!,$@,@opt,@fns).location do
1049 __LINE__.to_s + ':' + __FILE__
1050 end
1051 @retry_count +=1
1052 retry unless @retry_count > 1
1053 ensure
1054 end
1055 end
1056 end
1057 self
1058 end
1059 end
1060 class Operations
1061 @@n_do=0
1062 def initialize(opt='')
1063 @opt=opt
1064 @cX=SiSU_Screen::Ansi.new(@opt).cX
1065 end
1066 def counter
1067 @@n_do=0
1068 end
1069 def remote_put_base_site_rsync # -CR
1070 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark(:cyan) \
1071 if @opt.act[:maintenance][:set] ==:on
1072 require_relative 'remote' # remote.rb
1073 SiSU_Remote::Put.new(@opt).rsync_base
1074 end
1075 def remote_put_base_site_rsync_match # -CCRZ
1076 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark(:cyan) \
1077 if @opt.act[:maintenance][:set] ==:on
1078 require_relative 'remote' # remote.rb
1079 SiSU_Remote::Put.new(@opt).rsync_base_sync
1080 end
1081 def remote_put_base_site # -Cr
1082 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark(:cyan) \
1083 if @opt.act[:maintenance][:set] ==:on
1084 require_relative 'remote' # remote.rb
1085 SiSU_Remote::Put.new(@opt).scp_base
1086 end
1087 def remote_put_base_site_all # -CCr
1088 SiSU_Utils::CodeMarker.new(__LINE__,__FILE__).mark(:cyan) \
1089 if @opt.act[:maintenance][:set] ==:on
1090 require_relative 'remote' # remote.rb
1091 SiSU_Remote::Put.new(@opt).scp_base_all
1092 end
1093 def cgi # -F
1094 require_relative 'cgi' # cgi.rb
1095 SiSU_CGI::SearchSQL.new(@opt).read
1096 end
1097 def termsheet # -t
1098 system("sisu_termsheet #{@opt.selections.str} #{@opt.fns}\n")
1099 @@n_do=@@n_do+1
1100 SiSU_Screen::Ansi.new(
1101 @opt.selections.str,@@n_do,
1102 'Termsheet(s) processed'
1103 ).term_sheet_title unless @opt.act[:quiet][:set] ==:on
1104 end
1105 def webrick # -W
1106 prt=SiSU_Env::InfoEnv.new(@fns).port.webrick_port
1107 puts %{#{@cX.blue}<<#{@cX.off}#{@cX.green}Start Webrick web server on port: #{prt}#{@cX.off}#{@cX.blue}>> #{@cX.off*2} }
1108 require_relative 'webrick'
1109 SiSU_Webserv::WebrickStart.new
1110 end
1111 def not_found
1112 puts "\n#{@cX.fuchsia}FILE NOT FOUND:#{@cX.off} << #{@opt.fns} >> - requested #{@opt.selections.str} processing skipped\n"
1113 end
1114 def convert_name_message(fns,type,i,o,rune)
1115 %{\nIn filename: "#{@cX.fuchsia}#{fns}#{@cX.off}" << #{type} >> #{@cX.fuchsia}is apre 0.36 markup filename.#{@cX.off} #{@cX.brown}Please rename your file.#{@cX.off}\n\tAs of sisu-0.37, SiSU markup files with #{@cX.brown}the extensions #{i} should be re-named #{o}#{@cX.off}\n\tif you have the program called 'rename' installed, the following rune should do the trick:\n\t\t#{rune}\n\talternatively try:\n\t\tsisu --convert --36to37 #{fns}\n\trequested #{@opt.selections.str} processing skipped\n}
1116 end
1117 def not_recognised
1118 case @opt.fns
1119 when /(\.s[123])$/
1120 type=@opt.fns.gsub(/\S+?(#{$1})/,'\1')
1121 rune=%q{rename 's/\.s[123]$/\.sst/' *.s{1,2,3}}
1122 puts convert_name_message(@opt.fns,type,'.s1 .s2 and .s3','.sst',rune)
1123 when /(\.r[123])$/
1124 type=@opt.fns.gsub(/\S+?(#{$1})/,'\1')
1125 rune=%q{rename 's/\.r[123]$/\.ssm/' *.r{1,2,3}}
1126 puts convert_name_message(@opt.fns,type,'.r1 .r2 and .r3','.sst',rune)
1127 puts %{\n\tNote also that you will need to change the names of the files called/required\n\twithin the document text to build the composite document\n\t\t.s1 .s2 .s3 should be .sst \n\t\t.si should be .ssi\n\trequested #{@opt.selections.str} processing skipped\n}
1128 when /(\.ssi)$/
1129 puts "\n#{@cX.fuchsia}component filetype:#{@cX.off} << #{@opt.fns} >> - is not a processed filetype, (it may be used as a component of a .ssm markup file)\n\trequested #{@opt.selections.str} processing skipped\n"
1130 else
1131 puts "\n#{@cX.fuchsia}FILETYPE NOT RECOGNISED:#{@cX.off} << #{@opt.fns} >> - is not a recognized filetype,\n\trequested #{@opt.selections.str} processing skipped\n"
1132 end
1133 end
1134 end
1135 end
1136 __END__