From f297b90d4089b5bfe2f63010a6800e8d52047771 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 1 May 2012 23:37:43 -0400 Subject: v3: hub (seek finer grained control over what happens when; causes breakage) * (primarily) cycle files then options (instead of options then files) * manifest re-run on (currently generated) translated files if any --- lib/sisu/v3/hub.rb | 403 ++++++++++++++++++++++++++++--------------------- lib/sisu/v3/options.rb | 28 +++- 2 files changed, 256 insertions(+), 175 deletions(-) (limited to 'lib') diff --git a/lib/sisu/v3/hub.rb b/lib/sisu/v3/hub.rb index 241d1538..ce8446e5 100644 --- a/lib/sisu/v3/hub.rb +++ b/lib/sisu/v3/hub.rb @@ -62,6 +62,64 @@ module SiSU require_relative 'sysenv' # sysenv.rb include SiSU_Screen @@pwd_the=Dir.pwd + class OptionLoopFiles + def initialize(opt) + @opt=opt + end + def loop_files_on_given_option + @opt.files.each_with_index do |fns,i| + @opt.fns=fns + @opt.f_pth=@opt.f_pths[i] + if fns !~/\.-sst$/ + @opt.pth=@opt.paths[i] + @opt.lng=@opt.lngs[i] + else + @opt.pth=Dir.pwd + @opt.lng='en' + end + @@pwd=@opt.pth + Dir.chdir(@opt.pth) #watch + @env=SiSU_Env::InfoEnv.new(fns) + yield + end + end + def manifest_on_files_translated + r=Px[:lng_lst].join('|') + number_of_files={} + @opt.files.each_with_index do |fns,i| + fn=fns.gsub(/(?:\.#{r})?\.ss[tm]$/,'') + if number_of_files[fn].class == Array + number_of_files[fn] << i + else + number_of_files = { fn => [i] } + end + end + files_translated_idx=[] + number_of_files.each do |x| + if x[1].length > 1 + files_translated_idx << x[1] + end + end + if files_translated_idx.flatten.length > 1 + SiSU_Screen::Ansi.new(@opt.cmd,'Manifest re-run on (currently generated) tranlated files',"").grey_title_hi unless @opt.cmd =~/q/ + files_translated_idx.flatten.each do |i| + @opt.fns=@opt.files[i] + @opt.f_pth=@opt.f_pths[i] + if @opt.fns !~/\.-sst$/ + @opt.pth=@opt.paths[i] + @opt.lng=@opt.lngs[i] + else + @opt.pth=Dir.pwd + @opt.lng='en' + end + @@pwd=@opt.pth + Dir.chdir(@opt.pth) #watch + @env=SiSU_Env::InfoEnv.new(@opt.fns) + yield + end + end + end + end class Op @@env=SiSU_Env::InfoEnv.new def initialize(opt,req,message) @@ -124,9 +182,6 @@ module SiSU end def select require_relative @req - if @req =~/^conf$/ # -C - SiSU_Initialize::Source.new(@opt).read - end if not @opt.files.empty? @opt.files.each_with_index do |fns,i| env=SiSU_Env::InfoEnv.new(fns) @@ -177,64 +232,9 @@ module SiSU and @req =~ /^po4a$/ require_relative 'composite' # composite.rb #pre-processing SiSU_Po4a::Source.new(@opt).read # -P po4a.rb - elsif @req=~/^dal$/ \ - and FileTest.file?(@opt.fns) \ - and @opt.fns =~ /\.(?:(?:-|ssm\.)?sst|ssm)$/ - if fns =~ /\.ssm$/ - require_relative 'composite' # composite.rb #pre-processing - SiSU_Assemble::Composite.new(@opt).read - @opt.fns=fns.gsub(/\.ssm$/,'.ssm.sst') - end - SiSU_DAL::Source.new(@opt).read # -m - elsif FileTest.file?(env.source_file_with_path) - case @opt.fns - when /\.(?:(?:-|ssm\.)?sst|ssm)$/ - case @req - when /^dal$/ - if fns =~ /\.ssm$/ - require_relative 'composite' # composite.rb #pre-processing - SiSU_Assemble::Composite.new(@opt).read - @opt.fns=fns.gsub(/\.ssm$/,'.ssm.sst') - end - SiSU_DAL::Source.new(@opt).read # -m dal.rb - when /^git$/; SiSU_Git::Source.new(@opt).read # -g git.rb - when /^concordance$/; SiSU_Concordance::Source.new(@opt).read # -w concordance.rb - when /^share_src$/; SiSU_Markup::Source.new(@opt).read # -s share_src.rb - when /^sisupod_make$/; SiSU_Doc::Source.new(@opt).read # -S sisupod_make.rb -# when /^source_kdissert$/; SiSU_KdiSource::Source.new(@opt).read # -S share_src_kdissert.rb - when /^digests$/; SiSU_DigestView::Source.new(@opt).read # -N digests.rb - when /^plaintext$/; SiSU_Plaintext::Source.new(@opt).read # -t -a plaintext.rb - when /^po4a$/; SiSU_Po4a::Source.new(@opt).read # -P po4a.rb - #when /^wikispeak$/; SiSU_Wikispeak::Source.new(@opt).read # -g - when /^epub$/; SiSU_EPUB::Source.new(@opt).read # -e epub.rb - when /^odf$/; SiSU_ODF::Source.new(@opt).read # -o odf.rb - when /^xml_md_oai_pmh_dc$/; SiSU_XML_Metadata::OAI_PMH.new(@opt).read # -O - when /^texpdf$/; SiSU_TeX::Source.new(@opt).read # -p texpdf.rb - when /^manpage$/; SiSU_Manpage::Source.new(@opt).read # -i manpage.rb - when /^texinfo$/; SiSU_TexInfo::Source.new(@opt).read # -I texinfo.rb - when /^html$/; SiSU_HTML::Source.new(@opt).read # -h -H html.rb - when /^xhtml$/; SiSU_XHTML::Source.new(@opt).read # -b xhtml.rb - when /^xml$/; SiSU_XML_SAX::Source.new(@opt).read # -x xml.rb - when /^xml_dom$/; SiSU_XML_DOM::Source.new(@opt).read # -X xml_dom.rb - when /^shared_images$/; SiSU_Images::Source.new(@opt).read # -j shared_images.rb - #when /^xml_fictionbook$/; SiSU_XML_Fictionbook::Source.new(@opt).read # -f - when /^xml_scaffold$/; SiSU_XML_Scaffold::Source.new(@opt).read # -k xml_scaffold.rb - when /^embedded$/; SiSU_Embedded::Source.new(@opt).read # -m embedded.rb (image and other content) #check - when /^manifest$/; SiSU_Manifest::Source.new(@opt).read # -y manifest.rb - when /^qrcode$/; SiSU_QRcode::Source.new(@opt).read # -Q qrcode.rb - when /^sitemaps$/; SiSU_Sitemaps::Source.new(@opt).read # -Y sitemaps.rb - when /^zap$/; SiSU_Zap::Source.new(@opt).read # -Z zap.rb - when /^dbi$/; SiSU_DBI::SQL.new(@opt).connect # -D -d dbi.rb - when /^dbi_discreet$/; SiSU_DBI_Discreet::SQL.new(@opt).build # -d dbi_discreet.rb - end - @n_do=@n_do+1 - SiSU_Screen::Ansi.new(@opt.cmd,@n_do,"#{@req.upcase} processed").files_processed if @opt.cmd =~/[MVv]/ - ObjectSpace.garbage_collect - else #print "not processed --> ", fns, "\n" - end else - if @req !~/^conf$/ \ - and @opt.fns !~/http:\/\// + if @req !~/^conf$/ \ + and @opt.fns !~/http:\/\// SiSU::Operations.new(@opt).not_found end end @@ -256,8 +256,8 @@ module SiSU end end end - elsif @req =~/^dbi$/; SiSU_DBI::SQL.new(@opt).connect # -D -d - elsif @req=~/^sisupod_make$/; SiSU_Doc::Source.new(@opt).read # -S + #elsif @req =~/^dbi$/; SiSU_DBI::SQL.new(@opt).connect # -D -d + #elsif @req=~/^sisupod_make$/; SiSU_Doc::Source.new(@opt).read # -S end SiSU::Operations.new.counter end @@ -429,9 +429,6 @@ p "here #{__FILE__} #{__LINE__}" if @opt =~/M/ if @opt.cmd =~/Z/ #% -Z wipe previous output clean op('zap','Zap, deletions') end - if @opt.act[:share_source][:bool] - op('share_src','SiSU markup source') - end if @opt.act[:dal][:bool] @retry_count= -1 begin @@ -477,119 +474,185 @@ p "here #{__FILE__} #{__LINE__}" if @opt =~/M/ retry unless @retry_count > 1 ensure end - @opt.files=@opt.files.collect {|x| x=x.gsub(/(?:https?|file):\/\/\S+\/(\S+)\.sst$/,'\1.-sst') } - end - if @opt.act[:dal][:bool] #%--dal, -m - op('dal','dal') - end - @opt.files=@opt.files.collect {|x| x=x.gsub(/\.ssm$/,'.ssm.sst') } - if @opt.act[:sisupod][:bool] #% --sisupod, -S make sisupod - op('sisupod_make','sisupod (txz)') - if @opt.fns=~/\.kdi._sst/ - op('share_src_kdissert','kdissert (kdi)') #% -S share kdissert source + #@opt.files=@opt.files.collect {|x| x=x.gsub(/(?:https?|file):\/\/\S+\/(\S+)\.sst$/,'\1.-sst') } + end + #@opt.files_mod=@opt.files.collect {|x| x=x.gsub(/\.ssm$/,'.ssm.sst') } + def requires(req) + require_relative req + end + def each_file_loop_options + @opt.files.each_with_index do |fno,i| + @opt.fno=fno + @opt.fns=fno.gsub(/(?:https?|file):\/\/\S+\/(\S+)\.sst$/,'\1.-sst'). + gsub(/\.ssm$/,'.ssm.sst') + @opt.f_pth=@opt.f_pths[i] + if @opt.fns !~/\.-sst$/ + @opt.pth=@opt.paths[i] + @opt.lng=@opt.lngs[i] + else + @opt.pth=Dir.pwd + @opt.lng='en' + end + @@pwd=@opt.pth + Dir.chdir(@opt.pth) #watch + @env=SiSU_Env::InfoEnv.new(@opt.fns) + if @opt.act[:dal][:bool] #% --dal, -m + if @opt.fno =~ /\.ssm$/ + require_relative 'composite' # composite.rb #pre-processing + SiSU_Assemble::Composite.new(@opt).read + end + requires('dal') # -m dal.rb + SiSU_DAL::Source.new(@opt).read + end + if @opt.act[:share_source][:bool] + requires('share_src') # -s share_src.rb + SiSU_Markup::Source.new(@opt).read + end + if @opt.act[:sisupod][:bool] #% --sisupod, -S make sisupod + requires('sisupod_make') # -S sisupod_make.rb + SiSU_Doc::Source.new(@opt).read + end + if @opt.act[:qrcode][:bool] #% --qrcode, -Q + requires('qrcode') # -Q qrcode.rb + SiSU_QRcode::Source.new(@opt).read + end + if @opt.act[:hash_digests][:bool] #% --hash-digests, -N digest tree + requires('digests') # -N digests.rb + SiSU_DigestView::Source.new(@opt).read + end + if @opt.act[:txt][:bool] #% --txt, -t -a + requires('plaintext') # -t -a plaintext.rb + SiSU_Plaintext::Source.new(@opt).read + end + if @opt.act[:html][:bool] #% --html, -h + requires('html') # -h -H html.rb + SiSU_HTML::Source.new(@opt).read + end + if @opt.act[:concordance][:bool] #% --concordance, -w + requires('concordance') # -w concordance.rb + SiSU_Concordance::Source.new(@opt).read + end + if @opt.act[:epub][:bool] #% --epub, -e + requires('epub') # -e epub.rb + SiSU_EPUB::Source.new(@opt).read + end + if @opt.act[:odt][:bool] #% --odt, -o opendocument + requires('odf') # -o odf.rb + SiSU_ODF::Source.new(@opt).read + end + if @opt.act[:xhtml][:bool] #% --xhtml, -b xhtml + requires('xhtml') # -b xhtml.rb + SiSU_XHTML::Source.new(@opt).read + end + if @opt.act[:xml_sax][:bool] #% --xml-sax, -x xml sax type + requires('xml') # -x xml.rb + SiSU_XML_SAX::Source.new(@opt).read + end + if @opt.act[:xml_dom][:bool] #% --xml-dom, -x xml dom type + requires('xml_dom') # -X xml_dom.rb + SiSU_XML_DOM::Source.new(@opt).read + end + if @opt.act[:pdf][:bool] #% --pdf, -p latex/ texpdf + requires('texpdf') # -p texpdf.rb + SiSU_TeX::Source.new(@opt).read + end + if @opt.act[:manpage][:bool] #% --manpage, -i + requires('manpage') # -i manpage.rb + SiSU_Manpage::Source.new(@opt).read + end + if @opt.act[:texinfo][:bool] #% --texinfo, -I + requires('texinfo') # -I texinfo.rb + SiSU_TexInfo::Source.new(@opt).read + end + if @opt.act[:sqlite_discreet][:bool] #% --sqlite, -d DB sqlite + requires('dbi_discreet') # -d dbi_discreet.rb + SiSU_DBI_Discreet::SQL.new(@opt).build + end + if @opt.act[:manifest][:bool] #% --manifest, -y + requires('manifest') # -y manifest.rb + SiSU_Manifest::Source.new(@opt).read + end end end - if @opt.act[:qrcode][:bool] #% --qrcode, -Q - op('qrcode','QRcode') - end - if @opt.act[:hash_digests][:bool] #% --hash-digests, -N digest tree - op('digests','digests') - end - if @opt.act[:html][:bool] #% --html, -h - op('html','html') - end - if @opt.act[:txt][:bool] #% --txt, -t -a - #-A -f -e -E plaintext -a creates ms-dos type; -A creates unix type, plaintext file - op('plaintext','plaintext') - end - if @opt.act[:epub][:bool] #% --epub, -e - op('epub','ePub') - end - if @opt.act[:odt][:bool] #% --odt, -o opendocument - op('odf','OpenDocument') - end - if @opt.act[:xml_sax][:bool] #% --xml-sax, -x xml sax type - op('xml','xml sax') - end - if @opt.act[:xml_dom][:bool] #% --xml-dom, -x xml dom type - op('xml_dom','xml dom') - end - #if @opt.act[:fictionbook] #% --fictionbook, -f fictionbook xml - # op('xml_fictionbook','xml fictionbook') - #end - if @opt.act[:xhtml][:bool] #% --xhtml, -b xhtml - op('xhtml','xhtml sax') - end - if @opt.act[:images][:bool] #% --images, -j - op('shared_images','images') - end - if @opt.act[:concordance][:bool] #% --concordance, -w - op('concordance','Concordance') - end - if @opt.cmd =~/O/ #% -O open archive initiative, metadata harvesting - op('xml_md_oai_pmh_dc','OAI PMH') - end - if @opt.act[:po4a][:bool] #% --po4a, -P - op('po4a','po4a') - end - if @opt.act[:git][:bool] #% --git, -g sisu git - op('git','SiSU Git') - end - if @opt.cmd =~/T/ #% -T termsheet/standard form - SiSU_Help::Help.new('termsheet').help_request - @opt.files.each do |fns| - if FileTest.file?(fns) - @opt.fns=fns - case @opt.fns - when /\.(termsheet.rb)$/ - SiSU::Operations.new(@opt).termsheet - else #print "not processed --> ", fns, "\n" + def loop_files_on_given_option_do + if @opt.act[:images][:bool] #% --images, -j + OptionLoopFiles.new(@opt).loop_files_on_given_option do + requires('shared_images') + SiSU_Images::Source.new(@opt).read # -j shared_images.rb + end + end + if @opt.cmd =~/O/ #% -O open archive initiative, metadata harvesting + op('xml_md_oai_pmh_dc','OAI PMH') + end + if @opt.act[:po4a][:bool] #% --po4a, -P + OptionLoopFiles.new(@opt).loop_files_on_given_option do + requires('po4a') + SiSU_Po4a::Source.new(@opt).read # -P po4a.rb + end + end + if @opt.act[:git][:bool] #% --git, -g sisu git + OptionLoopFiles.new(@opt).loop_files_on_given_option do + #requires('git') + #fix + end + end + if @opt.cmd =~/T/ #% -T termsheet/standard form + SiSU_Help::Help.new('termsheet').help_request + @opt.files.each do |fns| + if FileTest.file?(fns) + @opt.fns=fns + case @opt.fns + when /\.(termsheet.rb)$/ + SiSU::Operations.new(@opt).termsheet + else #print "not processed --> ", fns, "\n" + end + else SiSU::Operations.new(@opt).not_found end - else SiSU::Operations.new(@opt).not_found end + SiSU::Operations.new.counter end - SiSU::Operations.new.counter - end - if @opt.cmd =~/k/ #% -T temporary tests - op('xml_scaffold','XML scaffold') - end - if @opt.act[:pdf][:bool] #% --pdf, -p latex/ texpdf - op('texpdf','LaTeX pdf') - end - if @opt.act[:manpage][:bool] #% --manpage, -i - op('manpage','manpage') - end - if @opt.act[:texinfo][:bool] #% --texinfo, -I - op('texinfo','TeX Info') - end - if @opt.act[:psql][:bool] #% --pg, -D DB postgresql - op('dbi','postgresql') - end - if @opt.act[:sqlite_discreet][:bool] #% --sqlite, -d DB sqlite - op('dbi_discreet','sqlite') - end - if @opt.act[:sqlite][:bool] #% --sqlite, -d DB sqlite - op('dbi','sqlite') - end - if @opt.act[:dal][:bool] #% --dal, -m embedded content - op('embedded','Embedded Content') - end - if @opt.act[:manifest][:bool] #% --manifest, -y - op('manifest','Manifest') - end - if @opt.act[:sitemap][:bool] #% --sitemap, -Y - op('sitemaps','Sitemap') - end - if @opt.mod.inspect !~/--harvest/ - if @opt.act[:scp][:bool] #% -r copy to remote server - op('remote','scp') + if @opt.cmd =~/k/ #% -T temporary tests + OptionLoopFiles.new(@opt).loop_files_on_given_option do + #requires('xml_scaffold') + #fix + end end - if @opt.act[:rsync][:bool] #% -R copy to remote server - op('remote','rsync') + if @opt.act[:psql][:bool] #% --pg, -D DB postgresql + op('dbi','postgresql') end - else + if @opt.act[:sqlite][:bool] #% --sqlite, -d DB sqlite + op('dbi','sqlite') + end + if @opt.act[:manifest][:bool] #% --manifest, -y + OptionLoopFiles.new(@opt).manifest_on_files_translated do + requires('manifest') + SiSU_Manifest::Source.new(@opt).read # -y manifest.rb + end + end + if @opt.act[:sitemap][:bool] #% --sitemap, -Y + OptionLoopFiles.new(@opt).loop_files_on_given_option do + requires('sitemaps') + SiSU_Sitemaps::Source.new(@opt).read # -Y sitemaps.rb + end + end + if @opt.mod.inspect !~/--harvest/ + if @opt.act[:scp][:bool] #% -r copy to remote server + op('remote','scp') + end + if @opt.act[:rsync][:bool] #% -R copy to remote server + op('remote','rsync') + end + else + end + op('urls','urls') + end + #if @opt.mod=~/^conf$/ # -C + if @opt.cmd=~/C/ # -C + requires('conf') # -s conf.rb + SiSU_Initialize::Source.new(@opt).read end - op('urls','urls') + each_file_loop_options + loop_files_on_given_option_do @msg,@msgs="\tsisu -W [to start ruby web-server on output directory]\n",nil unless @opt.cmd =~/q/ @tell.call.print_brown if @opt.cmd =~/[uUvVM]/ unless @opt.files.join.empty? if defined? @@env.processing_path.processing \ diff --git a/lib/sisu/v3/options.rb b/lib/sisu/v3/options.rb index 3db80231..0876604d 100644 --- a/lib/sisu/v3/options.rb +++ b/lib/sisu/v3/options.rb @@ -62,10 +62,10 @@ module SiSU_Commandline require_relative 'sysenv' # sysenv.rb @@base_path=nil class Options - attr_accessor :cmd,:mod,:act,:dir_structure_by,:f_pths,:files,:base_path,:base_stub,:sub_location,:paths,:lngs,:f_pth,:pth,:fns,:fnb,:fnc,:fncb,:lng,:lng_base,:what + attr_accessor :cmd,:mod,:act,:dir_structure_by,:f_pths,:files,:files_mod,:base_path,:base_stub,:sub_location,:paths,:lngs,:f_pth,:pth,:fno,:fns,:fnb,:fnc,:fncb,:lng,:lng_base,:what def initialize(a) - @cmd,@f_pth,@pth,@fns,@fnb,@fnc,@fncb,@what,@lng,@lng_base,@base_path,@base_stub,@sub_location='','','','','','','','','','','','','' - @f_pths,@files,@paths,@mod,@act=Array.new(5){[]} + @cmd,@f_pth,@pth,@fno,@fns,@fnb,@fnc,@fncb,@what,@lng,@lng_base,@base_path,@base_stub,@sub_location='','','','','','','','','','','','','','' + @f_pths,@files,@files_mod,@paths,@mod,@act=Array.new(5){[]} @env=SiSU_Env::InfoEnv.new @lng_base=@env.language_default_set @dir_structure_by=SiSU_Env::EnvCall.new.output_dir_structure.by? @@ -448,6 +448,14 @@ module SiSU_Commandline else { bool: false, set: :na, inst: '' } end + act[:processing_path]=if mod.inspect =~/"--processing-path=/ + base_pth=mod.join(';').gsub(/^.*--processing-path=['"]?(.+?)(?:['"]?;.+)?$/,'\1') + { bool: true, set: :on, inst: base_pth } + elsif mod.inspect =~/"--processing-path/ + { bool: true, set: :on, inst: @base_path } + else + { bool: false, set: :na, inst: nil } + end act[:dump]=if mod.inspect =~/"--dump=/ base_pth=mod.join(';').gsub(/^.*--dump=['"]?(.+?)(?:['"]?;.+)?$/,'\1') { bool: true, set: :on, inst: base_pth } @@ -753,6 +761,11 @@ module SiSU_Commandline def act @act end + def files_mod + files_mod=files + @files_mod=files_mod + @files_mod + end def f_pth @f_pth end @@ -768,6 +781,9 @@ module SiSU_Commandline def lng_base @lng_base end + def fno + @fno + end def fns @fns end @@ -780,12 +796,14 @@ module SiSU_Commandline end end def fnc - @fnc=if @fns =~/\.(?:ssm\.sst|ssm)$/; fnb + '.ssm.sst' + @fnc=if @fns =~/\.(?:ssm\.sst|ssm)$/ + fnb + '.ssm.sst' else @fns end end def fncb - @fncb=if @fns =~/(?:\~\S{2,3})?\.(?:ssm\.sst|ssm)$/; fnb + '.ssm.sst' + @fncb=if @fns =~/(?:\~\S{2,3})?\.(?:ssm\.sst|ssm)$/ + fnb + '.ssm.sst' else @fns.gsub(/(?:\~\S{2,3})?(\.sst)$/,'\1') end end -- cgit v1.2.3