From cfe3d294a03935ae807c6c3b313b4e7dc4a241f4 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Thu, 1 Nov 2007 02:15:50 +0000 Subject: generate from remote markup source, image path fix and some cosmetic re-arrangement --- lib/sisu/v0/composite.rb | 15 ++++----- lib/sisu/v0/db_import.rb | 87 ++++++++++++++++++++++++------------------------ lib/sisu/v0/dbi.rb | 4 +-- lib/sisu/v0/hub.rb | 68 ++++++++++++++++++++++--------------- lib/sisu/v0/remote.rb | 5 +-- 5 files changed, 95 insertions(+), 84 deletions(-) (limited to 'lib') diff --git a/lib/sisu/v0/composite.rb b/lib/sisu/v0/composite.rb index 4366b3ef..3e4e7d0d 100644 --- a/lib/sisu/v0/composite.rb +++ b/lib/sisu/v0/composite.rb @@ -66,19 +66,16 @@ module SiSU_Assemble images[0]=dir images end - def download_images(images_array) #first element in array is source url + def download_images(download_from,images_array) path="#{@env.path.processing}/external_document/image" File.mkpath(path) unless FileTest.directory?(path) - download_from=images_array.shift images_array.each do |i| image="#{path}/#{i}" - #unless FileTest.exists?(image) - imagefile=File.new(image,'w+') - open("#{download_from}/#{i}") do |g| - imagefile << g.read - end - imagefile.close - #end + imagefile=File.new(image,'w+') + open("#{download_from}/#{i}") do |g| + imagefile << g.read + end + imagefile.close end end def download_doc_skin(doc_skin) #first element in array is source url diff --git a/lib/sisu/v0/db_import.rb b/lib/sisu/v0/db_import.rb index 631c3209..4dc360f8 100644 --- a/lib/sisu/v0/db_import.rb +++ b/lib/sisu/v0/db_import.rb @@ -77,8 +77,7 @@ module SiSU_DB_import end @suffix=@opt.fns[/(?:.+?)(?:\.ssm\.sst|\.-?sst)/,1] @fnm="#@dal/#{@opt.fns}.meta.rbm" - @@seg='' - @@seg_full='' #create? consider placing field just before clean text as opposed to seg which contains seg(.html) name info seg_full would contain seg info for levels 5 & 6 where available eg seg_full may be 7.3 (level 5) and 7.3.1 (level 6) where seg is 7 + @@seg,@@seg_full='','' #create? consider placing field just before clean text as opposed to seg which contains seg(.html) name info seg_full would contain seg info for levels 5 & 6 where available eg seg_full may be 7.3 (level 5) and 7.3.1 (level 6) where seg is 7 @col=Hash.new('') @col[:ocn]='' @counter={} @@ -100,18 +99,18 @@ module SiSU_DB_import tell=SiSU_Screen::Ansi.new(@opt.cmd,'Marshal Load',@fnm) tell.print_grey if @opt.cmd =~/v/ case @sql_type - when /sqlite/ #fix logic for sqlite ! + when /sqlite/ #fix logic for sqlite ! import_db_metadata(@dal_array) import_documents(@dal_array) - import_db_urls(@dal_array,@fnm) #import OID on/off - @conn.commit #sqlite watch + import_db_urls(@dal_array,@fnm) #import OID on/off + @conn.commit #sqlite watch else file_exist=@conn.select_one(%{ SELECT metadata.tid FROM metadata WHERE metadata.filename ~ '#{@opt.fns}'; }) unless file_exist @conn.execute('BEGIN') import_db_metadata(@dal_array) import_documents(@dal_array) - import_db_urls(@dal_array,@fnm) #import OID on/off + import_db_urls(@dal_array,@fnm) #import OID on/off @conn.execute('COMMIT') else @db=SiSU_Env::Info_db.new @@ -337,12 +336,12 @@ module SiSU_DB_import # #id,info='Generated by',"#{@md.sisu_version[:project]} #{@md.sisu_version[:version]} #{@md.sisu_version[:date_stamp]} (#{@md.sisu_version[:date]})" #end #if @md.ruby_version; special_character_escape(@md.ruby_version) - SiSU_DB_DBI::Test.new(self,@opt).verify #% import title names, filenames (tuple) + SiSU_DB_DBI::Test.new(self,@opt).verify #% import title names, filenames (tuple) t=SiSU_DB_tuple::Load_metadata.new(@conn,@tp,@@id_t) t.tuple end - def import_documents(dbi_unit) #% import documents - populate main database table - #% import into substantive database tables (tuple) + def import_documents(dbi_unit) #% import documents - populate main database table + #% import into substantive database tables (tuple) begin @col[:tid]=@@id_t @en,@en_ast,@en_pls=[],[],[] @@ -502,7 +501,7 @@ module SiSU_DB_import t=SiSU_DB_tuple::Load_documents.new(@conn,@col,@opt) t.tuple @col[:lev]=@col[:plaintext]=@col[:body]='' - else #% regular text + else #% regular text @col[:lid]+=1 txt='' txt,@col[:ocn],@col[:ocnd],@col[:ocns],@col[:digest_clean],@col[:digest_all]=(/(.+?)<~(\d+);((?:\w|[0-6]:)\d+);(\w\d+)><([0-9a-f]{#{@@dl}}):([0-9a-f]{#{@@dl}})>/m).match(data).captures @@ -555,11 +554,11 @@ module SiSU_DB_import @col[:en_a]=@col[:en_z]=nil @col[:lev]=@col[:plaintext]=@col[:body]='' end - if notedata =~ /~\{.+?\}~/ #% import into database endnotes tables + if notedata =~ /~\{.+?\}~/ #% import into database endnotes tables endnote_array=notedata.scan(/~\{.+?\}~/) endnote_array.each do |inf| - if inf[/~\{\d+.+?<[0-9a-f]{#{@@dl}}>\}~/] # dal new endnotes 2003w31/1 - if inf[/~\{(\d+)(.+?)<([0-9a-f]{#{@@dl}})>\}~/] # dal new endnotes 2003w31/1 + if inf[/~\{\d+.+?<[0-9a-f]{#{@@dl}}>\}~/] # dal new endnotes 2003w31/1 + if inf[/~\{(\d+)(.+?)<([0-9a-f]{#{@@dl}})>\}~/] # dal new endnotes 2003w31/1 nr,txt,digest_clean=$1,$2,$3 end @id_n+=1 @@ -576,17 +575,17 @@ module SiSU_DB_import end if txt en={} - en={ :type => 'endnotes', - :id => @id_n, - :lid => @col[:lid], - :nr => nr, - :txt => txt, - :body => body, - :ocn => @col[:ocn], - :ocnd => @col[:ocnd], - :ocns => @col[:ocns], - :id_t => @@id_t, - :hash => digest_clean + en={ :type => 'endnotes', + :id => @id_n, + :lid => @col[:lid], + :nr => nr, + :txt => txt, + :body => body, + :ocn => @col[:ocn], + :ocnd => @col[:ocnd], + :ocns => @col[:ocns], + :id_t => @@id_t, + :hash => digest_clean } t=SiSU_DB_tuple::Load_endnotes.new(@conn,en) t.tuple @@ -595,11 +594,11 @@ module SiSU_DB_import end word_mode=notedata.scan(/\S+/) end - if notedata =~ /~\[\*.+?\]~/ #% import into database endnotes tables + if notedata =~ /~\[\*.+?\]~/ #% import into database endnotes tables endnote_array=notedata.scan(/~\[\*.+?\]~/) endnote_array.each do |inf| - if inf[/~\[\*\d+.+?<[0-9a-f]{#{@@dl}}>\]~/] # dal new endnotes 2003w31/1 - if inf[/~\[[*](\d+)(.+?)<([0-9a-f]{#{@@dl}})>\]~/] # dal new endnotes 2003w31/1 + if inf[/~\[\*\d+.+?<[0-9a-f]{#{@@dl}}>\]~/] # dal new endnotes 2003w31/1 + if inf[/~\[[*](\d+)(.+?)<([0-9a-f]{#{@@dl}})>\]~/] # dal new endnotes 2003w31/1 nr,txt,digest_clean=$1,$2,$3 end @id_n+=1 @@ -624,10 +623,10 @@ module SiSU_DB_import :txt => txt, :body => body, :ocn => @col[:ocn], - :ocnd => @col[:ocnd], - :ocns => @col[:ocns], - :id_t => @@id_t, - :hash => digest_clean + :ocnd => @col[:ocnd], + :ocns => @col[:ocns], + :id_t => @@id_t, + :hash => digest_clean } t=SiSU_DB_tuple::Load_endnotes.new(@conn,en) t.tuple @@ -639,8 +638,8 @@ module SiSU_DB_import if notedata =~ /~\[\+.+?\]~/ #% import into database endnotes tables endnote_array=notedata.scan(/~\[\+.+?\]~/) endnote_array.each do |inf| - if inf[/~\[\+\d+.+?<[0-9a-f]{#{@@dl}}>\]~/] # dal new endnotes 2003w31/1 - if inf[/~\[[+](\d+)(.+?)<([0-9a-f]{#{@@dl}})>\]~/] # dal new endnotes 2003w31/1 + if inf[/~\[\+\d+.+?<[0-9a-f]{#{@@dl}}>\]~/] # dal new endnotes 2003w31/1 + if inf[/~\[[+](\d+)(.+?)<([0-9a-f]{#{@@dl}})>\]~/] # dal new endnotes 2003w31/1 nr,txt,digest_clean=$1,$2,$3 end @id_n+=1 @@ -657,17 +656,17 @@ module SiSU_DB_import end if txt en={} - en={ :type => 'endnotes_plus', - :id => @id_n, - :lid => @col[:lid], - :nr => nr, - :txt => txt, - :body => body, - :ocn => @col[:ocn], - :ocnd => @col[:ocnd], - :ocns => @col[:ocns], - :id_t => @@id_t, - :hash => digest_clean + en={ :type => 'endnotes_plus', + :id => @id_n, + :lid => @col[:lid], + :nr => nr, + :txt => txt, + :body => body, + :ocn => @col[:ocn], + :ocnd => @col[:ocnd], + :ocns => @col[:ocns], + :id_t => @@id_t, + :hash => digest_clean } t=SiSU_DB_tuple::Load_endnotes.new(@conn,en) t.tuple diff --git a/lib/sisu/v0/dbi.rb b/lib/sisu/v0/dbi.rb index d9f73989..342b49b2 100644 --- a/lib/sisu/v0/dbi.rb +++ b/lib/sisu/v0/dbi.rb @@ -120,7 +120,8 @@ module SiSU_DBI tell.dbi_title unless @opt.cmd =~/q/ begin SiSU_DB_DBI::Case.new(@opt,@conn,@sql_type).cases - rescue; SiSU_Errors::Info_error.new($!,$@,@cf,@opt.fns).error + rescue + SiSU_Errors::Info_error.new($!,$@,@cf,@opt.fns).error ensure end begin @@ -132,4 +133,3 @@ module SiSU_DBI end end __END__ - diff --git a/lib/sisu/v0/hub.rb b/lib/sisu/v0/hub.rb index 029c99c5..2053ea8b 100644 --- a/lib/sisu/v0/hub.rb +++ b/lib/sisu/v0/hub.rb @@ -85,8 +85,9 @@ module SiSU @pod end def name - pod_download_as=if name_source=~/(?:sisupod\.(?:zip|ssp))/; dir_stub + '.ssp' - else name_source + pod_download_as=if name_source=~/(?:sisupod\.(?:zip|ssp))/ + dir_stub + '.ssp' + else name_source end end self @@ -116,7 +117,8 @@ module SiSU end def select require "#{SiSU_lib}/#@req" - if @req =~/^conf$/; SiSU_Initialize::Source.new(@opt).read # -C + if @req =~/^conf$/ # -C + SiSU_Initialize::Source.new(@opt).read end if not @opt.files.empty? @opt.files.each do |fns| @@ -135,7 +137,8 @@ module SiSU if @req=~/^dal$/ \ and FileTest.file?(@opt.fns) \ and @opt.fns =~ /\.(?:(?:-|ssm\.)?sst|ssm)$/ - if fns =~ /\.ssm$/; require "#{SiSU_lib}/composite" #pre-processing + if fns =~ /\.ssm$/ + require "#{SiSU_lib}/composite" #pre-processing SiSU_Assemble::Composite.new(@opt).read @opt.fns=fns.gsub(/\.ssm$/,'.ssm.sst') end @@ -145,7 +148,8 @@ module SiSU when /\.(?:(?:-|ssm\.)?sst|ssm)$/ case @req when /^dal$/ - if fns =~ /\.ssm$/; require "#{SiSU_lib}/composite" #pre-processing + if fns =~ /\.ssm$/ + require "#{SiSU_lib}/composite" #pre-processing SiSU_Assemble::Composite.new(@opt).read @opt.fns=fns.gsub(/\.ssm$/,'.ssm.sst') end @@ -254,8 +258,9 @@ p "here #{__FILE__} #{__LINE__}" if @opt =~/M/ end def webrick # -W port=prt=@fns - prt=if prt !~/\d+/; 'webrick default (sysenv)' - else "webrick port set to #{prt}" + prt=if prt !~/\d+/ + 'webrick default (sysenv)' + else "webrick port set to #{prt}" end puts %{#{@cX.blue}<<#{@cX.off}#{@cX.green}Start Webrick web server on port: #{prt}#{@cX.off}#{@cX.blue}>> #{@cX.off*2} } system("sisu_webrick #{port}&\n") @@ -298,7 +303,8 @@ p "here #{__FILE__} #{__LINE__}" if @opt =~/M/ Op.new(@opt,req,msg).select if req and msg end def actions - if @opt.mod.inspect =~/--convert|--to|--from/; require "#{SiSU_lib}/sst_convert_markup" + if @opt.mod.inspect =~/--convert|--to|--from/ + require "#{SiSU_lib}/sst_convert_markup" end if @opt.cmd =~/([abCcDdFfgGHhIiJjLMmNnOopQqrRSsTtUuVvwWXxYyZ_0-9])/ \ and @opt.cmd =~/^-/ \ @@ -310,7 +316,8 @@ p "here #{__FILE__} #{__LINE__}" if @opt =~/M/ extra='' if @opt.cmd !~/[mn]/ extra+=if @opt.cmd =~/[abghHhIiJjNOoptTwXxz]/ \ - and @opt.cmd !~/[mn]/; 'm' #% add dal + and @opt.cmd !~/[mn]/ + 'm' #% add dal elsif ((@opt.cmd =~/[Dd]/ \ or (@opt.mod.inspect =~/--(?:(?:sq)?lite|pg(?:sql)?)/)) \ and @opt.mod.inspect !~/(?:remove|(?:(?:re)?create(?:all)?|dropall|drop)$)/) \ @@ -332,16 +339,17 @@ p "here #{__FILE__} #{__LINE__}" if @opt =~/M/ end end @opt.cmd=@opt.cmd + extra - if @opt.cmd =~/[vVM]/ #% version information + if @opt.cmd =~/[vVM]/ #% version information if @opt.cmd =~/V/ \ - and @opt.files.empty? #% environment + and @opt.files.empty? #% environment SiSU_Help::Help.new('env',@opt).environment else SiSU_Help::Help.new('env',@opt).sisu_version end end - if @opt.cmd =~/^-L$/; SiSU_Help::Help.new('license',@opt).help_request #% version information + if @opt.cmd =~/^-L$/ #% version information + SiSU_Help::Help.new('license',@opt).help_request end - if @opt.cmd =~/m/i #% -m for -C + if @opt.cmd =~/m/i #% -m for -C path={} path[:css]=@@env.path.output + '/_sisu/css' path[:xml]=@@env.path.output + '/_sisu/xml' @@ -355,12 +363,13 @@ p "here #{__FILE__} #{__LINE__}" if @opt =~/M/ and FileTest.directory?(path[:xsd]) ) @opt.cmd=@opt.cmd +='C' unless @opt.cmd =~/C/ #FIX end - if @opt.cmd =~/M/; $VERBOSE=false #debug $VERBOSE=true + if @opt.cmd =~/M/ + $VERBOSE=false #debug $VERBOSE=true # -M test other expected directories including images end end end - if @opt.cmd =~/C/ #% -C initialize/configure + if @opt.cmd =~/C/ #% -C initialize/configure op('conf','configure site') if @opt.cmd =~/R/ if @opt.mod.inspect =~/--init(?:ialize)?=site/ \ @@ -376,19 +385,22 @@ p "here #{__FILE__} #{__LINE__}" if @opt =~/M/ end end end - if @opt.cmd =~/F/ #% -F cgi sample search form + if @opt.cmd =~/F/ #% -F cgi sample search form Operations.new(@opt).cgi end - if @opt.cmd =~/W/; Operations.new(@opt).webrick #% -W webrick #@argv==port + if @opt.cmd =~/W/ #% -W webrick #@argv==port + Operations.new(@opt).webrick end - if @opt.cmd =~/k/ #% -k dummy, build character encoding table + if @opt.cmd =~/k/ #% -k dummy, build character encoding table #Operations.new(@opt.cmd).encoding end - if @opt.cmd =~/Z/; op('zap','Zap, deletions') #% -Z wipe previous output clean + if @opt.cmd =~/Z/ #% -Z wipe previous output clean + op('zap','Zap, deletions') end - if @opt.cmd =~/s/; op('share_src','SiSU markup source') #% -s sisu source + if @opt.cmd =~/s/ #% -s sisu source + op('share_src','SiSU markup source') end - if @opt.cmd =~/m/ #% -m is remote url requested? (download if) + if @opt.cmd =~/m/ #% -m is remote url requested? (download if) @retry_count= -1 begin path_image='./_sisu/processing/external_document/image' @@ -404,29 +416,31 @@ p "here #{__FILE__} #{__LINE__}" if @opt =~/M/ @get_p << re_p.match(fns)[1] if re_p end end - if @get_s.length > 0 #% remote markup file .sst + if @get_s.length > 0 #% remote markup file .sst require "#{SiSU_lib}/remote" SiSU_Remote::Get.new(@opt,@get_s).fns Operations.new.counter end - if @get_p.length > 0 #% remote sisupod + if @get_p.length > 0 #% remote sisupod require "#{SiSU_lib}/remote" SiSU_Remote::Get.new(@opt,@get_p).sisupod end - rescue; SiSU_Errors::Info_error.new($!,$@,@opt,@fns).error #ok + rescue + SiSU_Errors::Info_error.new($!,$@,@opt,@fns).error #ok @retry_count +=1 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.cmd=~/m/; op('dal','dal') #% -m dal + if @opt.cmd=~/m/ #% -m dal + op('dal','dal') end @opt.files=@opt.files.collect {|x| x=x.gsub(/\.ssm$/,'.ssm.sst') } if @opt.cmd =~/S/ - op('sisupod_make','sisupod (zip)') #% -S make sisupod + op('sisupod_make','sisupod (zip)') #% -S make sisupod if @opt.fns=~/\.kdi._sst/ - op('share_src_kdissert','kdissert (kdi)') #% -S share kdissert source + op('share_src_kdissert','kdissert (kdi)') #% -S share kdissert source end end if @opt.cmd =~/N/; op('digests','digests') #% -N digest tree diff --git a/lib/sisu/v0/remote.rb b/lib/sisu/v0/remote.rb index c65c619f..be36ac9a 100644 --- a/lib/sisu/v0/remote.rb +++ b/lib/sisu/v0/remote.rb @@ -126,7 +126,8 @@ module SiSU_Remote doc_skin_dir = /((?:https?|file):\/\/\S+?)\/[^\/]+?\.sst$/.match(url).captures.join + '/_sisu/skin/doc' #"Got file, and ready to process: #{fnb}.t#{instr}" downloaded_file=File.new("#{fnb}.-sst",'w+') - images=SiSU_Assemble::Remote_image.new.image(imagedir) + image_download_url=SiSU_Assemble::Remote_image.new.image(imagedir) + images=[] skin=SiSU_Assemble::Remote_image.new.image(doc_skin_dir) f.collect.each do |r| # work area unless r =~/^%+\s/ @@ -150,7 +151,7 @@ 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(images) + SiSU_Assemble::Remote_image.new.download_images(image_download_url,images) @msg,@msgs='downloading done',nil @tell.call.warn unless @opt.cmd =~/q/ end -- cgit v1.2.3