From 8b3f9e832f69bcef52f073678bbde1fcc588e695 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 26 Apr 2010 20:58:26 -0400 Subject: git, start experimenting with an alternative/parallel git based sisu document structure * git, start to experiment with file structure to replace sisupod -g and will be in configure options, to track changes to document, enable creation of "pods" (zipped content) and allow for remote versioned (or unversioned) placement of content source; ideally would end up with two co-existing, distinct parse-able structures whether local or remote, the existing directory structure with multiple documents and document images etc. and git directories with all content associated with a single document (including other language versions of it); cannot guarantee at this stage that the file structure will be retained, which may mean recreating any directory started and defeat the purpose of using it, though it is in a version control repo, so perhaps not ... best left alone (unused) for now --- lib/sisu/v2/constants.rb | 6 +- lib/sisu/v2/git.rb | 166 ++++++++++++++++++++++++++++++++++++++++++++++- lib/sisu/v2/hub.rb | 8 ++- lib/sisu/v2/sysenv.rb | 24 ++++++- 4 files changed, 196 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/sisu/v2/constants.rb b/lib/sisu/v2/constants.rb index 02c76e6a..8606796a 100644 --- a/lib/sisu/v2/constants.rb +++ b/lib/sisu/v2/constants.rb @@ -58,7 +58,7 @@ =end Sfx={:txt=>'.txt',:html=>'.html',:xhtml=>'.xhtml',:xml=>'.xml',:epub=>'.epub',:epub_xhtml=>'.xhtml',:odt=>'.odt',:pdf=>'.pdf'} -Ax,Xx,Mx,Rx,Hx,Dx,Px,Db,Tex={},{},{},{},{},{},{},{},{} +Ax,Xx,Mx,Rx,Hx,Dx,Px,Db,Gt,Tex=Array.new(10){{}} Ax[:tab]="\t" Xx[:protect]='☞' Xx[:segment]='Ф' @@ -151,6 +151,10 @@ Db[:col_filename]=256 Db[:col_digest]=64 Db[:col_filesize]=10 Db[:col_info_note]=2500 +Gt[:grotto]='sisu:' +Gt[:txt]='txt' +Gt[:image]='images' +Gt[:conf]='conf' __END__ consider: 〔comment〕 diff --git a/lib/sisu/v2/git.rb b/lib/sisu/v2/git.rb index 0a318d83..2d7629fd 100644 --- a/lib/sisu/v2/git.rb +++ b/lib/sisu/v2/git.rb @@ -56,7 +56,167 @@ ** Description: system environment, resource control and configuration details =end - - #___# - +module SiSU_Git + require "#{SiSU_lib}/param" # param.rb + require "#{SiSU_lib}/sysenv" # sysenv.rb + require "#{SiSU_lib}/dal" # dal.rb + class Source + include FileUtils #::Verbose + def initialize(opt) + @opt=opt + @env=SiSU_Env::Info_env.new + @git_path={} + @git_path[:fnb]=@env.path.processing_path_git + '/' + @opt.fnb + @git_path[:src]=@git_path[:fnb] + '/' + Gt[:txt] + @git_path[:image]=@git_path[:fnb] + '/' + Gt[:image] + @git_path[:conf]=@git_path[:fnb] + '/' + Gt[:conf] + @md=SiSU_Param::Parameters.new(@opt).get + SiSU_DAL::Source.new(@opt).read # -m + end + def read + make_dir_fnb + if program_found? + git_init + end + populate.sisusrc_files + if program_found? + git_commit + end + end + def program_found? + found=`whereis git` + (found =~/bin\/git\b/) ? true : false + end + def make_dir_fnb + mkdir_p(@git_path[:fnb]) unless FileTest.directory?(@git_path[:fnb]) + mkdir_p(@git_path[:src]) unless FileTest.directory?(@git_path[:src]) + mkdir_p(@git_path[:conf]) unless FileTest.directory?(@git_path[:conf]) + mkdir_p("#{@git_path[:conf]}/skin") unless FileTest.directory?("#{@git_path[:conf]}/skin") + mkdir_p(@git_path[:image]) unless FileTest.directory?(@git_path[:image]) + end + def git_init + unless FileTest.directory?("#{@git_path[:fnb]}/.git") + system("cd #{@git_path[:fnb]}\ + && git init + ") + end + end + def git_commit + system("cd #{@git_path[:fnb]} \ + && git add . \ + && git commit -a + ") + end + def populate + def identify_language_versions + print __FILE__ + ':' + p __LINE__ + end + def copy_src_head + if @opt.fns =~/\.ssm\.sst/ + ssm=@opt.fns.gsub(/\.ssm\.sst/,'.ssm') + cp_r("#{@env.path.pwd}/#{ssm}",@git_path[:src]) + else + cp_r("#{@env.path.pwd}/#{@opt.fns}",@git_path[:src]) + end + end + def copy_related_sst_ssi + doc_import=[] + @rgx_doc_import=/^<<\s(\S+?\.ss[ti])/ + file_array=IO.readlines(@opt.fns,'') + file_array.each do |f| + if f =~@rgx_doc_import + doc_import = doc_import + f.scan(@rgx_doc_import).uniq.flatten + end + end + doc_import.each do |f| + cp_r("#{@env.path.pwd}/#{f}",@git_path[:src]) + end + end + def locate_parse_file + composite_src=@opt.fns=~/\.ssm$/ ? true : false + parse_file=if composite_src \ + and @opt.cmd.inspect !~/m/ + ##SiSU_Assemble::Composite.new(@opt).read + #SiSU_DAL::Source.new(@opt).read # -m + "#{@env.path.composite_file}/#{@opt.fnb}.ssm.sst" + elsif composite_src + "#{@env.path.composite_file}/#{@opt.fnb}.ssm.sst" + else "#{@env.path.pwd}/#{@opt.fns}" + end + end + def locate_skin + SiSU_Env::Info_skin.new(@md).select + end + def read_composite + #print __FILE__ + ':' + #p __LINE__ + end + def extract_skin + #print __FILE__ + ':' + #p __LINE__ + end + def extract_skin_and_images #(parse_file) + parse_file_name=locate_parse_file + parse_file=IO.readlines(parse_file_name,'') + rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/ + #rgx_rb_image=/["'](\S+?\.(?:png|jpg|gif))["']/ + #rgx_rb_image=/[^\/]?([a-z]\S+?\.(?:png|jpg|gif))/ + rgx_rb_image=/([a-z][^ \/]+?\.(?:png|jpg|gif))/ + rgx_skin=/^\s+:skin:\s+(\S+)/ + skin_get=nil + images=[] + skin_get + parse_file.each do |f| #% work area + if f !~/^%+\s/ + skin_get ||= f.scan(rgx_skin).uniq.flatten if f =~rgx_skin + if f =~rgx_image + images << f.scan(rgx_image).uniq + end + end + end + skin=skin_get[0] if skin_get + skin=locate_skin + parse_skin=IO.readlines(skin,"\n") + parse_skin.each do |f| #% work area + if f !~/^#/ \ + and f =~rgx_rb_image + images << f.scan(rgx_rb_image).uniq + end + end + image_path="#{@env.path.pwd}/_sisu/image" + images.flatten.each do |i| + if FileTest.file?("#{image_path}/#{i}") + cp_r("#{image_path}/#{i}",@git_path[:image]) + end + end + if FileTest.file?(skin) + cp_r(skin,"#{@git_path[:conf]}/skin") + end + {:skin =>skin, :images =>images} + end + def read_src + print __FILE__ + ':' + p __LINE__ + end + def composite_src? + @opt.fns=~/\.ssm$/ ? true : false + end + def sisusrc_files + populate.copy_src_head + if composite_src? + populate.copy_related_sst_ssi + end + populate.extract_skin + #parse_file_name=locate_parse_file + #parse_file=IO.readlines(parse_file_name,'') + populate.extract_skin_and_images #(parse_file) + #populate.extract_composite_source + #populate.read_composite # or read_each_composite + populate.identify_language_versions + end + self + end + end +end __END__ diff --git a/lib/sisu/v2/hub.rb b/lib/sisu/v2/hub.rb index 08a120fa..58f62d0f 100644 --- a/lib/sisu/v2/hub.rb +++ b/lib/sisu/v2/hub.rb @@ -124,6 +124,7 @@ module SiSU @opt.fns=fns.gsub(/\.ssm$/,'.ssm.sst') end SiSU_DAL::Source.new(@opt).read # -m + when /^git$/; SiSU_Git::Source.new(@opt).read # -g when /^concordance$/; SiSU_Concordance::Source.new(@opt).read # -w when /^share_src$/; SiSU_Markup::Source.new(@opt).read # -s when /^sisupod_make$/; SiSU_Doc::Source.new(@opt).read # -S @@ -283,7 +284,7 @@ p "here #{__FILE__} #{__LINE__}" if @opt =~/M/ if @opt.mod.inspect =~/--convert|--to|--from/ require "#{SiSU_lib}/sst_convert_markup" # sst_convert_markup.rb end - if @opt.cmd =~/([AabCcDdeFfGHhIiJjLMmNnOopQqrRSsTtUuVvwWXxYyZ_0-9])/ \ + if @opt.cmd =~/([AabCcDdeFfgGHhIiJjLMmNnOopQqrRSsTtUuVvwWXxYyZ_0-9])/ \ and @opt.cmd =~/^-/ \ and @opt.mod.inspect !~/--(?:sitemaps|query|identify)/ \ or @opt.mod.inspect =~/--(?:(?:sq)?lite|pg(?:sql)?)/ #and @@ -292,7 +293,7 @@ p "here #{__FILE__} #{__LINE__}" if @opt =~/M/ flag=SiSU_Env::Info_processing_flag.new extra='' if @opt.cmd !~/[mn]/ - extra+=if @opt.cmd =~/[abeghHhIiJjNOoptTwXxz]/ \ + extra+=if @opt.cmd =~/[abehHhIiJjNOoptTwXxz]/ \ and @opt.cmd !~/[mn]/ 'm' #% add dal elsif ((@opt.cmd =~/[Dd]/ \ @@ -372,6 +373,9 @@ p "here #{__FILE__} #{__LINE__}" if @opt =~/M/ if @opt.cmd =~/s/ #% -s sisu source op('share_src','SiSU markup source') end + if @opt.cmd =~/g/ #% -g sisu git + op('git','SiSU Git') + end if @opt.cmd =~/m/ #% -m is remote url requested? (download if) @retry_count= -1 begin diff --git a/lib/sisu/v2/sysenv.rb b/lib/sisu/v2/sysenv.rb index c857468f..ed0fe136 100644 --- a/lib/sisu/v2/sysenv.rb +++ b/lib/sisu/v2/sysenv.rb @@ -115,6 +115,7 @@ module SiSU_Env end processing_path=tmp_processing_individual processing_dir=prcss_dir + processing_git="#{Dir.pwd}/#{Gt[:grotto]}" user=ENV['USER'] port_pgsql=if defined? ENV['PGPORT'] \ and not (ENV['PGPORT'].nil? \ @@ -149,6 +150,7 @@ module SiSU_Env PROCESSING_SQLITE=:processing_sqlite PROCESSING_POSTGRESQL=:processing_postgresql PROCESSING_ENCODING=:processing_encoding + PROCESSING_GIT=:processing_git PAPERSIZE=:papersize LANGUAGE=:language LANGUAGE_CODE=:language_code @@ -191,6 +193,7 @@ module SiSU_Env PROCESSING_SQLITE => 'sqlite', PROCESSING_POSTGRESQL=> 'postgresql', PROCESSING_ENCODING => 'encoding', + PROCESSING_GIT => processing_git, #TEXINFO_STUB => 'texinfo', PAPERSIZE => 'A4', #A4, US_letter, book_b5, book_a5, US_legal LANGUAGE => 'English', @@ -526,7 +529,7 @@ module SiSU_Env end def program_found?(program) found=`whereis #{program}` - state=(found =~/bin\/#{program}\b/) ? true : false + (found =~/bin\/#{program}\b/) ? true : false end def locale #locales utf8 or other unless @@locale_flag @@ -817,7 +820,7 @@ module SiSU_Env class Info_env < Env_call require 'fileutils' include FileUtils - attr_accessor :filename,:sys,:home,:hostname,:user,:env,:rc,:www,:fnb,:fnn,:fnt,:flv,:webserv_path,:stub_pwd,:stub_src,:webserv_host_cgi,:webserv_port_cgi,:processing,:etc,:yamlrc_dir + attr_accessor :filename,:sys,:home,:hostname,:user,:env,:rc,:www,:fnb,:fnn,:fnt,:flv,:webserv_path,:stub_pwd,:stub_src,:webserv_host_cgi,:webserv_port_cgi,:processing,:processing_git,:etc,:yamlrc_dir @@image_flag,@@local_image=true,true #warning on @@image_flag @@fb=@@man_path=nil,nil def initialize(fns='',md=nil) @@ -1449,6 +1452,23 @@ WOK end processing end + def processing_path_git + proposed_dir=if defined? @rc['git']['dir'] \ + and not @rc['git']['dir'].nil? \ + and not @rc['git']['dir'].empty? + x=(@rc['git']['dir'] =~/^(?:~|home)$/) \ + ? home + '/' + 'sisu:' \ + : @rc['git']['dir'] + '/' + 'sisu:' + else defaults[:processing_git] + end + end + def processing_git + unless FileTest.directory?(processing_path_git) + mkdir_p(processing_path_git) + File.chmod(0700,processing_path_git) + end + processing_path_git + end def epub "#{processing}/epub/#{@fnb}" end -- cgit v1.2.3