From f31e286f4a73c5c0f355512b0cb45c6c82088516 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sat, 22 Jun 2013 01:13:46 -0400 Subject: v5: general code cleaning * propagate back to v4 after testing --- lib/sisu/v5/sysenv.rb | 131 +++++++++++++++++++++----------------------------- 1 file changed, 56 insertions(+), 75 deletions(-) (limited to 'lib/sisu/v5/sysenv.rb') diff --git a/lib/sisu/v5/sysenv.rb b/lib/sisu/v5/sysenv.rb index 1a00baa7..973e0dcc 100644 --- a/lib/sisu/v5/sysenv.rb +++ b/lib/sisu/v5/sysenv.rb @@ -113,18 +113,13 @@ module SiSU_Env else #error tmp_processing=tmp_processing_individual="/tmp/#{prcss_dir_stub}" end - tmp_processing_home=if @@home \ - and File.writable?("#{@@home}/.") - "#{@@home}/#{prcss_dir_stub}" - else prcss_dir_stub - end processing_pth=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? \ - or ENV['PGPORT'].empty?) \ + || ENV['PGPORT'].empty?) \ and ENV['PGPORT']=~/^\d+$/ ENV['PGPORT'] else '5432' @@ -219,7 +214,6 @@ module SiSU_Env @@default_dir=DEFAULT_DIR m=/.+\/(?:src\/)?(\S+)/m # m=/.+?\/(?:src\/)?([^\/]+)$/im # m=/.+\/(\S+)/m @@pwd=@pwd=SiSU_Utils::Path.new.base_markup - stub_pwd=@pwd[m,1] attr_accessor :user,:home,:hostname,:pwd,:host,:arch,:rbver,:dir_arch,:dir_sitearch,:dir_bin,:locale,:webserv_path,:webserv_host_cgi,:webserv_port_cgi,:default_dir,:rc_path,:ad_path def initialize @user,@home,@hostname,@pwd,@sisu_etc,@host,@arch,@rbver,@dir_arch,@dir_sitearch,@dir_bin,@locale,@default_dir=\ @@ -239,7 +233,6 @@ module SiSU_Env end def prog load_prog=false - pp='' $:.each do |reqpath| if FileTest.exist?("#{reqpath}/#{@prog}.rb") load_prog=true @@ -560,7 +553,6 @@ module SiSU_Env @fn end def published_manifests?(output_base) - ob=output_base @fn={} @m=[] unless (@fns.nil? \ @@ -794,14 +786,14 @@ module SiSU_Env end def imagemagick #imagemagick is a image manipulation program program='identify' - program_ref="\n\t\tsee " + #program_ref="\n\t\tsee " found=(program_found?(program)) ? true : false #STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}" unless found found end def graphicksmagick #graphicsmagick is a image manipulation program program='gm' - program_ref="\n\t\tsee " + #program_ref="\n\t\tsee " found=(program_found?(program)) ? true : false #STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}" unless found found @@ -864,12 +856,8 @@ module SiSU_Env : (STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}") end def scp - program='scp' puts "scp -Cr #{@input} #{@output}" if @cmd =~/[vVM]/ puts "scp disabled" - #(program_found?(program)) \ - #? system("scp -Cr #{@input} #{@output}") \ - #: (STDERR.puts "\t*WARN* #{program} not found" ) end def rsync(action='',chdir=nil) program='rsync' @@ -892,7 +880,7 @@ module SiSU_Env dir_change=Dir.chdir(chdir) dir_return=Dir.pwd end - dir_change + dir_change #check system(" #{rsync_cmd} #{msg} #{amp} ") @@ -922,7 +910,7 @@ module SiSU_Env @@lang_info ||=@lang_info.language.list end def lang(l='') # from i18n - x=if l =~/^#{@r}$/ + if l =~/^#{@r}$/ @lang_info.language.list[l] elsif @language =~/^#{@r}$/ @lang_info.language.list[@language] @@ -1294,14 +1282,14 @@ module SiSU_Env : false end def html_minitoc? - flag=if defined? @rc['html']['minitoc'] \ + if defined? @rc['html']['minitoc'] \ and @rc['html']['minitoc'].is_a?(String) @rc['html']['minitoc'] else false end end def manifest_minitoc? - flag=if defined? @rc['manifest']['minitoc'] \ + if defined? @rc['manifest']['minitoc'] \ and @rc['manifest']['minitoc'].is_a?(String) @rc['manifest']['minitoc'] else false @@ -1358,7 +1346,7 @@ module SiSU_Env end end def links_to_manifest? - flag=if (defined? @rc['omit']['links_to_manifest'] \ + if (defined? @rc['omit']['links_to_manifest'] \ and not @rc['omit']['links_to_manifest'].nil?) \ or (listed?('links_to_manifest') \ || listed?('manifest_links')) @@ -1377,7 +1365,7 @@ module SiSU_Env end end def minitoc? - flag=if (defined? @rc['omit']['minitoc'] \ + if (defined? @rc['omit']['minitoc'] \ and not @rc['omit']['minitoc'].nil?) \ or (listed?('minitoc')) :off @@ -1386,7 +1374,7 @@ module SiSU_Env end end def manifest_minitoc? - flag=if (defined? @rc['omit']['manifest_minitoc'] \ + if (defined? @rc['omit']['manifest_minitoc'] \ and not @rc['omit']['manifest_minitoc'].nil?) \ or listed?('manifest_minitoc') :off @@ -1395,7 +1383,7 @@ module SiSU_Env end end def html_minitoc? - flag=if (defined? @rc['omit']['html_minitoc'] \ + if (defined? @rc['omit']['html_minitoc'] \ and not @rc['omit']['html_minitoc'].nil?) \ or (listed?('html_minitoc') \ || listed?('minitoc')) @@ -1405,7 +1393,7 @@ module SiSU_Env end end def html_navigation? - flag=if (defined? @rc['omit']['html_navigation'] \ + if (defined? @rc['omit']['html_navigation'] \ and not @rc['omit']['html_navigation'].nil?) \ or listed?('html_navigation') :off @@ -1414,7 +1402,7 @@ module SiSU_Env end end def html_navigation_bar? - flag=if (defined? @rc['omit']['html_navigation_bar'] \ + if (defined? @rc['omit']['html_navigation_bar'] \ and not @rc['omit']['html_navigation_bar'].nil?) \ or listed?('html_navigation_bar') :off @@ -1423,7 +1411,7 @@ module SiSU_Env end end def segsubtoc? - flag=if (defined? @rc['omit']['segsubtoc'] \ + if (defined? @rc['omit']['segsubtoc'] \ and not @rc['omit']['segsubtoc'].nil?) \ or listed?('segsubtoc') :off @@ -1432,7 +1420,7 @@ module SiSU_Env end end def html_right_pane? - flag=if (defined? @rc['omit']['html_right_pane'] \ + if (defined? @rc['omit']['html_right_pane'] \ and not @rc['omit']['html_right_pane'].nil?) \ or listed?('html_right_pane') :off @@ -1441,7 +1429,7 @@ module SiSU_Env end end def html_top_band? - flag=if (defined? @rc['omit']['html_top_band'] \ + if (defined? @rc['omit']['html_top_band'] \ and not @rc['omit']['html_top_band'].nil?) \ or listed?('html_top_band') :off @@ -1450,7 +1438,7 @@ module SiSU_Env end end def search_form? #decide later, as is configured here (in sisurc) and can be turned off on command line - flag=if (defined? @rc['omit']['search_form'] \ + if (defined? @rc['omit']['search_form'] \ and not @rc['omit']['search_form'].nil?) \ or listed?('search_form') :off @@ -1459,7 +1447,7 @@ module SiSU_Env end end def html_search_form? #decide later, as is configured here (in sisurc) and can be turned off on command line - flag=if (defined? @rc['omit']['html_search_form'] \ + if (defined? @rc['omit']['html_search_form'] \ and not @rc['omit']['html_search_form'].nil?) \ or listed?('html_search_form') :off @@ -1654,7 +1642,7 @@ WOK end end def search_action #check - action=if search? + if search? else '' end end @@ -1759,7 +1747,7 @@ WOK end end def search_action #check - action=if search? + if search? else '' end end @@ -1767,7 +1755,7 @@ WOK end def source_file_path file=@fns.gsub(/\.ssm(?:\.sst)?/,'.ssm.sst') - pth=unless file =~/\.ssm\.sst$/; "#{Dir.pwd}" + unless file =~/\.ssm\.sst$/; "#{Dir.pwd}" else "#{processing_path.composite_file}" end end @@ -1845,7 +1833,7 @@ WOK self end def read_source_file_array(fns) - fns_array=(fns !~/\.ssm.sst$/) \ + (fns !~/\.ssm.sst$/) \ ? (IO.readlines(fns, mode: 'r:utf-8', cr_newline: true)) : (IO.readlines("#{processing_path.composite_file}/#{fns}", mode: 'r:utf-8', cr_newline: true)) end @@ -1853,12 +1841,12 @@ WOK read_source_file_array(fns) end def read_source_file_string(fns) - fns_str=(fns !~/\.ssm.sst$/) \ + (fns !~/\.ssm.sst$/) \ ? (IO.read(fns, mode: 'r:utf-8', cr_newline: true)) : (IO.read("#{processing_path.composite_file}/#{fns}", mode: 'r:utf-8', cr_newline: true)) end def source_file_processing_array(fns) - sf=read_source_file_string(fns).split(/\s*\n\s*\n/m) + read_source_file_string(fns).split(/\s*\n\s*\n/m) end def path #dir def home @@ -2030,7 +2018,7 @@ WOK url.webserv_map_pwd end def image_source #image repository source directory - image_path=if defined? @rc['image']['path'] \ + if defined? @rc['image']['path'] \ and defined? @rc['image']['public'] pth="#{@rc['image']['path']}" "#{pth}/#{@rc['image']['public']}" @@ -2042,7 +2030,7 @@ WOK "#{share}/image" end def image_source_include #image repository source directory - image_path=if defined? @rc['image']['path'] \ + if defined? @rc['image']['path'] \ and defined? @rc['image']['public'] \ and FileTest.directory?("#{@rc['image']['path']}/#{@rc['image']['public']}")==true "#{@rc['image']['path']}/#{@rc['image']['public']}" @@ -2143,7 +2131,6 @@ WOK FileUtils::mkdir_p(processing_path_usr) unless FileTest.directory?(processing_path_usr) File.chmod(0700,processing_path_usr) end - fn_base_bundle=paths[:fnb] sisupod_processing_path=paths[:sisupod] FileUtils::mkdir_p(sisupod_processing_path) unless FileTest.directory?(sisupod_processing_path) sisupod_processing_path_lng=if defined? @opt.lng @@ -2210,7 +2197,7 @@ WOK def git pth=if defined? @rc['git']['dir'] \ and @rc['git']['dir'].is_a?(String) - x=(@rc['git']['dir'] =~/^(?:~|home)$/) \ + (@rc['git']['dir'] =~/^(?:~|home)$/) \ ? home + '/' + Gt[:git] : @rc['git']['dir'] + '/' + Gt[:git] else defaults[:processing_git] @@ -2256,7 +2243,6 @@ WOK FileUtils::mkdir_p("#{processing_path.epub}/META-INF") unless FileTest.directory?("#{processing_path.epub}/META-INF") FileUtils::mkdir_p("#{processing_path.epub}/#{Ep[:d_oebps]}/image") unless FileTest.directory?("#{processing_path.epub}/#{Ep[:d_oebps]}/image") FileUtils::mkdir_p("#{processing_path.epub}/#{Ep[:d_oebps]}/css") unless FileTest.directory?("#{processing_path.epub}/#{Ep[:d_oebps]}/css") - images=%W[bullet_09.png arrow_next_red.png arrow_prev_red.png arrow_up_red.png] processing_path.epub end def epub_cp_images(md) @@ -2494,13 +2480,13 @@ WOK end def cgi_sample_search_form_name(opt=nil) if opt.mod.inspect =~/--(?:cgi-)?search-form-name[=-]["']?(\S+?\.cgi)/ - m=$1 - elsif not (opt.mod.inspect =~/--db[=-]["']?sqlite/) \ + $1 + elsif not opt.mod.inspect =~/--db[=-]["']?sqlite/ \ and defined? @rc['search'] \ and defined? @rc['search']['sisu'] \ and defined? @rc['search']['sisu']['action'] \ and @rc['search']['sisu']['action'] =~/https?:\/\/\S+?\.cgi/ - x=/(?:https?:\/\/\S+?)\/([^\/]+?\.cgi)$/.match(@rc['search']['sisu']['action'])[1] + /(?:https?:\/\/\S+?)\/([^\/]+?\.cgi)$/.match(@rc['search']['sisu']['action'])[1] else (opt.mod.inspect =~/--db[=-]["']?sqlite/) \ ? 'sisu_sqlite.cgi' \ @@ -2521,7 +2507,7 @@ WOK @rc['show_output_on'] else 'filesystem' end - output=case output_type + case output_type when /^filesystem(?:_url)?/; url.dir_url when /^remote(?:_webserv)?/; url.remote when /^(?:webserv|local_webserv)/; url.local @@ -2843,7 +2829,7 @@ WOK end if f_pod \ && FileTest.file?(f_pod) - tree=(SiSU_Env::SystemCall.new.program_found?('tree')) \ + (SiSU_Env::SystemCall.new.program_found?('tree')) \ ? "tree #{processing_path.processing}/#{Gt[:sisupod]}" : '' if FileTest.directory?(processing_path.processing) @@ -2858,7 +2844,6 @@ WOK sisupod_processing_path end def sisupod_gen_v2(fns_pod) - pwd=Dir.pwd sisupod_processing_path="#{processing_path.processing}/#{Gt[:sisupod]}" if FileTest.directory?(sisupod_processing_path) \ or FileTest.file?(sisupod_processing_path) @@ -3338,7 +3323,7 @@ WOK #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 + @opt.fnc if (local_gen =~/\S/ \ and local_gen !~/\/\//) \ and (remote_gen =~/\S/ \ @@ -3346,7 +3331,7 @@ WOK and @@flag_remote==true \ and @opt.cmd !~/U/ # SiSU_Env::SystemCall.new("#{local_src}/#{src_txt}",remote_src,@opt.cmd).rsync - delete_extra_files='--delete' # '--delete-after' + #delete_extra_files='--delete' # '--delete-after' inp=[] if (@opt.act[:html][:set]==:on \ || @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \ @@ -3438,8 +3423,8 @@ WOK inp.join(' ') else '' end - local_css,images,images_external,images_system='','','','' - images_gen=images=images_skin=images_system=local_css='' + local_css,images,images_system='','','' + images=images_skin=images_system=local_css='' if @opt.cmd =~/[hwbxX]/ \ && (defined? @md.ec[:image]) \ && (@md.ec[:image].length > 0) @@ -3509,7 +3494,6 @@ WOK ldest='_sisu/*' l_rel="#{@env.path.webserv}/#{@env.path.stub_pwd}" image_sys="#{@env.path.webserv}/_sisu/image_sys" - images="#{@env.path.webserv}/_sisu/image" self.remote_host_base.each do |remote_conn| remote="#{remote_conn[:name]}/#{@env.path.stub_pwd}" remote_conf="#{remote_conn[:name]}/_sisu" @@ -3628,7 +3612,7 @@ WOK end def basefilename #Remove if possible m=/(.+?)\.(?:(?:-|ssm\.)?sst|ssm)$/m - fnb=@fns[m,1] + @fns[m,1] end def make_file(path,filename) (File.writable?("#{path}/.")) \ @@ -4068,9 +4052,9 @@ WOK end def psql def user(opt=nil) - x=if opt \ + if opt \ and opt.mod.inspect =~/--db-user[=-]["']?(\S+)["']+/ - m=$1 + $1 elsif opt \ and opt.mod =~/--webserv[=-]webrick/ @env.user @@ -4280,7 +4264,6 @@ WOK self end def mkdir - txt_path="#{output_path.base.dir}/#{@md.fnb}" def output def base FileUtils::mkdir_p(output_path.base.dir) unless FileTest.directory?(output_path.base.dir) @@ -4300,12 +4283,12 @@ WOK path="#{output_path.base.dir}/#{@md.fnb}" make_path(path) filename=@fno - file=make_file(path,filename) + make_file(path,filename) end def mkfile_pwd path=Dir.pwd filename=@fno - file=make_file(path,filename) + make_file(path,filename) end def write_file def txt @@ -4325,7 +4308,6 @@ WOK || (output_dir_structure.dump?)) \ ? "#{output_path.html.dir}" : "#{output_path.html.dir}/#{@md.fnb}" - fn=base_filename.html_seg_index make_path(pth) p_fn=place_file.html_seg_index.dir @@filename_html_index=File.new(p_fn,'w+') @@ -4336,7 +4318,6 @@ WOK || (output_dir_structure.redirect?)) \ ? "#{output_path.html.dir}" : "#{output_path.html.dir}/#{@md.fnb}" - fn=base_filename.html_segtoc make_path(pth) p_fn=place_file.html_segtoc.dir @@filename_html_index=File.new(p_fn,'w+') @@ -4345,43 +4326,43 @@ WOK path=output_path.xhtml.dir make_path(path) fn=base_filename.xhtml - file=make_file(path,fn) + make_file(path,fn) end def xml_sax path=output_path.xml.dir make_path(path) fn=base_filename.xml_sax - file=make_file(path,fn) + make_file(path,fn) end def xml_dom path=output_path.xml.dir make_path(path) fn=base_filename.xml_dom - file=make_file(path,fn) + make_file(path,fn) end def manpage path=output_path.manpage.dir make_path(path) fn=base_filename.manpage - file=make_file(path,fn) + make_file(path,fn) end def texinfo path=output_path.texinfo.dir make_path(path) fn=base_filename.texinfo - file=make_file(path,fn) + make_file(path,fn) end def info path=output_path.texinfo.dir make_path(path) fn=base_filename.info - file=make_file(path,fn) + make_file(path,fn) end def hash_digest path=output_path.hash_digest.dir make_path(path) fn=base_filename.hash_digest - file=make_file(path,fn) + make_file(path,fn) end def qrcode path=output_path.qrcode.dir @@ -5817,7 +5798,7 @@ WOK begin super(fns) @env=SiSU_Env::InfoEnv.new(fns) - ver=InfoVersion.instance + InfoVersion.instance if operation.class.inspect =~/SiSU_Param/ @md=operation end @@ -5896,7 +5877,7 @@ WOK @env=SiSU_Env::InfoEnv.new('',@md) end def html - css=if @md.doc_css \ + if @md.doc_css \ and FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@md.doc_css}_html.css") "#{@md.doc_css}_html.css" elsif FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@env.path.stub_pwd}_html.css") @@ -5906,7 +5887,7 @@ WOK end end def html_tables - css=if @md.doc_css \ + if @md.doc_css \ and FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@md.doc_css}_html_tables.css") "#{@md.doc_css}_html_tables.css" elsif FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@env.path.stub_pwd}_html_tables.css") @@ -5915,7 +5896,7 @@ WOK end end def xhtml - css=if @md.doc_css \ + if @md.doc_css \ and FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@md.doc_css}_xhtml.css") "#{@md.doc_css}_xhtml.css" elsif FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@env.path.stub_pwd}_xhtml.css") @@ -5924,7 +5905,7 @@ WOK end end def xml_sax - css=if @md.doc_css \ + if @md.doc_css \ and FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@md.doc_css}_xml_sax.css") "#{@md.doc_css}_xml_sax.css" elsif FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@env.path.stub_pwd}_xml_sax.css") @@ -5933,7 +5914,7 @@ WOK end end def xml_dom - css=if @md.doc_css \ + if @md.doc_css \ and FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@md.doc_css}_xml_dom.css") "#{@md.doc_css}_xml_dom.css" elsif FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@env.path.stub_pwd}_xml_dom.css") @@ -5942,7 +5923,7 @@ WOK end end def docbook_xml - css=if @md.doc_css \ + if @md.doc_css \ and FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@md.doc_css}_docbook.css") "#{@md.doc_css}_xml_dom.css" elsif FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@env.path.stub_pwd}_docbook.css") @@ -5951,7 +5932,7 @@ WOK end end def homepage - css=if @md.doc_css \ + if @md.doc_css \ and FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@md.doc_css}_homepage.css") "#{@md.doc_css}_homepage.css" elsif FileTest.file?("#{@env.path.output}/#{@env.path.style}/#{@env.path.stub_pwd}_homepage.css") -- cgit v1.2.3