From 0081730547d53f86744f61f772657c34e8c5149b Mon Sep 17 00:00:00 2001
From: Ralph Amissah <ralph@amissah.com>
Date: Sat, 24 Sep 2011 08:12:12 -0400
Subject: v3: remote, src & sisupod processing, and rsync placement

---
 data/doc/sisu/CHANGELOG_v3  |  7 ++++-
 lib/sisu/v3/composite.rb    |  8 +++--
 lib/sisu/v3/hub.rb          | 50 +++++++++++++++++--------------
 lib/sisu/v3/options.rb      | 64 +++++++++++++++++++++++++++++++++-------
 lib/sisu/v3/remote.rb       |  4 ++-
 lib/sisu/v3/sisupod_make.rb | 17 -----------
 lib/sisu/v3/sysenv.rb       | 71 ++++++++++++++++++++++++++++-----------------
 7 files changed, 140 insertions(+), 81 deletions(-)

diff --git a/data/doc/sisu/CHANGELOG_v3 b/data/doc/sisu/CHANGELOG_v3
index 042de0c6..abb354d3 100644
--- a/data/doc/sisu/CHANGELOG_v3
+++ b/data/doc/sisu/CHANGELOG_v3
@@ -29,7 +29,12 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_3.0.19.orig.tar.xz
 
   * texinfo, fix output
 
-  * remote, include manpage & info file (when selected)
+  * remote
+    * rsync, include manpage, info file (when selected)
+    * rsync, images, (html, xmls) only include images related to document
+    * src & sisupod processing
+
+  * sisupod processing
 
   * param, matching of date, years 1400 - 21\d\d
 
diff --git a/lib/sisu/v3/composite.rb b/lib/sisu/v3/composite.rb
index 33c15cc0..b269cc39 100644
--- a/lib/sisu/v3/composite.rb
+++ b/lib/sisu/v3/composite.rb
@@ -70,10 +70,11 @@ module SiSU_Assemble
       images[0]=dir
       images
     end
-    def download_images(download_from,images_array)
+    def download_images(images_info)
       path="#{@env.processing_path.processing}/external_document/image"
       mkdir_p(path) unless FileTest.directory?(path)
-      images_array.each do |i|
+      download_from=images_info.shift
+      images_info.each do |i|
         image="#{path}/#{i}"
         imagefile=File.new(image,'w+')
         open("#{download_from}/#{i}") do |g|
@@ -226,7 +227,8 @@ module SiSU_Assemble
         @@imager.each do |d,i|
           i.flatten!
           i.uniq!
-          download_images(d,i)
+          image_info=d + i
+          download_images(mage_info.flatten)
         end
       end
       tuned_file
diff --git a/lib/sisu/v3/hub.rb b/lib/sisu/v3/hub.rb
index 8bd1cb7a..584845ba 100644
--- a/lib/sisu/v3/hub.rb
+++ b/lib/sisu/v3/hub.rb
@@ -156,11 +156,20 @@ module SiSU
             break
           else
             put=fns.gsub(/(.+)?\.ssm\.sst$/,'\1.ssm')
-            @opt.fns=fns
-            @opt.pth=@opt.paths[i]
-            @opt.f_pth=@opt.f_pths[i]
-            @opt.lng=@opt.lngs[i]
-            @@pwd=@opt.pth
+            if fns !~/\.-sst$/
+              @opt.fns=fns
+              @opt.pth=@opt.paths[i]
+              @opt.f_pth=@opt.f_pths[i]
+              @opt.lng=@opt.lngs[i]
+              @@pwd=@opt.pth
+            else
+              @opt.fns=fns
+              @opt.pth=Dir.pwd
+              @opt.f_pth=@opt.f_pths[i] #@opt.f_pth= { pth: Dir.pwd }
+              @opt.lng='en'
+              #@opt.lng=@opt.lngs[i]
+              @@pwd=@opt.pth
+            end
             Dir.chdir(@opt.pth) #watch
             env=SiSU_Env::Info_env.new(fns)
             if @req !~/(?:urls|remote)$/
@@ -427,12 +436,12 @@ p "here #{__FILE__} #{__LINE__}" if @opt =~/M/
             path_image='./_sisu/processing/external_document/image'
             path_skin='./_sisu/processing/external_document/skin/doc'
             @get_s,@get_p,@get_pl=[],[],[]
-            re_s=/((?:https?|file):\/\/\S+?\.sst)$/
+            re_s=/(\S+?\.-sst)$/
             re_p3=/((?:https?|file):\/\/\S+?(?:\/\S+?\.ss[mt]\.txz|sisupod(?:\.txz)?|\.ssp))/
             re_pl3=/^(\/\S+?\.ss[mt]\.txz)/
             @opt.files.each do |fns|
               if fns =~re_s
-                @get_s << re_s.match(fns)[1] if re_s
+                @get_s << @opt.f_pths[0][:url]
               end
               if fns =~re_p3
                 @get_p << re_p3.match(fns)[1] if re_p3
@@ -441,21 +450,18 @@ p "here #{__FILE__} #{__LINE__}" if @opt =~/M/
                 @get_pl << re_pl3.match(fns)[1] if re_p3
               end
             end
-            re_p2=/((?:https?|file):\/\/\S+?(?:\/\S+?\.ss[mt]\.zip|sisupod(?:\.zip)?|\.ssp))/
-            re_pl2=/^(\/\S+?\.ss[mt]\.zip)/
-            @opt.files.each do |fns|
-              if fns =~re_s
-                @get_s << re_s.match(fns)[1] if re_s
-              end
-              if fns =~re_p2
-                @get_p << re_p2.match(fns)[1] if re_p2
-              end
-              if fns =~re_pl2
-                @get_pl << re_pl2.match(fns)[1] if re_p2
-              end
-            end
-            if @get_s.length > 0                           #% remote markup file .sst
-              require_relative 'remote'                 # remote.rb
+           #re_p2=/((?:https?|file):\/\/\S+?(?:\/\S+?\.ss[mt]\.zip|sisupod(?:\.zip)?|\.ssp))/
+           #re_pl2=/^(\/\S+?\.ss[mt]\.zip)/
+           #@opt.files.each do |fns|
+           #  if fns =~re_p2
+           #    @get_p << re_p2.match(fns)[1] if re_p2
+           #  end
+           #  if fns =~re_pl2
+           #    @get_pl << re_pl2.match(fns)[1] if re_p2
+           #  end
+           #end
+            if @get_s.length > 0                                               #% remote markup file .sst
+              require_relative 'remote'                                        # remote.rb
               SiSU_Remote::Get.new(@opt,@get_s).fns
               Operations.new.counter
             end
diff --git a/lib/sisu/v3/options.rb b/lib/sisu/v3/options.rb
index eeca31ec..ffd0da0f 100644
--- a/lib/sisu/v3/options.rb
+++ b/lib/sisu/v3/options.rb
@@ -192,6 +192,7 @@ module SiSU_commandline
       c,w='',''
       m,f,pth,z,lng,lngs=[],[],[],[],[],[]
       a=s.split(/\s+/)
+      r_l=Px[:lng_lst].join('|')
       a.uniq.each do |x|
         if x =~/^-[a-z0-5]+/i \
         or x =~/^--\S+/
@@ -203,8 +204,51 @@ module SiSU_commandline
           end
         elsif x =~ /(?:\.(?:(?:-|ssm\.)?sst(?:\.xml)?|ssm|ssi|sx[sdn]\.xml|s[1-3]|kdi|ssp)|\S+?\.ss[mt]\.(?:txz|zip)|sisupod\.(?:txz|zip))$/
           if x =~/^(?:https?|file):\/\/\S+/ \
-          or x =~/\S+?\.ss[mt]\.(?:txz|zip)|sisupod\.(?:txz|zip)/ \
-          && FileTest.file?(x)
+          and x =~/\S+?\.ss[mt]$/
+            r_url=/(http:\/\/\S+?\/\S+?\/src(?:\/(?:#{r_l}))?)\//
+            url_base = (x[r_url,1])
+            url = x
+            y=x.gsub(/http:\/\/\S+?\/\S+?\/src\//,'')
+            t=/(#{r_l})\/[^\/]+?\.ss[tm]$/
+            l_p = (y[t,1]) \
+              ? y[t,1]
+              : nil
+            lng << l_p
+            lngs << if l_p
+              l_p
+            elsif x =~/~(#{r_l})\.ss[tm]/
+              $1
+            else lng_base
+            end
+            r_f=/(?:#{r_l})\/([^\/]+?\.ss[tm])$/
+            fn = (y[r_f,1]) \
+              ? y[r_f,1]
+              : y
+            fn.gsub!(/\.((?:ssm\.)?sst)/,'.-\1')
+            fullname=Dir.pwd + '/' + fn
+            pt=Pathname.new(fullname)
+            pth << Dir.pwd
+            r_u=/.+?\/([^\/]+)(?:\/(?:#{r_l})$|$)/
+            lng_is =if l_p
+              l_p
+            elsif x =~/~(#{r_l})\.ss[tm]/
+              $1
+            else lng_base
+            end
+            f_pths << {
+              pth: pt.split[0].realpath.to_s,
+              f: pt.split[1].to_s,
+              pth_stub: pt.split[0].realpath.to_s[r_u,1],
+              lng: (pt.split[0].realpath.to_s[t,1]) \
+                ? pt.split[0].realpath.to_s[t,1]
+                : nil,
+              lng_is: lng_is,
+              url_base: url_base,
+              url: url
+            }
+            f << fn
+          elsif x =~/^(?:https?|file):\/\/\S+/ \
+          and x =~/\S+?\.ss[mt]\.(?:txz|zip)|sisupod\.(?:txz|zip)/
             x=x.gsub(/^file:\/\//,'')
             f << x
           elsif FileTest.file?(x)
@@ -212,34 +256,34 @@ module SiSU_commandline
             pt=Pathname.new(x)
             pth << pt.split[0].realpath.to_s     #remove?
             f << pt.split[1].to_s                #remove?
-            r=Px[:lng_lst].join('|')
-            u=/.+?\/([^\/]+)(?:\/(?:#{r})$|$)/
-            t=/.+\/(#{r})$/
+            r_u=/.+?\/([^\/]+)(?:\/(?:#{r_l})$|$)/
+            t=/.+\/(#{r_l})$/
             l_p = (pt.split[0].realpath.to_s[t,1]) \
               ? pt.split[0].realpath.to_s[t,1]
               : nil
-              #: ''
             lng << l_p
             lngs << if l_p
               l_p
-            elsif x =~/~(#{r})\.ss[tm]/
+            elsif x =~/~(#{r_l})\.ss[tm]/
               $1
             else lng_base
             end
             lng_is =if l_p
               l_p
-            elsif x =~/~(#{r})\.ss[tm]/
+            elsif x =~/~(#{r_l})\.ss[tm]/
               $1
             else lng_base
             end
             f_pths << {
               pth: pt.split[0].realpath.to_s,
               f: pt.split[1].to_s,
-              pth_stub: pt.split[0].realpath.to_s[u,1],
+              pth_stub: pt.split[0].realpath.to_s[r_u,1],
               lng: (pt.split[0].realpath.to_s[t,1]) \
                 ? pt.split[0].realpath.to_s[t,1]
                 : nil,
-              lng_is: lng_is
+              lng_is: lng_is,
+              url_base: nil,
+              url: nil
             }
 #           Dir.chdir(pt.split[0].realpath)
           else  puts "file not found: #{x}"
diff --git a/lib/sisu/v3/remote.rb b/lib/sisu/v3/remote.rb
index a3b9a62e..2e055707 100644
--- a/lib/sisu/v3/remote.rb
+++ b/lib/sisu/v3/remote.rb
@@ -149,7 +149,9 @@ module SiSU_Remote
               images.sort!
               @msg,@msgs='downloading images:', [ images.join(',') ]
               @tell.call.warn unless @opt.cmd =~/q/
-              SiSU_Assemble::Remote_image.new.download_images(image_download_url,images)
+              image_info=image_download_url + images
+              SiSU_Assemble::Remote_image.new.download_images(image_info)
+              #SiSU_Assemble::Remote_image.new.download_images(image_download_url,images)
               @msg,@msgs='downloading done',nil
               @tell.call.warn unless @opt.cmd =~/q/
             end
diff --git a/lib/sisu/v3/sisupod_make.rb b/lib/sisu/v3/sisupod_make.rb
index dd6c89c2..e2ac4f51 100644
--- a/lib/sisu/v3/sisupod_make.rb
+++ b/lib/sisu/v3/sisupod_make.rb
@@ -303,23 +303,6 @@ module SiSU_Doc
         SiSU_Screen::Ansi.new('',"#{@opt.fns}.txz not built").blue_tab
       end
     end
-    def sisupod_zip
-      mkdir_p(@file.output_path.sisupod.dir) unless FileTest.directory?(@file.output_path.sisupod.dir)
-      if FileTest.directory?(@env.processing_path.processing)
-        Dir.chdir(@env.processing_path.processing)
-        system(%{
-          echo "SiSU sisupod #{@ver[:version]}" > sisu_zip.txt
-          zip -qz #{@zipfile}.zip sisu_zip.txt < sisu_zip.txt
-          zip -qr #{@zipfile}.zip sisupod
-          mv #{@zipfile}.zip #{@file.place_file.sisupod.dir} &
-          rm -r sisupod/*
-        })
-        Dir.chdir(@env.path.pwd)
-        SiSU_Screen::Ansi.new('',"#{@zipfile}.zip").blue_tab if @opt.cmd =~/[MVv]/
-      else
-        SiSU_Screen::Ansi.new('',"#{@zipfile}.zip not built").blue_tab
-      end
-    end
   end
 end
 __END__
diff --git a/lib/sisu/v3/sysenv.rb b/lib/sisu/v3/sysenv.rb
index b5a10614..ed2d74dc 100644
--- a/lib/sisu/v3/sysenv.rb
+++ b/lib/sisu/v3/sysenv.rb
@@ -808,7 +808,8 @@ module SiSU_Env
         end
         msg=''
         msg=" && echo 'OK: #{@input} -> #{@output}'" unless @cmd =~/q/
-        puts "rsync -az#{vb} #{action} #{@input} #{@output}" if @cmd =~/[vVM]/
+        rsync_cmd="rsync -az#{vb} #{action} #{@input} #{@output}"
+        puts rsync_cmd if @cmd =~/[vVM]/
         dir_change,dir_return='',''
         if chdir \
         && chdir != Dir.pwd
@@ -817,7 +818,7 @@ module SiSU_Env
         end
         dir_change
         system("
-          rsync -az#{vb} #{action} #{@input} #{@output} #{msg}
+          #{rsync_cmd} #{msg}
         ")
         dir_return
       else puts "\tWARN: #{program} not found"
@@ -2952,8 +2953,8 @@ WOK
       def document
         self.remote_host_base.each do |remote_conn|
           local_gen=@source_path
-          local_gen_image="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image"
-          local_gen_image_external="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image_external"
+          #local_gen_image="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image"
+          #local_gen_image_external="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image_external"
           remote_gen="#{remote_conn[:name]}/#{@env.path.stub_pwd}/."
           remote_rel=remote_conn[:name] + '/' + @f.output_path.stub.rcp
           src_txt=@opt.fnc
@@ -2966,66 +2967,82 @@ WOK
 #           System_call.new("#{local_src}/#{src_txt}",remote_src,@opt.cmd).rsync
             delete_extra_files='--delete' # '--delete-after'
             inp=[]
-            if @opt.cmd =~/h/ \
+            if (@opt.cmd =~/h/ \
+            || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
             && FileTest.file?(@f.place_file.html_scroll.dir)
               inp << @f.output_path.html_seg.rel << @f.place_file.html_scroll.rel
             end
-            if @opt.cmd =~/w/ \
+            if (@opt.cmd =~/w/ \
+            || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
             && FileTest.file?(@f.place_file.html_concordance.dir)
               inp << @f.place_file.html_concordance.rel
             end
-            if @opt.cmd =~/e/ \
+            if (@opt.cmd =~/e/ \
+            || @opt.cmd =~/^-R[mqvVM]*$/) \
             && FileTest.file?(@f.place_file.epub.dir)
               inp << @f.place_file.epub.rel
             end
-            if @opt.cmd =~/o/ \
+            if (@opt.cmd =~/o/ \
+            || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
             && FileTest.file?(@f.place_file.odt.dir)
               inp << @f.place_file.odt.rel
             end
-            if @opt.cmd =~/b/ \
+            if (@opt.cmd =~/b/ \
+            || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
             && FileTest.file?(@f.place_file.xhtml.dir)
               inp << @f.place_file.xhtml.rel
             end
-            if @opt.cmd =~/x/ \
+            if (@opt.cmd =~/x/ \
+            || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
             && FileTest.file?(@f.place_file.xml_sax.dir)
               inp << @f.place_file.xml_sax.rel
             end
-            if @opt.cmd =~/X/ \
+            if (@opt.cmd =~/X/ \
+            || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
             && FileTest.file?(@f.place_file.xml_dom.dir)
               inp << @f.place_file.xml_dom.rel
             end
-            if @opt.cmd =~/[at]/ \
+            if (@opt.cmd =~/[at]/ \
+            || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
             && FileTest.file?(@f.place_file.txt.dir)
               inp << @f.place_file.txt.rel
             end
-            if @opt.cmd =~/i/ \
+            if (@opt.cmd =~/i/ \
+            || @opt.cmd =~/^-[mqvVM]*i[mqvVM]*$/) \
             && FileTest.file?(@f.place_file.manpage.dir)
               inp << @f.place_file.manpage.rel
             end
-            if @opt.cmd =~/I/ \
+            if (@opt.cmd =~/I/ \
+            || @opt.cmd =~/^-[mqvVM]*I[mqvVM]*$/) \
             && FileTest.file?(@f.place_file.info.dir)
               inp << @f.place_file.info.rel
             end
-            if @opt.cmd =~/N/ \
+            if (@opt.cmd =~/N/ \
+            || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
             && FileTest.file?(@f.place_file.hash_digest.dir)
               inp << @f.place_file.hash_digest.rel
             end
-            if @opt.cmd =~/s/ \
+            if (@opt.cmd =~/s/ \
+            || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
             && FileTest.file?(@f.place_file.src.dir)
               inp << @f.place_file.src.rel
             end
-            if @opt.cmd =~/S/ \
+            if (@opt.cmd =~/S/ \
+            || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
             && FileTest.file?(@f.place_file.sisupod.dir)
               inp << @f.place_file.sisupod.rel
             end
-            if @opt.cmd =~/p/
+            if (@opt.cmd =~/p/ \
+            || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/)
               inp << @f.output_path.pdf.rel + '/' + @opt.fnb + '*'
             end
-            if @opt.cmd =~/Q/ \
+            if (@opt.cmd =~/Q/ \
+            || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
             && FileTest.file?(@f.place_file.qrcode_md.dir)
               inp << @f.place_file.qrcode_md.rel << @f.place_file.qrcode_title.rel
             end
-            if @opt.cmd =~/y/ \
+            if (@opt.cmd =~/y/ \
+            || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
             && FileTest.file?(@f.place_file.manifest.dir)
               inp << @f.place_file.manifest.rel
             end
@@ -3034,19 +3051,19 @@ WOK
             else ''
             end
             local_css,images,images_external,images_system='','','',''
+            images_gen=images=images_skin=images_system=local_css=''
             if @opt.cmd =~/[hwbxX]/ \
-            and defined? @md.ec[:image] \
-            and not @md.ec[:image].empty?
+            && (defined? @md.ec[:image]) \
+            && (@md.ec[:image].length > 0)
               images=@f.place_file.images.rel + '/' + @md.ec[:image].join(" #{@f.output_path.images.rel}/")
-              images_external="#{local_gen_image_external}/" + @md.ec[:image].join(" #{local_gen_image_external}/")
             end
-            images_gen=images=images_skin=images_system=local_css=''
             if @opt.cmd =~/[yhwbxX]/ \
-            and defined? @md.ec[:image] \
-            and not @md.ec[:image].empty?
+            && (defined? @md.ec[:image]) \
+            && (@md.ec[:image].length > 0)
               local_css=@f.output_path.css.rel
               images_system='_sisu/image_sys'
-              if @f.output_path.images.rel.length > 0
+              if @f.output_path.images.rel.length > 0 \
+              && images_from_skin.length > 0
                 images_skin=@f.place_file.images.rel + '/' + images_from_skin.join(" #{@f.output_path.images.rel}/")
               end
             end
-- 
cgit v1.2.3