}
else ''
end
end
def search_form_static(action=nil,db=nil)
rc=SiSU_Env::Get_init.instance.yamlrc
create_form=if action and db and action =~/http:\/\// and db =~/\S+/
true
elsif widget.search_fixed?
db=if rc['search']['db']=~/\S+/
rc['search']['db']=~/^SiSU_\S+/ ? rc['search']['db'] : "SiSU_#{rc['search']['db']}"
else nil
end
action=rc['search']['action']
true
else false
end
if create_form
%{
}
else ''
end
end
def search_action
action=if search?
else ''
end
end
self
end
def widget_static
@rc=SiSU_Env::Get_init.instance.yamlrc
@vz=SiSU_Env::Get_init.instance.skin
@flag={ :ad=>false,:md=>false,:sk=>false,:rc=>false }
def search?
flag=if defined? @rc['search'] and
defined? @rc['search']['action'] and @rc['search']['action'] =~/http:\/\// and
defined? @rc['search']['db'] and @rc['search']['db'] =~/\S+/
defined? @rc['search']['db'] and @rc['search']['db'] =~/\S+/
flag=if defined? @vz.widget_search and @vz.widget_search == true
true
elsif defined? @rc['search']['flag'] and @rc['search']['flag'] == true
true
else
false
end
else
false
end
end
def search_fixed?
flag=if defined? @rc['search'] and
defined? @rc['search']['action'] and @rc['search']['action'] =~/http:\/\// and
defined? @rc['search']['db'] and @rc['search']['db'] =~/\S+/
defined? @rc['search']['db'] and @rc['search']['db'] =~/\S+/
flag=if defined? @vz.widget_search and @vz.widget_search == true
true
elsif defined? @rc['search']['flag'] and @rc['search']['flag'] == true
true
else
false
end
else
false
end
end
def search_form(action=nil,db=nil)
rc=SiSU_Env::Get_init.instance.yamlrc
create_form=if action and db and action =~/http:\/\// and db =~/\S+/
true
elsif widget_static.search?
db=if rc['search']['db']=~/\S+/
rc['search']['db']=~/^SiSU_\S+/ ? rc['search']['db'] : "SiSU_#{rc['search']['db']}"
else nil
end
action=rc['search']['action']
true
else false
end
if create_form and @fnb and @fnb=~/\S+/
%{
}
elsif create_form
%{
}
else ''
end
end
def search_action
action=if search?
else ''
end
end
self
end
def path #dir
def home
@sys.home
#@home
end
def pwd
@sys.pwd
end
def stub_pwd
@stub_pwd
end
def etc
defaults[:sisu_etc] #live/dynamic
# @sys.sisu_etc #broken: live/dynamic
# defaults[:sisu_etc] #live/dynamic
end
def arch
@sys.dir_arch
end
def sitearch
@sys.dir_sitearch
end
def bin
@sys.dir_bin
end
def share #shared data repository source directory
defaults[:sisu_share]
end
def style
defaults[:stylesheet_stub]
end
def sample_data #sample data repository source directory
defaults[:sample_data_path]
end
def rc
@sys.rc_path
end
def yamlrc
rc.each do |v|
if FileTest.exists?("#{v}/sisurc.yml")
@yamlrc_dir="#{v}/sisurc.yml"
break
end
end
unless @yamlrc_dir
rc.each do |v|
if FileTest.exists?("#{v}/sisurc.yaml")
@yamlrc_dir="#{v}/sisurc.yaml"
break
end
end
end
@yamlrc_dir
end
def man
if defined? @rc['webserv']['man']; "#{webserv}/#{@rc['webserv']['man']}"
else defaults[:webserv_man]
end
end
def webserv_path #testing, check need, remove
@webserv_path
end
def webserv #separation required for webrick which cannot use path.output (different requirements as no file is passed)
man_path=if defined? @rc['webserv']['path'] and @rc['webserv']['path'] =~/\S\S+/
man_path=case @rc['webserv']['path']
when /^\/\S+/; @rc['webserv']['path']
when /^\.\/(\S+)/; "#{pwd}/#{$1}"
when /^~\/(\S+)/; "#{home}/#{$1}"
else "#{home}/#{@rc['webserv']['path']}"
end
else nil
end
@webserv_path=if defined? man_path and File.writable?("#{man_path}/."); man_path #web server path as configured in rc file
elsif FileTest.directory?(defaults[:webserv_path]) and File.writable?("#{defaults[:webserv_path]}/.") #web server path default
defaults[:webserv_path]
else #create default directory under home and place output there
File.mkpath(defaults[:output_local]) unless FileTest.directory?(defaults[:output_local])
defaults[:output_local]
end
end
def webserv_stub_ensure
File.mkpath(path.webserv) unless FileTest.directory?(path.webserv)
File.mkpath("#{path.webserv}/#@stub_pwd") unless FileTest.directory?("#{path.webserv}/#@stub_pwd")
end
def webserv_map_pwd #dir
"#{path.webserv}/#{stub_pwd}"
end
def webserv_dir #fixed/hard path to /www web/presentation directory, on Debian /var/www subdirectories are created within it, depending on markup directory stub-name (last segment of markup directory name)
defaults[:webserv_dir]
end
def webserv_image #web/presentation directory, subdirectories are created within it, depending on markup directory stub-name (last segment of markup directory name)
images=if defined? @rc['webserv']['images']
@rc['webserv']['images']
else defaults[:images]
end
"#{path.webserv}/#{images}"
end
def output #web/webserv output directory... subdirectory into which further subdirectories are made based on file names
"#{path.webserv}/#@stub_pwd"
end
def sitemaps
"#{path.output}/sitemaps"
end
def encoding
pth="#{processing}/#{defaults[:processing_encoding]}"
File.mkpath(pth) unless FileTest.directory?(pth)
pth
end
def processing_base_tmp
defaults[:processing_path_tmp_base]
end
def processing #processing directory, used/needed for sisu work files, has sub-directories (dal,tex etc)
File.mkpath(defaults[:processing_path]) unless FileTest.directory?(defaults[:processing_path])
File.mkpath(defaults[:processing_path_tmp]) unless FileTest.directory?(defaults[:processing_path_tmp])
path_processing=if defined? @rc['processing']['path'] and @rc['processing']['path']
File.mkpath("#{path.home}/#{@rc['processing']['path']}") unless FileTest.directory?("#{path.home}/#{@rc['processing']['path']}")
["#{path.home}/#{@rc['processing']['path']}",defaults[:processing_path],defaults[:processing_path_tmp]]
else [defaults[:processing_path],defaults[:processing_path_tmp]]
end
@processing=nil
path_processing.each do |v| #
#if File.writable?("#{v}/.") #check now is earlier
@processing=v
unless FileTest.directory?(@processing)
puts "a processing directory (#@processing) is being created for use by sisu"
File.mkpath(@processing)
end
break
#end
end
@processing
end
def dal
pth=if defined? @rc['processing']['dal']; "#{processing}/#{@rc['processing']['dal']}"
else "#{processing}/#{defaults[:processing_dal]}"
end
File.mkpath(pth) unless FileTest.directory?(pth)
pth
end
def tune
pth=if defined? @rc['processing']['tune']; "#{processing}/#{@rc['processing']['tune']}"
else "#{processing}/#{defaults[:processing_tune]}"
end
File.mkpath(pth) unless FileTest.directory?(pth)
pth
end
def odf
"#{processing}/odf"
end
def tex
pth=if defined? @rc['processing']['latex']; "#{processing}/#{@rc['processing']['latex']}"
else "#{processing}/#{defaults[:processing_latex]}"
end
File.mkpath(pth) unless FileTest.directory?(pth)
pth
end
def texi
pth=if defined? @rc['processing']['texinfo']; "#{processing}/#{@rc['processing']['texinfo']}"
else "#{processing}/#{defaults[:processing_texinfo]}"
end
File.mkpath(pth) unless FileTest.directory?(pth)
pth
end
def texinfo #texinfo webserv, check
"#{processing}/#{defaults[:processing_texinfo]}"
end
def lout
pth=if defined? @rc['processing']['lout']; "#{processing}/#{@rc['processing']['lout']}"
else "#{processing}/#{defaults[:processing_lout]}"
end
File.mkpath(pth) unless FileTest.directory?(pth)
pth
end
def feed
if defined? @rc['webserv']['feed']; "#{public_output}/#{@rc['webserv']['feed']}"
else defaults[:webserv_feed]
end
end
def feed_home
"#{public_output}/#{@rc['webserv']['feed_home']}"
end
def scripts #used previously only to include tla version info
if defined? @rc['project']['path']; "#{home}/#{@rc['project']['path']}"
end
end
def sqlite
"#{home}/sqlite"
end
def cgi
if defined? @rc['webserv']['cgi']; "#{@rc['webserv']['cgi']}"
else defaults[:webserv_cgi]
end
end
def php
if defined? @rc['webserv']['php']; "#{public_output}/#{@rc['webserv']['php']}"
else defaults[:webserv_php]
end
end
# programs
def output_tell
url.webserv_map_pwd
end
def image_source #image repository source directory
image_path=if defined? @rc['image']['path'] and defined? @rc['image']['public']
pth="#{@rc['image']['path']}"
"#{pth}/#{@rc['image']['public']}"
else
"#{share}/image"
end
end
def image_source_tex #image repository source directory
image_path=if defined? @rc['image']['path'] and defined? @rc['image']['public']
pth="#{@rc['image']['path']}"
"#{pth}/#{@rc['image']['public']}"
else
image=defaults[:image_stub]
"#{share}/image"
end
end
def image_external
"#{processing}/external_document/image"
end
def image_source_local_tex
if FileTest.directory?(defaults[:image_local]); defaults[:image_local]
end
end
def image_source_remote_tex
if FileTest.directory?(image_external); image_external
end
end
self
end
def url
def hostname
"http://#{@sys.hostname}"
end
def dir_url
"file://#{path.webserv}/#{stub_pwd}"
end
def localhost
"http://localhost/#{stub_pwd}"
end
def local
"http://#{hostname}/#@stub_pwd"
end
def root
if defined? @rc['webserv']['url_root'] and @rc['webserv']['url_root'] =~/http:\/\//; "#{@rc['webserv']['url_root']}/#@stub_pwd"
else "http://localhost/#@stub_pwd"
end
end
def remote
root
end
def webserv_host_base
if defined? @rc['webserv']['host']
case @rc['webserv']['host']
when /http:\/\//; @rc['webserv']['host']
when /\S+/; "http://#{@rc['webserv']['host']}"
else defaults[:webserv_host_cgi]
end
else defaults[:webserv_host_cgi]
end
end
def webrick_port
if @md and @md.cmd.inspect=~/-F/ and @md.mod.inspect=~/port=(\d+)/
$1
else
if defined? @rc['webserv_cgi']['port']
if @rc['webserv_cgi']['port'].nil? and (defined? @md.mod and not @md.mod.nil? and @md.mod.inspect=~/webrick/)
defaults[:webserv_port_cgi]
elsif not @rc['webserv_cgi']['port'].nil?
@rc['webserv_cgi']['port']
else defaults[:webserv_port_cgi]
end
else defaults[:webserv_port_cgi]
end
end
end
def webserv_port_cgi
if @md and @md.cmd.inspect=~/-F/ and @md.mod.inspect=~/port=(\d+)/
$1
else
if defined? @rc['webserv_cgi']['port']
if @rc['webserv_cgi']['port'].nil? and (defined? @md.mod and not @md.mod.nil? and @md.mod.inspect=~/webrick/)
defaults[:webserv_port_cgi]
elsif not @rc['webserv_cgi']['port'].nil?
@rc['webserv_cgi']['port']
else nil
end
else nil
end
end
end
def webserv_cgi #web url for local webserv (localhost, or hostname)
if defined? @rc['webserv_cgi']['host'] and not @rc['webserv_cgi']['host'].nil?
http=@rc['webserv_cgi']['host'] =~ /http:\/\// ? '' : 'http://'
if webserv_port_cgi
"#{http}#{@rc['webserv_cgi']['host']}:#{webserv_port_cgi}/#@stub_pwd"
else "#{http}#{@rc['webserv_cgi']['host']}/#@stub_pwd"
end
else
http=webserv_host_base=~/http:\/\// ? '' : 'http://'
if webserv_port_cgi
"#{http}#{webserv_host_base}:#{webserv_port_cgi}/#@stub_pwd"
else "#{http}#{webserv_host_base}/#@stub_pwd"
end
end
end
def webserv_base_cgi #web url for local webserv (localhost, or hostname)
if defined? @rc['webserv_cgi']['host'] and not @rc['webserv_cgi']['host'].nil?
http=@rc['webserv_cgi']['host'] =~ /http:\/\// ? '' : 'http://'
if webserv_port_cgi
"#{http}#{@rc['webserv_cgi']['host']}:#{webserv_port_cgi}"
else "#{http}#{@rc['webserv_cgi']['host']}"
end
else
http=webserv_host_base=~/http:\/\// ? '' : 'http://'
if webserv_port_cgi
"#{http}#{webserv_host_base}:#{webserv_port_cgi}"
else "#{http}#{webserv_host_base}"
end
end
end
def webrick #must have a port #REMOVE
#port=":#{webserv_port_cgi}"
if defined? @rc['webserv_cgi']['host'] and not @rc['webserv_cgi']['host'].nil?
http=if @rc['webserv_cgi']['host'] =~/http:\/\//
'http://'
else defaults
end
"#{http}#{@rc['webserv_cgi']['host']}"
elsif webserv_host_base and not webserv_host_base.nil?
"#{http}#{webserv_host_base}"
else "#{http}localhost"
end
end
def webserv #web url for local webserv (localhost, or hostname)
if path.webserv_dir and path.webserv =~ /#{path.webserv_dir}/ #revisit
"#{path.webserv}/#@stub_pwd".gsub(/#{path.webserv_dir}/,"#{url.hostname}/#@stub_pwd")
elsif defined? @rc['webserv']['webrick_url'] and @rc['webserv']['webrick_url'] == false
"file://#{path.webserv}/#@stub_pwd"
else "#{url.hostname}:#{webserv_port_cgi}/#@stub_pwd"
end
end
def webserv_base #web url for local webserv (localhost, or hostname)
if path.webserv_dir and path.webserv =~ /#{path.webserv_dir}/ #revisit
"#{path.webserv}/#@stub_pwd".gsub(/#{path.webserv_dir}/,"#{url.hostname}")
elsif defined? @rc['webserv']['webrick_url'] and @rc['webserv']['webrick_url'] == false
"file://#{path.webserv}"
else "#{url.webrick_base}"
end
end
def webserv_files_from_db #sort this out, messy
if defined? @rc['webserv_cgi']['file_links']
case @rc['webserv_cgi']['file_links']
when /webserv_cgi/; url.webserv_base_cgi
when /webserv/; @rc['webserv']['url_root']
when /http:\/\//; @rc['webserv_cgi']['file_links']
when /\S+/; "http://#{@rc['webserv_cgi']['file_links']}"
else webserv_base_cgi
end
else webserv_base_cgi
end
end
def sample_search_form_title
if defined? @rc['search']['title'] and @rc['search']['title'] =~/\S+/
@rc['search']['title']
else %{SiSU search form (sample):}
end
end
def output_tell
output_type=if defined? @rc['show_output_on'] and @rc['show_output_on'] =~/^(?:filesystem|webserv|(?:local|remote)(?:_webserv)?|webrick)/
@rc['show_output_on']
else 'filesystem'
end
output=case output_type
when /^filesystem(?:_url)?/; url.dir_url
when /^remote(?:_webserv)?/; url.remote
when /^(?:webserv|local_webserv)/; url.local
when /^local(:\d+)/; url.hostname + $1 + '/' + stub_pwd
when /^localhost(:\d+)/; url.localhost + $1 + '/' + stub_pwd
when /^localhost/; url.localhost
when /^webrick/; url.webrick
when /^path/; url.webserv_map_pwd
else url.webserv_map_pwd
end
end
def images
'../_sisu/image'
end
def images_local
if FileTest.directory?(defaults[:image_local])
if @@image_flag
require 'ftools'
images=Dir.glob("#{defaults[:image_local]}/*.{png,jpg,gif}")
pth="#{path.webserv}/#@stub_pwd"
File.mkpath("#{pth}/_sisu/image_local") unless FileTest.directory?("#{pth}/_sisu/image_local")
images.each { |i| File.install(i,"#{pth}/#{i}") } unless images.length > 0
@@image_flag=false
end
'../_sisu/image_local'
else
if @@local_image==true
cmd=if @cmd; @cmd
else ''
end
tell=SiSU_Screen::Ansi.new(cmd,"WARNING - no local image directory or images:", defaults[:image_local] )
tell.warn unless cmd =~/q/
@@local_image=false
end
url.images
end
end
#def images_external #url_images_external #ex defaults url.path_png
# '../_sisu/image_external'
#end
def images_external
if FileTest.directory?(image_external)
if @@image_flag
require 'ftools'
images=Dir.glob("#{image_external}/*.{png,jpg,gif}")
pth="#{path.webserv}/#@stub_pwd"
File.mkpath("#{pth}/_sisu/image_external") unless FileTest.directory?("#{pth}/_sisu/image_external")
images.each { |i| File.install(i,"#{pth}/#{i}") } unless images.length > 0
@@image_flag=false
end
'../_sisu/image_external'
else
if @@local_image==true
tell=SiSU_Screen::Ansi.new(@cmd,"WARNING - image directory for external images or no such images:", :image_external )
tell.warn unless @cmd =~/q/
@@local_image=false
end
url.images_external
end
end
self
end
def digest
def type
if defined? @rc['default']['digest'] and @rc['default']['digest'] != nil
case @rc['default']['digest']
when /^sha(?:2|256)?$/; 'sha256'
when /^md5$/; 'md5'
else 'md5'
end
else 'md5'
end
end
def length
case digest.type
when /sha256/; 64
when /md5/; 32
else 32
end
end
def pattern
"[0-9a-f]{#{digest.length}}"
end
self
end
def program
def text_editor
if defined? @rc['program_select']['editor'] and @rc['program_select']['editor'] =~/\S\S+/
@rc['program_select']['editor']
elsif defined? @rc['program_select']['text_editor'] and @rc['program_select']['text_editor'] =~/\S\S+/
@rc['program_select']['text_editor']
else 'editor' #'gvim -c :R -c :S'
end
end
def pdf_viewer
if defined? @rc['program_select']['pdf_viewer'] and @rc['program_select']['pdf_viewer'] =~/\S\S+/
@rc['program_select']['pdf_viewer']
else 'pdf-viewer' #'evince'
end
end
def web_browser
if defined? @rc['program_select']['www_browser'] and @rc['program_select']['www_browser'] =~/\S\S+/
@rc['program_select']['www_browser']
elsif defined? @rc['program_select']['web_browser'] and @rc['program_select']['web_browser'] =~/\S\S+/
@rc['program_select']['web_browser']
else 'x-www-browser' #'kazehakase' 'galeon'
end
end
def www_browser
web_browser
end
def console_web_browser
if defined? @rc['program_select']['console_www_browser'] and @rc['program_select']['console_www_browser'] =~/\S\S+/
@rc['program_select']['console_www_browser']
elsif defined? @rc['program_select']['console_web_browser'] and @rc['program_select']['console_web_browser'] =~/\S\S+/
@rc['program_select']['console_web_browser']
else 'console-www-browser' #'links2' 'elinks' 'epiphany'
end
end
def console_www_browser
web_browser
end
def xml_viewer
if defined? @rc['program_select']['xml_viewer'] and @rc['program_select']['xml_viewer'] =~/\S\S+/
@rc['program_select']['xml_viewer']
else text_editor
end
end
def xml_editor
xml_viewer
end
def odf_viewer
if defined? @rc['program_select']['odf_viewer'] and @rc['program_select']['odf_viewer'] =~/\S\S+/
@rc['program_select']['odf_viewer']
else 'oowriter' #'odf-viewer','oowriter'
end
end
def file_encoding #file encoding
is=''
if defined? @rc['program_set']['file_encoding']; is=@rc['program_set']['encoding']
end
if is.nil? or is==true; is='encoding'
end
is
end
def wc #wordcount
is=''
if defined? @rc['program_set']['wc']; is=@rc['program_set']['wc']
end
if is.nil? or is==true; is='wc'
end
is
end
def tidy
if defined? @rc['program_set']['tidy']; is=@rc['program_set']['tidy']
end
if is.nil? or is==true; is='tidy'
end
is
end
def rexml #should be part of ruby 1.8 but apparently not always
is=if FileTest.directory?("#{Config::CONFIG['rubylibdir']}/rexml") #Config::CONFIG['sitedir']
true
else false
end
is=if defined? @rc['program_set']['rexml']; @rc['program_set']['rexml']
else ''
end
if is.nil? or is==true; is='rexml'
end
is
end
def pdflatex
is=if defined? @rc['program_set']['pdflatex']; @rc['program_set']['pdflatex']
else ''
end
if is.nil? or is==true; is='pdflatex'
end
is
end
def postgresql
is=if defined? @rc['program_set']['postgresql']; @rc['program_set']['postgresql']
else ''
end
if is.nil? or is==true; is='postgresql'
end
is
end
def sqlite
is=if defined? @rc['program_set']['sqlite']; @rc['program_set']['sqlite']
else ''
end
if is.nil? or is==true; is='sqlite'
end
is
end
self
end
def i18n
def language # language settings
##
m=/.+\/\S+?\~(\S+)/
pwd=Dir.pwd
conf=if defined? @rc['default']['language']; @rc['default']['language']
else nil
end
l=if pwd=~m ; pwd[m1,1] #2 directory: by visible directory name
elsif conf; @rc['default']['language'] #3 config: from sisurc.yaml
else defaults[:language] #4 sisu: program default
end #1 document: param gets
SiSU_Env::Standardise_language.new(l)
end
def multilingual
if defined? @rc['default']['multilingual'] and @rc['default']['multilingual'] != nil; @rc['default']['multilingual']
else defaults[:multilingual]
end
end
def lang_filename(l)
@lang={}
x=if multilingual
x=if defined? @rc['default']['language_file'] and @rc['default']['language_file'] != nil; @rc['default']['language_file']
else 1
end
else 0
end
if (l != defaults[:language_code]) or (language.code != defaults[:language_code]) #watch
if x==1; @lang[:pre],@lang[:mid],@lang[:post]="#{l}.",'',''
elsif x==2; @lang[:pre],@lang[:mid],@lang[:post]='',".#{l}",''
elsif x==3; @lang[:pre],@lang[:mid],@lang[:post]='','',".#{l}"
else @lang[:pre],@lang[:mid],@lang[:post]='','',''
end
else @lang[:pre],@lang[:mid],@lang[:post]='','',''
end
@lang
end
self
end
def file_encoding
is=''
if defined? @rc['program_set']['file_encoding']; is=@rc['program_set']['encoding']
end
if is.nil? or is==true; is='encoding'
end
is
end
def papersize # paper settings, default overidden in param if set within document
if defined? @rc['default']['papersize']; @rc['default']['papersize'].downcase
else defaults[:papersize].downcase
end
end
def odf_structure
rm_rf("#{path.processing}/odf")
system("unzip -q #{path.share}/odf/odt.zip -d #{path.processing}")
end
def sisupod_gen(fns_pod)
pwd=Dir.pwd
sisupod_processing_path="#{path.processing}/sisupod"
rm_rf(sisupod_processing_path) if FileTest.directory?(sisupod_processing_path) or FileTest.file?(sisupod_processing_path)
File.mkpath(sisupod_processing_path) unless FileTest.directory?(sisupod_processing_path)
if FileTest.file?("#{Dir.pwd}/#{fns_pod}")
system("unzip -q #{Dir.pwd}/#{fns_pod} -d #{path.processing}")
else
tell=SiSU_Screen::Ansi.new('',"file not found: #{fns_pod}")
tell.warn unless @cmd=~/q/
end
sisupod_processing_path
end
end
class Info_processing_flag
attr_accessor :color,:cf_0,:cf_1,:cf_2,:cf_3,:cf_4,:cf_5
def initialize
@rc=Get_init.instance.yamlrc
end
def color #processing flag shortcuts
if defined? @rc['flag']['color']; @rc['flag']['color']
else false
end
end
def cf_0 #processing flag shortcuts
if defined? @rc['flag']['default'] and
not (@rc['flag']['default'].nil? or @rc['flag']['default'].empty?)
@rc['flag']['default']
else '-NhwpAobxXyYv'
end
end
def cf_1 #processing flag shortcuts
if defined? @rc['flag']['i'] and
not (@rc['flag']['i'].nil? or @rc['flag']['i'].empty?)
@rc['flag']['i']
else '-NhwpAoy' #'-Nhwpy'
end
end
def cf_2 #processing flag shortcuts
if defined? @rc['flag']['ii'] and
not (@rc['flag']['ii'].nil? or @rc['flag']['ii'].empty?)
@rc['flag']['ii']
else '-NhwpAobxXy' # '-NhwpAoy'
end
end
def cf_3 #processing flag shortcuts
if defined? @rc['flag']['iii'] and
not (@rc['flag']['iii'].nil? or @rc['flag']['iii'].empty?)
@rc['flag']['iii']
else '-NhwpAobxXyY'
end
end
def cf_4 #processing flag shortcuts
if defined? @rc['flag']['iv'] and
not (@rc['flag']['iv'].nil? or @rc['flag']['iv'].empty?)
@rc['flag']['iv']
else '-NhwpAobxXDyY --import'
end
end
def cf_5 #processing flag shortcuts
if defined? @rc['flag']['v'] and
not (@rc['flag']['v'].nil? or @rc['flag']['v'].empty?)
@rc['flag']['v']
else '-NhwpAobxXDyY --update'
end
end
end
class Info_settings < Info_env
def permission?(prog) #program defaults
if defined? @rc['permission_set'][prog]; @rc['permission_set'][prog]
else false
end
end
def program?(prog) #program defaults
if defined? @rc['program_set'][prog]; @rc['program_set'][prog]
else false
end
end
end
class File_map < Info_env
attr_accessor :local_sisu_source
def initialize(opt='') #watch
super()
@opt=opt #,opt.fns,opt.cmd
#@file=@opt.fns #not always fns
@env=if @opt.fns and not @opt.fns.empty?
SiSU_Env::Info_env.new(@opt.fns)
else
SiSU_Env::Info_env.new('dummy.sst')
end
if @opt.cmd =~/m/; @md=SiSU_Param::Parameters.new(@opt).get
end
ft=[]
if @md and defined? @md.fn and @md.fn # used for multilingual
if @md.cmd =~ /[hH]/; ft << @md.fn[:html]
end
if @md.cmd =~ /w/ and @md.cmd !~ /[hH]/; ft << @md.fn[:concordance]
end
if @md.cmd =~ /y/ and @md.cmd !~ /[hH]/; ft << @md.fn[:manifest]
end
if @md.cmd =~ /p/; ft << @md.fn[:pdf_l] << @md.fn[:pdf_p]
end
if @md.cmd =~ /x/; ft << @md.fn[:sax]
end
if @md.cmd =~ /X/; ft << @md.fn[:dom]
end
if @md.cmd =~ /b/; ft << @md.fn[:xhtml]
end
if @md.cmd =~ /[aAeE]/; ft << @md.fn[:plain]
end
if @md.cmd =~ /[g]/; ft << @md.fn[:wiki]
end
if @md.cmd =~ /N/; ft << @md.fn[:digest]
end
if @md.cmd =~ /o/; ft << @md.fn[:odf]
end
if @md.cmd =~ /s/; ft << @md.fns
end
if @md.cmd =~ /S/; ft << 'sisupod.zip' << '.kdi'
end
@fnb=@md.fnb
else # still needed where/when param is not parsed
if @opt.cmd =~ /[hH]/; ft << '.html' << '.html.??'
end
if @opt.cmd =~ /w/ and @opt.cmd !~ /[hH]/; ft << 'concordance.html' << '??.concordance.html' << 'concordance.??.html'
end
if @opt.cmd =~ /y/ and @opt.cmd !~ /[hH]/; ft << 'sisu_manifest.html' << '??.sisu_manifest.html' << 'sisu_manifest.??.html'
end
if @opt.cmd =~ /p/; ft << 'landscape.pdf' << 'portrait.pdf' << '.pdf'
end
if @opt.cmd =~ /x/; ft << 'sax.xml' << '??.sax.xml' << 'sax.??.xml'
end
if @opt.cmd =~ /X/; ft << 'dom.xml' << '??.dom.xml' << 'dom.??.xml'
end
if @opt.cmd =~ /b/; ft << 'scroll.xhtml' << '??.scroll.xhtml' << 'scroll.??.xhtml'
end
if @opt.cmd =~ /[aAeE]/; ft << 'plain.txt' << '??.plain.txt' << 'plain.??.txt'
end
if @opt.cmd =~ /[g]/; ft << 'wiki.txt' << '??.wiki.txt' << 'wiki.??.txt'
end
if @opt.cmd =~ /N/; ft << 'digest.txt' << '??.digest.txt' << 'digest.??.txt'
end
if @opt.cmd =~ /o/; ft << 'opendocument.odt' << '??.opendocument.odt' << 'opendocument.??.odt'
end
if @opt.cmd =~ /s/; ft << '.sst' << '.ssi' << '.ssm'
end
if @opt.cmd =~ /S/; ft << 'sisupod.zip' << '.kdi'
end
if @opt.mod.inspect =~ /sxm|sxs|xml/; ft << @fnb << '.sxs.xml'
end
if @opt.mod.inspect =~ /sxd/; ft << @fnb << '.sxd.xml'
end
if @opt.mod.inspect =~ /sxn/; ft << @fnb << '.sxn.xml'
end
end
ft=ft.uniq
filetypes=ft.join(',')
@filetypes=if filetypes !~/..+/; '' # -r called alone, copy all
elsif @opt.cmd =~/u/; '' # -u added, copy all, (used to create remote directory tree see output path), not the usual function of -u
elsif filetypes =~/\S+?,\S+/; '*{' + filetypes + '}' # more than one relevant file type
else '*' + filetypes # one relevant file type
end
@source_path=if @fnb and not @fnb.empty?; "#{@env.path.output}/#@fnb"
else @env.path.output
end
@local_sisu_source=if @filetypes =~/\S/; "#@source_path/#@filetypes"
else @source_path
end
end
end
class Clean_output
require 'fileutils'
include FileUtils::Verbose
def initialize(opt)
@opt=opt
z=File_map.new(@opt)
@zap=z.local_sisu_source
if @opt.cmd =~ /[hH]/
@zap=Dir.glob(@zap).join(' ')
if @opt.cmd !~ /w/; @zap.gsub!(/#@source_path\/concordance.html/,'')
end
end
@env=SiSU_Env::Info_env.new
end
def zap
if @zap !~/\/\//; rm_rf(@zap) if FileTest.directory?(@zap)
else puts 'suspect zap request, ignored'
end
#Dir.unlink(@zap) if FileTest.directory?(@zap)
#System_call.new(@zap,'',@cmd).rm
end
def zap_map
if @opt.fnb and not @opt.fnb.empty?
sm="#{@env.path.output}/sitemaps/sitemap_#{@opt.fnb}.xml"
rm(sm) if FileTest.file?(sm)
end
end
end
class Info_remote_host
def initialize
@rc=Get_init.instance.yamlrc
end
def remote_host #see Info_remote remote_host_base_general
r={}
r=if (defined? @rc['remote']['user'] and defined? @rc['remote']['host'])
r[:user]=@rc['remote']['user']
r[:host]=@rc['remote']['host']
r[:path]=if defined? @rc['remote']['path']
@rc['remote']['path']
else ''
end
r[:name]="#{r[:user]}@#{r[:host]}:#{r[:path]}"
r
else
r[:name]='.'
r[:user]=''
r[:host]=''
r[:path]=''
r
#puts "no remote host or user"
end
end
end
class Info_remote < File_map
@@flag_remote=false
require 'socket'
def initialize(opt)
super(opt) #
@opt=opt
@rc=Get_init.instance.yamlrc
end
def remote_host_base_general
SiSU_Env::Info_remote_host.new.remote_host
end
def remote_host_base
remote=remote_host_base_general
#host_ip=IPSocket.getaddress(remote[:host]) unless remote[:host].empty?
@@flag_remote=true if remote[:name] =~/\S+@\S+/ #and host_ip =~/\d+\.\d+\.\d+\.\d+/ #very naive check should be enough /[0-255]+\.[0-255]+\.[0-255]+\.[0-255]+/
#remote[:name]
remote_host_base_general[:name]
end
def scp #sort out later using ruby libraries #not ideal, first time each file is sent, -r must be called separately for subdir to be built
input=@local_sisu_source
output=case @opt.cmd
when /u/; "#{self.remote_host_base}/#{@env.path.stub_pwd}/." #creates remote directory tree, this is not the usual function of u
when /[aAbeEhHNopwxXy]/; "#{self.remote_host_base}/#{@env.path.stub_pwd}/#{@fnb}/."
else "#{self.remote_host_base}/#{@env.path.stub_pwd}/."
end
if (input =~/\S/ and input !~/\/\//) and (output =~/\S/ and output !~/\/\//) and @@flag_remote==true and @opt.cmd !~/U/
System_call.new(input,output).scp
elsif @opt.cmd =~/U/; puts "#{input} -> #{output}"
else puts 'suspect scp request, ignored'
end
end
def rsync
input=@source_path
output="#{self.remote_host_base}/#{@env.path.stub_pwd}/."
if (input =~/\S/ and input !~/\/\//) and (output =~/\S/ and output !~/\/\//) and @@flag_remote==true and @opt.cmd !~/U/
System_call.new(input,output,@opt.cmd).rsync('--delete-after')
elsif @opt.cmd =~/U/
puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
puts "#{input} -> #{output}"
else
puts 'suspect rsync request, ignored'
puts "#{input} -> #{output} remote flag: #@@flag_remote"
puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
end
end
def scp_base #base site
input=@source_path
output="#{remote_host_base}/#{@env.path.stub_pwd}/."
if defined? @rc['permission_set']['remote_base_site'] and @rc['permission_set']['remote_base_site'] and @@flag_remote==true and @opt.cmd !~/U/
puts "begin scp_base: #{input} -> #{output}"
System_call.new("#{input}/#{@env.path.style}/",output).scp
elsif @opt.cmd =~/U/
puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
puts "begin scp_base: #{input} -> #{output}"
puts "#{input}/#{@env.path.style}/ -> #{output}"
else puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
end
end
def scp_base_all #base site
input=@source_path
output="#{remote_host_base}/#{@env.path.stub_pwd}/."
if defined? @rc['permission_set']['remote_base_site'] and @rc['permission_set']['remote_base_site'] and @@flag_remote==true and @opt.cmd !~/U/
puts "begin scp_base_all: #{input} -> #{output}"
System_call.new("#{input}/_sisu/image/",output).scp
System_call.new("#{input}/_sisu/image_local/",output).scp
System_call.new("#{input}/#{@env.path.style}/",output).scp
elsif @opt.cmd =~/U/
puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
puts "scp_base_all: #{input} -> #{output}"
puts "#{input}/_sisu/image/ -> #{output}"
puts "#{input}/_sisu/image_local/ -> #{output}"
puts "#{input}/#{@env.path.style}/ -> #{output}"
else puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
end
end
def rsync_base #base site
input=@source_path
output="#{remote_host_base}/#{@env.path.stub_pwd}/."
if defined? @rc['permission_set']['remote_base_site'] and @rc['permission_set']['remote_base_site'] and @@flag_remote==true and @opt.cmd !~/U/
#puts "begin rsync_base: #{input} -> #{output}"
#System_call.new("#{input}/_sisu/image/",output).rsync
#System_call.new("#{input}/_sisu/image_local/",output).rsync
#System_call.new("#{input}/#{@env.path.style}/",output).rsync
elsif @opt.cmd =~/U/
puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
puts "rsync_base: #{input} -> #{output}"
puts "#{input}/_sisu/image/ -> #{output}"
puts "#{input}/_sisu/image_local/ -> #{output}"
puts "#{input}/#{@env.path.style}/ -> #{output}"
else puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
end
end
def rsync_base_sync #base site
input=@source_path
output="#{remote_host_base}/#{@env.path.stub_pwd}/."
if defined? @rc['permission_set']['remote_base_site'] and @rc['permission_set']['remote_base_site'] and @@flag_remote==true and @opt.cmd !~/U/
puts "begin rsync_base_sync: #{input} -> #{output}"
System_call.new("#{input}/_sisu/image/",output).rsync('--delete-after')
System_call.new("#{input}/_sisu/image_local/",output).rsync('--delete-after')
System_call.new("#{input}/#{@env.path.style}/",output).rsync('--delete-after')
elsif @opt.cmd =~/U/
puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
puts "rsync_base_sync: #{input} -> #{output}"
puts "#{input}/_sisu/image/ -> #{output}"
puts "#{input}/_sisu/image_local/ -> #{output}"
puts "#{input}/#{@env.path.style}/ -> #{output}"
else puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
end
end
def rsync_sitemaps #sitemap directory
input="#@source_path/sitemapindex.xml"
output="#{remote_host_base}/#{@env.path.stub_pwd}/."
if @@flag_remote
#if defined? @rc['permission_set']['remote_base_site'] and @rc['permission_set']['remote_base_site'] #and @@flag_remote==true and @opt.cmd !~/U/
System_call.new(input,output).rsync('--delete-after')
elsif @opt.cmd =~/U/
puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
puts "rsync_sitemaps: #{input} -> #{output}"
else puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
end
end
end
class Info_version }
end
def html_tables
%{ }
end
end
class SiSU_file