# encoding: utf-8
=begin
* Name: SiSU
* Description: a framework for document structuring, publishing and search
* Author: Ralph Amissah
* Copyright: (C) 1997 - 2012, Ralph Amissah, All Rights Reserved.
* License: GPL 3 or later:
SiSU, a framework for document structuring, publishing and search
Copyright (C) Ralph Amissah
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see .
If you have Internet connection, the latest version of the GPL should be
available at these locations:
* SiSU uses:
* Standard SiSU markup syntax,
* Standard SiSU meta-markup syntax, and the
* Standard SiSU object citation numbering and system
* Hompages:
* Download:
* Ralph Amissah
** Description: system environment, resource control and configuration details
=end
@@cX=nil
@@current_document=Dir.pwd #nil #''
@@lang_info=nil
module SiSU_Env
require_relative 'constants' # constants.rb
require 'fileutils'
include FileUtils::Verbose
require 'singleton'
@@noyaml=false
class InfoDate
require 'date'
attr_accessor :dt,:t
def initialize
@dt,@t=Date.today.to_s,Time.now
end
def week
w=@t.strftime('%W')
"#{@t.year}w#{w}"
end
def month
"#{@t.year}#{@t.month}"
end
def year
@t.year
end
def weekonly
@t.strftime('%W')
end
def monthonly
@t.month
end
def year_static
'2012'
end
end
class InfoSystem
require 'rbconfig'
include Singleton
@@user,@@home,@@hostname,@@pwd,@@sisu_etc,@@host,@@arch,@@rbver,@@dir_arch,@@dir_sitearch,@@dir_bin,@@locale,@@rc,@@sisurc_path,@@ad=ENV['USER'],ENV['HOME'],ENV['HOSTNAME'],ENV['PWD'],Config::CONFIG['sysconfdir'] + '/sisu',Config::CONFIG['host'],Config::CONFIG['arch'],%x{ruby -v}.strip,Config::CONFIG['archdir'],Config::CONFIG['sitearchdir'],Config::CONFIG['bindir'],%x{locale charmap}.strip,nil,nil,{} # %x{ruby -v}.strip # Config::CONFIG['rb_ver']
out=Config::CONFIG['localstatedir']
etc=Config::CONFIG['sysconfdir'] + '/sisu'
share=Config::CONFIG['datadir'] + '/sisu'
data=Config::CONFIG['datadir'] + '/doc/sisu'
m=/.+\/(?:src\/)?(\S+)/m # m=/.+?\/(?:src\/)?([^\/]+)$/im # m=/.+\/(\S+)/m
@stub_pwd ||=@@pwd[m,1]
prcss_dir='_sisu_processing_'
prcss_dir_tmp_root="/tmp/#{prcss_dir}"
prcss_dir_stub="#{prcss_dir}/#{@stub_pwd}"
if @@user
tmp_processing="#{prcss_dir_tmp_root}/#{@@user}/#{@stub_pwd}"
tmp_processing_individual="#{prcss_dir_tmp_root}/#{@@user}/#{@stub_pwd}"
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?) \
and ENV['PGPORT']=~/^\d+$/
ENV['PGPORT']
else '5432'
end
IMAGES=:images
SISU_ETC=:sisu_etc
SISU_SHARE=:sisu_share
SAMPLE_DATA_PATH=:sample_data_path
IMAGE_STUB=:image_stub
STYLESHEET_STUB=:stylesheet_stub
IMAGE_LOCAL=:image_local
WEBSERV_PATH=:webserv_path
WEBSERV_MAN=:webserv_man
WEBSERV_PHP=:webserv_php
WEBSERV_CGI=:webserv_cgi
WEBSERV_RSS=:webserv_rss
WEBSERV_SQLITE=:webserv_sqlite
OUTPUT_LOCAL=:output_local
PROCESSING_DIR=:processing_dir
PROCESSING_PATH=:processing_path
PROCESSING_DIR_TMP_ROOT=:processing_dir_tmp_root
PROCESSING_PATH_TMP_BASE=:processing_path_tmp_base
PROCESSING_DAL=:processing_dal
PROCESSING_TUNE=:processing_tune
PROCESSING_LATEX=:processing_latex
PROCESSING_TEXINFO=:processing_texinfo
PROCESSING_LOUT=:processing_lout
PROCESSING_SQLITE=:processing_sqlite
PROCESSING_POSTGRESQL=:processing_postgresql
PROCESSING_ENCODING=:processing_encoding
PROCESSING_GIT=:processing_git
PAPERSIZE=:papersize
#LANGUAGE=:language
#LANGUAGE_CODE=:language_code
MULTILINGUAL=:multilingual
BUNDLE=:bundle
CONCORD_MAX=:concord_max
DIGEST=:digest
WEBSERV_HOST_CGI=:webserv_host_cgi
WEBSERV_PORT_CGI=:webserv_port_cgi
POSTGRESQL_USER=:postgresql_user
POSTGRESQL_PORT=:postgresql_port
SQLITE_USER=:sqlite_user
SQLITE_PATH=:sqlite_path
SQLITE_PORT=:sqlite_port
DEFAULT_DIR={
IMAGES => '_sisu/image',
SISU_ETC => etc,
SISU_SHARE => share,
SAMPLE_DATA_PATH => data,
IMAGE_STUB => '_sisu/image',
STYLESHEET_STUB => '_sisu/css',
IMAGE_LOCAL => @@pwd + '/_sisu/image',
WEBSERV_PATH => out + '/www',
#WEBSERV_DIR => www, # uncomment for urls...
#WEBSERV_IMAGE => out + '/www/_sisu/image',
WEBSERV_MAN => out + '/www/man', #alter
WEBSERV_PHP => out + '/www/php',
WEBSERV_CGI => '/usr/lib/cgi-bin',
WEBSERV_RSS => out + '/www/feed',
WEBSERV_SQLITE => out + '/www/sqlite',
OUTPUT_LOCAL => @@home + '/sisu_www',
PROCESSING_DIR => processing_dir,
PROCESSING_PATH => processing_pth,
PROCESSING_DIR_TMP_ROOT => prcss_dir_tmp_root,
PROCESSING_PATH_TMP_BASE => processing_pth,
PROCESSING_DAL => 'dal',
PROCESSING_TUNE => 'tune',
PROCESSING_LATEX => 'tex',
PROCESSING_TEXINFO => 'texinfo',
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',
#LANGUAGE_CODE => 'en', #change, unecessary duplication though currently used
MULTILINGUAL => false,
BUNDLE => false,
CONCORD_MAX => 260000,
DIGEST => 'sha256',
WEBSERV_HOST_CGI => ' http://localhost',
WEBSERV_PORT_CGI => 8081, #8111,8123,8081
POSTGRESQL_USER => @@user, #'ralph', # change user !!!
POSTGRESQL_PORT => port_pgsql,
#POSGRESQL_LINKS_PATH => '',
SQLITE_USER => @@user,
SQLITE_PATH => @@user, #??
SQLITE_PORT => '**',
}
@@default_dir=DEFAULT_DIR
m=/.+\/(?:src\/)?(\S+)/m # m=/.+?\/(?:src\/)?([^\/]+)$/im # m=/.+\/(\S+)/m
stub_pwd=@@pwd[m,1]
@@rc_path=[
"#{@@pwd}/.sisu/#{SiSU_version_dir}",
"#{@@pwd}/.sisu",
"#{@@pwd}/_sisu/#{SiSU_version_dir}",
"#{@@pwd}/_sisu",
"#{@@home}/.sisu/#{SiSU_version_dir}",
"#{@@home}/.sisu",
"#{@@sisu_etc}/#{SiSU_version_dir}",
]
@@yamlrc_path=@@rc_path
#@@yamlrc_path=(stub_pwd !~/^sisupod$/) \
#? (["#{@@pwd}/_sisu/#{SiSU_version_dir}","#{@@pwd}/_sisu","#{@@home}/.sisu/#{SiSU_version_dir}","#{@@home}/.sisu","#{@@sisu_etc}/#{SiSU_version_dir}"])
#: ["#{@@home}/.sisu/#{SiSU_version_dir}","#{@@home}/.sisu","#{@@sisu_etc}/#{SiSU_version_dir}"] #security policy: prevent reading of sisurc.yml in sisupod
@@ad_path=(stub_pwd !~/^sisupod$/) \
? ([
"#{@@pwd}/.sisu/skin/yml",
"#{@@pwd}/_sisu/skin/yml",
"#{@@home}/.sisu/skin/yml",
"#{@@sisu_etc}/skin/yml",
])
: ["#{@@home}/.sisu",@@sisu_etc]
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,:yamlrc_path,:ad_path
def initialize
@user,@home,@hostname,@pwd,@sisu_etc,@host,@arch,@rbver,@dir_arch,@dir_sitearch,@dir_bin,@locale,@default_dir,@rc_path,@yamlrc_path,@ad_path=\
@@user,@@home,@@hostname,@@pwd,@@sisu_etc,@@host,@@arch,@@rbver,@@dir_arch,@@dir_sitearch,@@dir_bin,@@locale,@@default_dir,@@rc_path,@@yamlrc_path,@@ad_path
#note rbver is duplicated in InfoVersion
end
end
class Load
def initialize(prog,mandatory=false)
@prog,@mandatory=prog,mandatory
end
def prog
load_prog=false
pp=''
$:.each do |reqpath|
if FileTest.exist?("#{reqpath}/#{@prog}.rb")
load_prog=true
break
end
end
if load_prog \
and @prog=~/dbi/
require 'dbi' #revisit
end
if load_prog
require @prog
else
@mandatory \
? (SiSU_Screen::Ansi.new(@cmd,"module required: #{@prog}").warn)
: (SiSU_Screen::Ansi.new(@cmd,"#{@prog} load requested").warn)
end
load_prog
end
def prog?
load_prog=false
$:.each do |reqpath|
if FileTest.exist?("#{reqpath}/#{@prog}.rb"); load_prog=true
break
end
end
load_prog
end
end
class GetInit < InfoSystem
include Singleton
@@noyaml=false
@@rc,@@sisurc_path,@@vz,@@tx=nil,nil,nil,nil
@@ad={ promo: nil, promo_list: nil, flag_promo: false }
attr_accessor :yaml
def initialize
super()
end
def skin
@@vz ||=SiSU_Viz::Skin.new
end
def tex
@@tx ||=SiSU_Viz::TeX.new
end
def sisu_yaml
def rc
unless @@rc
@yamlrc_path.each do |v|
if @@noyaml \
or FileTest.exist?("#{v}/noyaml")
puts "WARNING - YAML loading switched off, to enable delete the file:\n\t#{v}/noyaml\n\n" unless @@noyaml
@@noyaml=true
break
else
f='sisurc.yml'
if FileTest.exist?("#{v}/#{f}")
require 'yaml'
@@sisurc_path="#{v}/#{f}"
@@rc=YAML::load(File::open(@@sisurc_path))
break
end
unless @@rc
f='sisurc.yaml'
if FileTest.exist?("#{v}/#{f}")
require 'yaml'
@@sisurc_path="#{v}/#{f}"
@@rc=YAML::load(File::open(@@sisurc_path))
break
end
end
end
end
end
@@rc
end
def rc_path
rc
@@sisurc_path
end
self
end
def ads #WORK AREA
tell_no_yaml='WARNING - YAML loading switched off, to enable delete the file:'
@ad_path.each do |v|
if @@noyaml \
or FileTest.exist?("#{v}/noyaml")
puts tell_no_yaml + "\n\t#{v}/noyaml\n" unless @@noyaml
@@noyaml=true
break
else
if FileTest.exist?("#{v}/list.yml")
unless @@ad[:promo_list]
require 'yaml'
@@ad[:promo_list] ||= YAML::load(File::open("#{v}/list.yml"))
end
@@ad[:flag_promo]=true
break
end
@@ad[:flag_promo]=false
end
end
@ad_path.each do |v|
if @@noyaml \
or FileTest.exist?("#{v}/noyaml")
puts tell_no_yaml + "\n\t#{v}/noyaml\n" unless @@noyaml
@@noyaml=true
break
else
if FileTest.exist?("#{v}/promo.yml")
unless @@ad[:promo]
require 'yaml'
@@ad[:promo] ||= YAML::load(File::open("#{v}/promo.yml"))
end
@@ad[:flag_promo]=true
break
end
@@ad[:flag_promo]=false
end
end
@@ad
end
end
class EnvCall
@@rc,@@fns,@@fnn,@@fnb,@@fnt,@@flv,@@fnz=nil,nil,nil,nil,nil,nil,nil
@@ad={}
attr_accessor :rc,:fnn,:fnb,:fnt,:fnv,:fnz,:ad
def initialize(fns='')
super()
@fns=fns
@sys=InfoSystem.instance
@rc=GetInit.instance.sisu_yaml.rc
@ad=GetInit.instance.ads
if @fns \
and @fns != '' \
and @fns !=@@fns
@@fns,@@fnn,@@fnb,@@fnt,@@flv,@@fnz=@fns,nil,nil,nil,nil,nil
end
if @fns \
and @fns != '' #watch
m=/((.+?)(?:\~\w\w(?:_\w\w)?)?)\.((?:-|ssm\.)?sst|ssm|ssi)$/
@@fnn ||=@fns[m,1]
@@fnb ||=@fns[m,2]
@@fnt ||=@fns[m,3]
@@flv ||=document_language_versions_found[:f]
unless @@fns =~/\S+?\.txz/
@@fnz ||=if @@fns =~/(?:\~\S{2,3})?\.(?:ssm\.sst|ssm)$/; @@fnb + '.ssm.txz'
elsif @@fnb; @@fnb + '.sst.txz'
else '' # e.g. termsheet
end
end
end
@fnn,@fnb,@fnt,@flv,@fnz=@@fnn,@@fnb,@@fnt,@@flv,@@fnz
end
def output_dir_structure
def by_language_code?
x=if defined? @rc['output_dir_structure_by'] \
and @rc['output_dir_structure_by'] =~/language/
true
elsif defined? @rc['output_structure']['by_language'] \
and @rc['output_structure']['by_language'] ==true
true
else false
end
end
def by_filetype?
x=if by_language_code?
false
elsif defined? @rc['output_dir_structure_by'] \
and @rc['output_dir_structure_by'] =~/filetype/
true
elsif defined? @rc['output_structure']['by_filetype'] \
and @rc['output_structure']['by_filetype'] ==true
true
else false
end
end
def by_filename?
x=if by_language_code?
false
elsif by_filetype?
false
elsif defined? @rc['output_dir_structure_by'] \
and @rc['output_dir_structure_by'] =~/filename/
true
elsif defined? @rc['output_structure']['by_filename'] \
and @rc['output_structure']['by_filename'] ==true
true
else true
end
end
def multilingual?
by_language_code?
end
def by?
by=if by_language_code?
'language'
elsif by_filetype?
'filetype'
elsif by_filename?
'filename'
else
'filename'
end
end
self
end
def document_language_versions_found #REVISIT
@fn={}
filename=(@fns =~/\.ssm\.sst$/) \
? @fns.gsub(/\.ssm\.sst$/,'.ssm')
: @fns
unless (filename.nil? \
or filename.empty?)
if output_dir_structure.by_language_code?
m=/((.+?)(?:\~\w{2,3})?)\.(sst|ssm)$/
@fn[:b],@fn[:m],@fn[:t]=filename[m,1],filename[m,2],filename[m,3]
else m=/(.+?)\.(sst|ssm)$/
@fn[:b]=@fn[:m]=filename[m,1]
@fn[:t]=filename[m,2]
end
end
lng_base=SiSU_Env::InfoEnv.new.language_default_set
lang=SiSU_Env::StandardiseLanguage.new
langs=lang.codes
x=[]
if FileTest.file?("#{@fn[:m]}.#{@fn[:t]}")
n=@fn[:m].gsub(/^.+?\//,'')
n =n + '.' + @fn[:t]
x << { f: "#{@fn[:m]}.#{@fn[:t]}", l: lng_base, n: n }
end
#x << { f: "#{@fns}", l: lng_base }
langs.each do |l|
lng=SiSU_Env::StandardiseLanguage.new(l)
if FileTest.file?("#{@fn[:m]}~#{lng.code}.#{@fn[:t]}")
x << { f: "#{@fn[:m]}~#{lng.code}.#{@fn[:t]}", l: lng.code }
elsif FileTest.file?("#{@fn[:m]}~#{lng.name}.#{@fn[:t]}")
x << { f: "#{@fn[:m]}~#{lng.name}.#{@fn[:t]}", l: lng.code }
end
if FileTest.file?("#{lng.code}/#{@fn[:m]}~#{lng.code}.#{@fn[:t]}")
if FileTest.file?("#{lng.code}/#{@fn[:m]}~#{lng.code}.#{@fn[:t]}")
x << { f: "#{lng.code}/#{@fn[:m]}~#{lng.code}.#{@fn[:t]}", l: lng.code }
elsif FileTest.file?("#{lng.code}/#{@fn[:m]}~#{lng.name}.#{@fn[:t]}")
x << { f: "#{lng.code}/#{@fn[:m]}~#{lng.name}.#{@fn[:t]}", l: lng.code }
end
end
if FileTest.file?("#{lng.code}/#{@fn[:m]}.#{@fn[:t]}")
if FileTest.file?("#{lng.code}/#{@fn[:m]}.#{@fn[:t]}")
x << { f: "#{lng.code}/#{@fn[:m]}.#{@fn[:t]}", l: lng.code }
elsif FileTest.file?("#{lng.code}/#{@fn[:m]}.#{@fn[:t]}")
x << { f: "#{lng.code}/#{@fn[:m]}.#{@fn[:t]}", l: lng.code }
end
end
end
@fn[:f]=x
@fn
end
def published_manifests?(output_base)
ob=output_base
@fn={}
@m=[]
unless (@fns.nil? \
or @fns.empty?)
if output_dir_structure.by_language_code?
m=/((.+?)(?:\~\w{2,3})?)\.((?:-|ssm\.)?sst$)/
@fn[:b],@fn[:m],@fn[:t]=@fns[m,1],@fns[m,2],@fns[m,3]
else m=/(.+?)\.((?:-|ssm\.)?sst$)/
@fn[:b]=@fn[:m]=@fns[m,1]
@fn[:t]=@fns[m,2]
end
end
lang=SiSU_Env::StandardiseLanguage.new
langs=lang.codes
x=[]
if FileTest.file?("#{@fn[:m]}.#{@fn[:t]}"); x << "#{@fn[:m]}.#{@fn[:t]}"
end
dir=SiSU_Env::InfoEnv.new(@fns)
@m << { m: 'sisu_manifest.html', l: 'English' } #fix later, default language
langs.each do |l|
lng=SiSU_Env::StandardiseLanguage.new(l)
fns_c="#{@fn[:m]}~#{lng.code}.#{@fn[:t]}"
fns_l="#{@fn[:m]}~#{lng.name}.#{@fn[:t]}"
if FileTest.file?(fns_c)
fn_set_lang=SiSU_Env::StandardiseLanguage.new.file_to_language(fns_c) #reconsider file_to_language
lng=fn_set_lang[:n]
fn=SiSU_Env::EnvCall.new(fns_c).lang(fn_set_lang[:c])
@m << { m: fn[:manifest], l: lng }
elsif FileTest.file?(fns_l)
fn_set_lang=SiSU_Env::StandardiseLanguage.new.file_to_language(fns_l) #reconsider file_to_language
@fnl=dir.i18n.lang_filename(fn_set_lang[:c])
fn=SiSU_Env::EnvCall.new(fns_l).lang(fn_set_lang[:c])
@m << { m: fn[:manifest], l: lng }
end
end
@m.uniq!
@m
end
def filename(code,name,suffix)
#d=SiSU_Env::InfoEnv.new(@fns)
#fnl=d.i18n.lang_filename(code)
"#{name}#{suffix}"
#if code
# "#{fnl[:pre]}#{name}#{fnl[:mid]}#{suffix}#{fnl[:post]}"
#else "#{name}#{suffix}"
#end
end
def lang(code)
@fn={
html: filename(code,'','.html'),
book_index: filename(code,'book_index','.html'),
concordance: filename(code,'concordance','.html'),
sax: filename(code,'sax','.xml'),
dom: filename(code,'dom','.xml'),
docbook: filename(code,'docbook','.xml'),
xhtml: filename(code,'scroll','.xhtml'),
pdf_l: filename(code,'','.pdf'),
pdf_p: filename(code,'','.pdf'),
pdf_l_a4: filename(code,"a4",'.pdf'),
pdf_p_a4: filename(code,"a4",'.pdf'),
pdf_l_a5: filename(code,"a5",'.pdf'),
pdf_p_a5: filename(code,"a5",'.pdf'),
pdf_l_b5: filename(code,"b5",'.pdf'),
pdf_p_b5: filename(code,"b5",'.pdf'),
pdf_l_letter: filename(code,"letter",'.pdf'),
pdf_p_letter: filename(code,"letter",'.pdf'),
pdf_l_legal: filename(code,"legal",'.pdf'),
pdf_p_legal: filename(code,"legal",'.pdf'),
toc: filename(code,'toc','.html'),
doc: filename(code,fnb,'.html'),
index: filename(code,'index','.html'),
po: filename(code,@fns,'.po'),
pot: filename(code,@fns,'.pot'),
odf: filename(code,'','.odt'),
epub: filename(code,'','.epub'),
plain: filename(code,'','.txt'),
manpage: filename(code,'','.1'), #fix, section number
wiki: filename(code,'wiki','.txt'),
digest: filename(code,'digest','.txt'),
metadata: filename(code,'metadata','.html'), #chk
manifest: filename(code,'manifest','.html'),
oai_pmh: filename(code,'oai_pmh','.xml'),
sitemap: filename(code,'sitemap','.xml'),
sitemap_touch: filename(code,"sitemap_#{fnb}",'.xml'),
sxs: filename(code,fnb,'.sxs.xml'),
sxd: filename(code,fnb,'.sxd.xml'),
sxn: filename(code,fnb,'.sxn.xml'),
sisupod: filename(nil,@fnz,''),
book_idx_html: filename(code,'book_index','.html'),
book_idx_epub: filename(code,'book_index','.xhtml'),
epub_concord: filename(code,'concordance','.xhtml'),
}
@fn
end
end
class SystemCall
@@locale_flag=false
def initialize(input='',output='',cmd='')
@input,@output,@cmd=input,output,cmd
@prog=SiSU_Env::InfoProgram.new
@sys=InfoSystem.instance
end
def program_found?(program)
found=`which #{program}` #`whereis #{program}`
(found =~/bin\/#{program}\b/) ? true : false
end
def locale #locales utf8 or other
unless @@locale_flag
@@locale_flag=true
end
@sys.locale
end
def file_encoding(filename,cmd='') #file encoding
program='file'
fnsp=SiSU_Env::InfoEnv.new(filename).source_file_with_path
if program_found?(program)
encoding=%x{file -L #{fnsp}}.strip
encoding.gsub!(/#{fnsp}:(\s+|$)/,'')
encoding=if encoding \
and not encoding.empty?
encoding
else 'UTF-8 assumed, encoding undetermined'
end
puts encoding if cmd =~/[VM]/
encoding
else encoding='UTF-8 assumed, file encoding check program unavailable'
end
end
def wc #word count
program='wc'
if program_found?(program) \
and locale !~/utf-?8/i
true
else
program_ref="(not available)" unless program_found?(program)
program_ref="(UTF-8)" if locale =~/utf-?8/i
false
end
end
def rcs #rcs for document markup data
program='rcs'
program_ref="\n\t\tdocument version information requested"
if program_found?(program); true
else puts "\tWARN: #{program} is not installed #{program_ref}" #if @cmd =~/v/
false
end
end
def cvs #cvs for document markup data
program='cvs'
program_ref="\n\t\tdocument version information requested"
if program_found?(program); true
else puts "\tWARN: #{program} is not installed #{program_ref}" #if @cmd =~/v/
false
end
end
def openssl #openssl for digests
program='openssl'
program_ref="\n\t\tused to generate requested source document identification digest"
if program_found?(program); true
else puts "\tWARN: #{program} is not installed #{program_ref}" #if @cmd =~/v/
false
end
end
def md5(filename) #md5 dgst
program='openssl'
program_ref="\n\t\tmd5 digest requested"
if program_found?(program)
pwd=Dir.pwd
Dir.chdir(File.dirname(filename))
dgst=%x{openssl dgst -md5 #{File.basename(filename)}}.strip #use file name without file path
Dir.chdir(pwd)
dgst.scan(/\S+/)
else puts "\tWARN: #{program} is not installed #{program_ref}" #if @cmd =~/v/
false
end
end
def sha256(filename) #sha dgst
program='openssl'
program_ref="\n\t\tsha digest requested"
if program_found?(program)
pwd=Dir.pwd
Dir.chdir(File.dirname(filename))
dgst=%x{openssl dgst -sha256 #{File.basename(filename)}}.strip #use file name without file path
Dir.chdir(pwd)
dgst.scan(/\S+/)
else puts "\tWARN: #{program} is not installed #{program_ref}" #if @cmd =~/v/
false
end
end
def psql #psql
program='psql'
program_ref="\n\t\tpsql requested"
if program_found?(program); true
else puts "\tWARN: #{program} is not installed #{program_ref}" #if @cmd =~/v/
false
end
end
def create_pg_db(dbname_stub=nil) #createdb
unless dbname_stub
@pwd ||=Dir.pwd
m=/.+\/(?:src\/)?(\S+)/im # m=/.+?\/(?:src\/)?([^\/]+)$/im # m=/.+\/(\S+)/m
dbname_stub=@pwd[m,1]
end
program='createdb'
db_name="#{Db[:name_prefix]}#{dbname_stub}"
program_ref="\n\t\tcreatedb dbname #{db_name} #for postgresql database creation"
(program_found?(program)) \
? system("#{program} #{dbname_name}")
: (puts "\tWARN: #{program} is not available #{program_ref}")
end
def relaxng(cmd='') #trang - convert between different schema languages for XML
program='trang'
program_ref="\n\t\tsee "
(program_found?(program)) \
? system("#{program} #{@input} #{@output}")
: (puts "\tWARN: #{program} is not installed #{program_ref}" if cmd =~/V/)
end
def qrencode #qrcode - for generating QR code
program='qrencode'
program_ref="\n\t\tsee "
found=(program_found?(program)) ? true : false
found \
? (system(%{
echo "#{@input}" | #{program} -s 3 -o #{@output}
}))
: (puts "\tWARN: #{program} is not installed #{program_ref}" if cmd =~/V/)
#found
end
def imagemagick #imagemagick is a image manipulation program
program='identify'
program_ref="\n\t\tsee "
found=(program_found?(program)) ? true : false
puts "\tWARN: #{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 "
found=(program_found?(program)) ? true : false
puts "\tWARN: #{program} is not installed #{program_ref}" unless found
found
end
def well_formed? #tidy - check for well formed xml xhtml etc.
program=@prog.tidy
program_ref="\n\t\tsee "
(program_found?(program)) \
? system("#{@prog.tidy} -xml #{@input} > #{@output}")
: (puts "\tWARN: #{program} is not installed #{program_ref}")
end
def tex2pdf_engine
prog=['xetex','xelatex','pdflatex','pdfetex','pdftex']
@pdfetex_flag=false
@cmd ||=''
@texpdf=nil
prog.each do |program|
if program_found?(program)
@texpdf=program if program =~/xetex|xelatex|pdftex|pdflatex/
@pdfetex_flag=true
break
end
end
if @pdfetex_flag==false
@texpdf=prog.join(', ')
end
@texpdf
end
def latex2pdf(md,papersize='a4') #convert from latex to pdf
tell=((@cmd =~/[MVv]/) ? '' : '> /dev/null' )
mode='batchmode' #mode='nonstopmode'
program_ref="\n\t\tSee http://www.tug.org/applications/pdftex/\n\t\tOn Debian this is is included in tetex-extra"
texpdf=tex2pdf_engine
if @pdfetex_flag;
texpdf_cmd=case texpdf
when /xetex/
@input =~/landscape\.tex$/ \
? %{#{texpdf} -interaction=#{mode} -fmt=xelatex -papersize="#{papersize} -l" #{@input} #{tell}\n}
: %{#{texpdf} -interaction=#{mode} -fmt=xelatex -papersize="#{papersize}" #{@input} #{tell}\n}
when /xelatex/
@input =~/landscape\.tex$/ \
? %{#{texpdf} -interaction=#{mode} -papersize="#{papersize} -l" #{@input} #{tell}\n}
: %{#{texpdf} -interaction=#{mode} -papersize="#{papersize}" #{@input} #{tell}\n}
when /pdftex/; "#{texpdf} -interaction=#{mode} -fmt=pdflatex #{@input} #{tell}\n"
when /pdflatex/; "#{texpdf} -interaction=#{mode} #{@input} #{tell}\n"
end
system(texpdf_cmd)
else puts "\tWARN: none of the following programs are installed: #{program[0]}, #{program[1]}, #{program[2]} is installed. #{program_ref}"
end
end
def makeinfo #texinfo
program='makeinfo'
program_ref="\n\t\tsee http://www.gnu.org/software/texinfo/"
(program_found?(program)) \
? system("#{program} #{@input}\n")
: (puts "\tWARN: #{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}") \
#: (puts "\tWARN: #{program} not found" )
end
def rsync(action='',chdir=nil)
program='rsync'
if program_found?(program)
vb=if @cmd =~/q/; 'q'
elsif @cmd =~/v/; 'v'
else ''
end
msg=''
msg=" && echo 'OK: #{@input} -> #{@output}'" unless @cmd =~/q/
rsync_cmd="rsync -az#{vb} #{action} #{@input} #{@output}"
puts rsync_cmd if @cmd =~/[vVM]/
dir_change,dir_return='',''
if chdir \
&& chdir != Dir.pwd
dir_change=Dir.chdir(chdir)
dir_return=Dir.pwd
end
dir_change
system("
#{rsync_cmd} #{msg}
")
dir_return
else puts "\tWARN: #{program} not found"
end
end
def rm
if @cmd =~/^-Z[mMvVq]*$/; FileUtils::rm_rf(@input)
elsif @cmd =~/V/; FileUtils::rm(@input)
elsif @cmd !~/q/; FileUtils::rm(@input)
elsif @cmd =~/q/; FileUtils::rm(@input)
else puts "\tWARN: operation ignored"
end
end
end
class StandardiseLanguage
require_relative 'i18n' # i18n.rb
def initialize(l='')
@language=(l.nil? || l.empty?) \
? SiSU_Env::InfoEnv.new.language_default_set
: l
@r=%{(?:#{Px[:lng_lst].join('|')})}
@lang_info=SiSU_i18n::Languages.new
end
def lang_lst # from i18n
@@lang_info ||=@lang_info.language.list
end
def lang(l='') # from i18n
x=if l =~/^#{@r}$/
@lang_info.language.list[l]
elsif @language =~/^#{@r}$/
@lang_info.language.list[@language]
else nil
end
end
def language
lng={}
case @language
when /^am$|Amharic/i; d,c,l=false,lang_lst['am'][:c], lang_lst['am'][:n]
when /^bg$|Bulgarian/i; d,c,l=false,lang_lst['bg'][:c], lang_lst['bg'][:n]
when /^bn$|Bengali/i; d,c,l=false,lang_lst['bn'][:c], lang_lst['bn'][:n]
when /^br$|Breton/i; d,c,l=false,lang_lst['br'][:c], lang_lst['br'][:n]
when /^ca$|Catalan/i; d,c,l=false,lang_lst['ca'][:c], lang_lst['ca'][:n]
when /^cs$|Czech/i; d,c,l=false,lang_lst['cs'][:c], lang_lst['cs'][:n]
when /^cy$|Welsh/i; d,c,l=false,lang_lst['cy'][:c], lang_lst['cy'][:n]
when /^da$|Danish|Dansk/i; d,c,l=false,lang_lst['da'][:c], lang_lst['da'][:n]
when /^de$|German/i; d,c,l=false,lang_lst['de'][:c], lang_lst['de'][:n]
when /^el$|Greek/i; d,c,l=false,lang_lst['el'][:c], lang_lst['el'][:n]
when /^en$|English/i; d,c,l=false,lang_lst['en'][:c], lang_lst['en'][:n]
when /^eo$|Esperanto/i; d,c,l=false,lang_lst['eo'][:c], lang_lst['eo'][:n]
when /^es$|Spanish|Espanol/i; d,c,l=false,lang_lst['es'][:c], lang_lst['es'][:n]
when /^et$|Estonian/i; d,c,l=false,lang_lst['et'][:c], lang_lst['et'][:n]
when /^eu$|Basque/i; d,c,l=false,lang_lst['eu'][:c], lang_lst['eu'][:n]
when /^fi$|Finnish|Finsk|Suomi/i; d,c,l=false,lang_lst['fi'][:c], lang_lst['fi'][:n]
when /^fr$|French|Francais/i; d,c,l=false,lang_lst['fr'][:c], lang_lst['fr'][:n]
when /^ga$|Irish/i; d,c,l=false,lang_lst['ga'][:c], lang_lst['ga'][:n]
when /^gl$|Galician/i; d,c,l=false,lang_lst['gl'][:c], lang_lst['gl'][:n]
when /^he$|Hebrew/i; d,c,l=false,lang_lst['he'][:c], lang_lst['he'][:n]
when /^hi$|Hindi/i; d,c,l=false,lang_lst['hi'][:c], lang_lst['hi'][:n]
when /^hr$|Croatian/i; d,c,l=false,lang_lst['hr'][:c], lang_lst['hr'][:n]
when /^hy$|Armenian/i; d,c,l=false,lang_lst['hy'][:c], lang_lst['hy'][:n]
when /^ia$|Interlingua/i; d,c,l=false,lang_lst['ia'][:c], lang_lst['ia'][:n]
when /^is$|Icelandic/i; d,c,l=false,lang_lst['is'][:c], lang_lst['is'][:n]
when /^it$|Italian/i; d,c,l=false,lang_lst['it'][:c], lang_lst['it'][:n]
when /^la$|Latin/i; d,c,l=false,lang_lst['la'][:c], lang_lst['la'][:n]
when /^lo$|Lao/i; d,c,l=false,lang_lst['lo'][:c], lang_lst['lo'][:n]
when /^lt$|Lithuanian/i; d,c,l=false,lang_lst['lt'][:c], lang_lst['lt'][:n]
when /^lv$|Latvian/i; d,c,l=false,lang_lst['lv'][:c], lang_lst['lv'][:n]
when /^ml$|Malayalam/i; d,c,l=false,lang_lst['ml'][:c], lang_lst['ml'][:n]
when /^mr$|Marathi/i; d,c,l=false,lang_lst['mr'][:c], lang_lst['mr'][:n]
when /^nl$|Dutch/i; d,c,l=false,lang_lst['nl'][:c], lang_lst['nl'][:n]
when /^no$|Norwegian|Norsk/i; d,c,l=false,lang_lst['no'][:c], lang_lst['no'][:n]
when /^nn$|Norwegian Nynorsk/i; d,c,l=false,lang_lst['nn'][:c], lang_lst['nn'][:n]
when /^oc$|Occitan/i; d,c,l=false,lang_lst['oc'][:c], lang_lst['oc'][:n]
when /^pl$|Polish/i; d,c,l=false,lang_lst['pl'][:c], lang_lst['pl'][:n]
when /^pt$|Portuguese/i; d,c,l=false,lang_lst['pt'][:c], lang_lst['pt'][:n]
when /^pt_BR$|Portuguese Brazil/i; d,c,l=false,lang_lst['pt_BR'][:c], lang_lst['pt_BR'][:n]
when /^ro$|Romanian/i; d,c,l=false,lang_lst['ro'][:c], lang_lst['ro'][:n]
when /^ru$|Russian/i; d,c,l=false,lang_lst['ru'][:c], lang_lst['ru'][:n]
when /^sa$|Sanskrit/i; d,c,l=false,lang_lst['sa'][:c], lang_lst['sa'][:n]
when /^se$|Sami/i; d,c,l=false,lang_lst['se'][:c], lang_lst['se'][:n]
when /^sk$|Slovak/i; d,c,l=false,lang_lst['sk'][:c], lang_lst['sk'][:n]
when /^sl$|Slovenian/i; d,c,l=false,lang_lst['sl'][:c], lang_lst['sl'][:n]
when /^sq$|Albanian/i; d,c,l=false,lang_lst['sq'][:c], lang_lst['sq'][:n]
when /^sr$|Serbian/i; d,c,l=false,lang_lst['sr'][:c], lang_lst['sr'][:n]
when /^sv$|Swedish|Svensk/i; d,c,l=false,lang_lst['sv'][:c], lang_lst['sv'][:n]
when /^ta$|Tamil/i; d,c,l=false,lang_lst['ta'][:c], lang_lst['ta'][:n]
when /^te$|Telugu/i; d,c,l=false,lang_lst['te'][:c], lang_lst['te'][:n]
when /^th$|Thai/i; d,c,l=false,lang_lst['th'][:c], lang_lst['th'][:n]
when /^tk$|Turkmen/i; d,c,l=false,lang_lst['tk'][:c], lang_lst['tk'][:n]
when /^tr$|Turkish/i; d,c,l=false,lang_lst['tr'][:c], lang_lst['tr'][:n]
when /^uk$|Ukranian/i; d,c,l=false,lang_lst['uk'][:c], lang_lst['uk'][:n]
when /^ur$|Urdu/i; d,c,l=false,lang_lst['ur'][:c], lang_lst['ur'][:n]
when /^us|American$|/i; d,c,l=false,lang_lst['en'][:c], lang_lst['en'][:n]
when /^vi$|Vietnamese/i; d,c,l=false,lang_lst['vi'][:c], lang_lst['vi'][:n]
else d,c,l=true, lang_lst['en'][:c], lang_lst['en'][:n] #default
end
lng[:d],lng[:c],lng[:n]=d,c,l
lng
end
def name
language[:n].downcase
end
def title
language[:n]
end
def code
language[:c]
end
def tex_name
language[:xlp]
end
def file_to_language(file) # used, fix and remove
m=/.+?\~(\w{2,3})\.(?:-|ssm\.)?sst$/
@language=if file =~m ; file[m,1]
else ''
end
language
end
def codes
# Language List po4a
#
# Px[:lng_lst]=%w[am bg bn br ca cs cy da de el en eo es et eu fi fr ga gl he hi hr hy ia is it la lo lt lv ml mr nl nn no oc pl pt pt_BR ro ru sa se sk sl sq sr sv ta te th tk tr uk ur us vi]
# see polyglossia for subset
#
# also note ISO_639-2
#
#
Px[:lng_lst] # constants.rb
end
end
class InfoEnv < EnvCall
require 'pathname'
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,: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)
super() #you may not want to re-execute this static info so frequently!
@fns,@md=fns,md
@env=SiSU_Env::EnvCall.new(fns) if fns
fnb=if @md \
and defined? @md.fnb
@md.fnb
elsif defined? @env.fnb \
and @env.fnb
@env.fnb
elsif not @fns.nil? \
and not @fns.empty?
m=/(.+)?\.(?:(?:-|ssm\.)?sst|ssm)$/m
@fns[m,1] if not @fns.empty?
end
if fnb; @@fb ||=fnb
end
@sys=InfoSystem.instance
@fnb ||=@@fb #clean up this... used primarily for zap which is not passed normal parameters
@fixed_websev_root='' # @home
@pwd=@@pwd=Dir.pwd
m=/.+\/(?:src\/)?(\S+)/m # m=/.+?\/(?:src\/)?([^\/]+)$/im # m=/.+\/(\S+)/m
@stub_pwd=@@pwd[m,1]
@stub_txt= @stub_pwd + '/txt'
@stub_html= @stub_pwd + '/html'
@stub_epub= @stub_pwd + '/epub'
@stub_odt= @stub_pwd + '/odt'
@stub_pdf= @stub_pwd + '/pdf'
@stub_manifest=@stub_pwd + '/manifest'
@stub_odt= @stub_pwd + '/odt'
@stub_src= @stub_pwd + '/src'
@stub_pod= @stub_pwd + '/pod'
@stub_md= @stub_pwd + '/sisu_site_metadata'
pt=Pathname.new(Dir.pwd)
stub=if output_dir_structure.by_language_code?
r=Px[:lng_lst].join('|')
stub=if Dir.pwd =~/.+?\/([^\/]+)(?:\/(#{r})$)/
lng=pt.split[-1].to_s
lng_part='/' + lng
base=pt.split[0].split[-1].to_s
else
lng_part='/' + language_default_set
base=pt.split[-1].to_s
end
base + lng_part
elsif output_dir_structure.by_filetype?
pt.split[-1].to_s
elsif output_dir_structure.by_filename?
''
end
@stub_set_manifest=stub + '/manifest'
end
def user
@sys.user
end
def hostname
@sys.hostname
end
def host
@sys.host
end
def arch
@sys.arch
end
def rbver
@sys.rbver
end
def locale
@sys.locale
end
def concord_max
((defined? @rc['processing']['concord_max']) \
&& @rc['processing']['concord_max']) \
? @rc['processing']['concord_max']
: (defaults[:concord_max])
end
def language_default_set #set directory (default) language
((defined? @rc['default']['language']) \
&& @rc['default']['language'] =~/\S+/) \
? @rc['default']['language']
: 'en'
end
def markup_emphasis
if defined? @rc['default']['emphasis'] \
and @rc['default']['emphasis'] \
and @rc['default']['emphasis']=~/bold/
'bold'
elsif defined? @rc['default']['emphasis'] \
and @rc['default']['emphasis'] \
and @rc['default']['emphasis']=~/italic/
'italics'
elsif defined? @rc['default']['emphasis'] \
and @rc['default']['emphasis'] \
and @rc['default']['emphasis']=~/underscore/
'underscore'
else 'bold'
end
end
def plaintext_wrap
((defined? @rc['default']['text_wrap']) \
&& (@rc['default']['text_wrap']) \
&& (@rc['default']['text_wrap'].to_s=~/\d\d+/) \
&& (@rc['default']['text_wrap'].to_i > 19) \
&& (@rc['default']['text_wrap'].to_i < 201)) \
? @rc['default']['text_wrap'].to_i
: 78
end
def current_document
@@current_document||=Dir.pwd
@@current_document
end
def stub_pwd #200412
@stub_pwd
end
def stub_md_harvest #watch
@stub_set_manifest
end
def stub_src
@stub_src
end
def stub_pod
@stub_pod
end
def sisupod_v3(opt)
#processing_path.processing
# sisupod
# doc/
# manifest.txt
# en/content.sst [file content]
# fr/content.sst
# _sisu
# skin/
# doc [relevant skin if any other than default]
# image@ (ln -s ../../image)
# audio@ (ln -s ../../audio)
# video@ (ln -s ../../video)
# image/ [all images for specific document gathered here]
# audio/
# video/
spp="#{processing_path.processing}/sisupod"
sppc="#{spp}/doc/_sisu"
lng_dirs=[]
if FileTest.directory?(spp) \
or FileTest.file?(spp)
FileUtils::rm_rf(spp)
end
paths=[]
flv=SiSU_Env::EnvCall.new(opt.fns).document_language_versions_found
flv[:f].each {|l| lng_dirs << l[:l] }
lng_dirs.uniq!
lng_dirs.each do |lng|
paths << "#{spp}/doc/#{lng}"
end
paths \
<< "#{spp}/image" \
<< "#{sppc}/skin/doc" \
<< "#{sppc}/skin/dir" \
<< "#{sppc}/skin/site"
#<< "#{spp}/audio" \
#<< "#{spp}/video" \
paths.each do |x|
unless FileTest.directory?(x)
FileUtils::mkdir_p(x)
end
end
if FileTest.directory?(sppc)
pwd=Dir.pwd
Dir.chdir(sppc)
FileUtils::ln_s('../../image', 'image')
#FileUtils::ln_s('../../audio', 'audio')
#FileUtils::ln_s('../../video', 'video')
Dir.chdir(pwd)
end
end
def sisupod_v2
#processing_path.processing
# sisupod
# content.sst [file content]
# filename.sst [link to content.sst]
# _sisu
# skin/
# doc [relevant skin if any other than default]
# image [all images for specific document gathered here]
sisupod_processing_path="#{processing_path.processing}/sisupod"
if FileTest.directory?(sisupod_processing_path) \
or FileTest.file?(sisupod_processing_path)
FileUtils::rm_rf(sisupod_processing_path)
end
paths=[]
paths=[
"#{processing_path.processing}/sisupod/_sisu/skin/doc",
"#{processing_path.processing}/sisupod/_sisu/skin/dir",
"#{processing_path.processing}/sisupod/_sisu/skin/site",
"#{processing_path.processing}/sisupod/_sisu/image"
]
paths.each {|x| FileUtils::mkdir_p(x) unless FileTest.directory?(x) }
end
def defaults #multiple default directories
@default_dir ||=@sys.default_dir #DEFAULT_DIR
end
def html_seg_title_banner?
((defined? @rc['html']['seg_title_banner']) \
&& @rc['html']['seg_title_banner']==true) \
? @rc['html']['seg_title_banner']
: false
end
def html_quick_ref?
((defined? @rc['html']['quick_ref']) \
&& @rc['html']['quick_ref']==true) \
? @rc['html']['quick_ref']
: false
end
def html_minitoc?
flag=if defined? @rc['html']['minitoc'] \
and not @rc['html']['minitoc'].nil?
@rc['html']['minitoc']
else false
end
end
def manifest_minitoc?
flag=if defined? @rc['manifest']['minitoc'] \
and not @rc['manifest']['minitoc'].nil?
@rc['manifest']['minitoc']
else false
end
end
def odt_ocn?
((defined? @rc['odt']['ocn']) \
&& @rc['odt']['ocn']==true) \
? @rc['odt']['ocn']
: false
end
def plaintext_ocn?
((defined? @rc['plaintext']['ocn']) \
&& @rc['plaintext']['ocn']==true) \
? @rc['plaintext']['ocn']
: false
end
def widget #needs (md) #move
@rc=SiSU_Env::GetInit.instance.sisu_yaml.rc
@ad=SiSU_Env::GetInit.instance.ads
@vz=SiSU_Env::GetInit.instance.skin
@flag={ ad: false, md: false, sk: false, rc: false }
def promo?
@flag[:ad]=if @md.flag_promo && @ad[:flag_promo]
@flag[:md]=true
true
elsif defined? @vz.widget_promo \
and not @vz.widget_promo.nil? \
and @vz.widget_promo.class==Array \
and @vz.widget_promo.length > 0
@flag[:sk]=true
true
elsif defined? @rc['html']['promo'] \
and not @rc['html']['promo'].nil? \
and @rc['html']['promo'].length > 0
@flag[:rc]=true
true
else false
end
@flag
end
def search?
searches=['sisu']
flag=false
if defined? @rc['search']
searches.each do |type|
flag=if defined? @rc['search'][type] \
and defined? @rc['search'][type]['action'] \
and @rc['search'][type]['flag']==true \
and @rc['search'][type]['action'] =~/https?:\/\//
flag=if promo?[:ad]
false
elsif defined? @vz.widget_search \
and @vz.widget_search==true
true
elsif defined? @rc['search'][type]['flag'] \
and @rc['search'][type]['flag']==true
true
else false
end
else false
end
end
else false
end
flag
end
def search_fixed?
searches=['sisu','hyperestraier']
flag=if defined? @rc['search']
searches.each do |type|
if defined? @rc['search'][type] \
and defined? @rc['search'][type]['action'] \
and @rc['search'][type]['action'] =~/https?:\/\// \
and defined? @rc['search'][type]['db'] \
and @rc['search'][type]['db'] =~/\S+/
flag=if promo?[:ad]
false
elsif defined? @vz.widget_search \
and @vz.widget_search==true
true
elsif defined? @rc['search'][type]['flag'] \
and @rc['search'][type]['flag']==true
true
else false
end
else false
end
end
else false
end
end
def search_form(type='sisusearch',action=nil,db=nil,table=false)
rc=SiSU_Env::GetInit.instance.sisu_yaml.rc
create_form_sisu=if action \
and db \
and action =~/https?:\/\// \
and db =~/\S+/
true
elsif widget.search?
db=if rc['search']['sisu']['flag']==true \
and rc['search']['sisu']['db']=~/\S+/
(rc['search']['sisu']['db']=~/^#{Db[:name_prefix]}\S+/) \
? rc['search']['sisu']['db']
: "#{Db[:name_prefix]}#{rc['search']['sisu']['db']}"
else nil
end
action=rc['search']['sisu']['action']
true
elsif defined? rc['search']['sisu']['flag'] \
and defined? rc['search']['sisu']['action'] \
and rc['search']['sisu']['flag']==true \
and rc['search']['sisu']['action'] =~/https?:\/\//
true
else false
end
if table
table_open='
'
table_close='
'
else
table_open=''
table_close=' '
end
form=if create_form_sisu \
and type=~/sisusearch/ \
and defined? rc['search']['sisu'] \
and defined? rc['search']['sisu']['action']
<
#{table_open}
#{table_close}
WOK
else ''
end
form
end
def search_form_static(action=nil,db=nil)
rc=SiSU_Env::GetInit.instance.sisu_yaml.rc
create_form=if rc['search']['sisu']['flag']==true \
and action \
and db \
and action =~/https?:\/\// \
and db =~/\S+/
true
elsif widget.search_fixed?
db=if rc['search']['sisu']['flag']==true \
and rc['search']['sisu']['db']=~/\S+/
(rc['search']['sisu']['db']=~/^#{Db[:name_prefix]}\S+/) \
? rc['search']['sisu']['db']
: "#{Db[:name_prefix]}#{rc['search']['sisu']['db']}"
else nil
end
action=rc['search']['sisu']['action']
true
else false
end
if create_form
%{
}
else ''
end
end
def search_action #check
action=if search?
else ''
end
end
self
end
def widget_static
@rc=SiSU_Env::GetInit.instance.sisu_yaml.rc
@vz=SiSU_Env::GetInit.instance.skin
@flag={ ad: false, md: false, sk: false, rc: false }
def search?
flag=if defined? @rc['search'] \
and defined? @rc['search']['sisu'] \
and defined? @rc['search']['sisu']['action'] \
and @rc['search']['sisu']['action'] =~/https?:\/\// \
and defined? @rc['search']['sisu']['db'] \
and @rc['search']['sisu']['db'] =~/\S+/ \
and defined? @rc['search']['sisu']['db'] \
and @rc['search']['sisu']['db'] =~/\S+/
flag=if defined? @vz.widget_search \
and @vz.widget_search==true
true
elsif defined? @rc['search']['sisu']['flag'] \
and @rc['search']['sisu']['flag']==true
true
else
false
end
else
false
end
end
def search_fixed?
flag=if defined? @rc['search'] \
and defined? @rc['search']['sisu'] \
and defined? @rc['search']['sisu']['action'] \
and @rc['search']['sisu']['action'] =~/https?:\/\// \
and defined? @rc['search']['sisu']['db'] \
and @rc['search']['sisu']['db'] =~/\S+/ \
and defined? @rc['search']['sisu']['db'] \
and @rc['search']['sisu']['db'] =~/\S+/
flag=if defined? @vz.widget_search \
and @vz.widget_search==true
true
elsif defined? @rc['search']['sisu']['flag'] \
and @rc['search']['sisu']['flag']==true
true
else
false
end
else
false
end
end
def search_form(action=nil,db=nil)
rc=SiSU_Env::GetInit.instance.sisu_yaml.rc
create_form=if defined? rc['search']['sisu']['flag'] \
and rc['search']['sisu']['flag']==true \
and action \
and db \
and action =~/https?:\/\// \
and db =~/\S+/
true
elsif widget_static.search? \
and rc['search']['sisu']['flag']==true
db=if rc['search']['sisu']['db']=~/\S+/
(rc['search']['sisu']['db']=~/^#{Db[:name_prefix]}\S+/) \
? rc['search']['sisu']['db']
: "#{Db[:name_prefix]}#{rc['search']['sisu']['db']}"
else nil
end
action=rc['search']['sisu']['action']
true
else false
end
if create_form \
and @fnb \
and @fnb=~/\S+/
%{
}
elsif create_form
%{
}
else ''
end
end
def search_action #check
action=if search?
else ''
end
end
self
end
def source_file_path
file=@fns.gsub(/\.ssm(?:\.sst)?/,'.ssm.sst')
pth=unless file =~/\.ssm\.sst$/; "#{Dir.pwd}"
else "#{processing_path.composite_file}"
end
end
def source_file_with_path
file=@fns.gsub(/\.ssm(?:\.sst)?/,'.ssm.sst')
"#{source_file_path}/#{file}"
end
def read_source_file(fns)
fns_array=if RUBY_VERSION < '1.9'
x=unless fns =~/\.ssm.sst$/
IO.readlines(fns,'')
else IO.readlines("#{processing_path.composite_file}/#{fns}",'')
end
else #ruby version >= '1.9'
x=unless fns =~/\.ssm.sst$/
IO.readlines(fns,'r:utf-8')
else IO.readlines("#{processing_path.composite_file}/#{fns}",'r:utf-8')
end
end
end
def font
def texpdf
def main
(defined? @rc['default']['texpdf_font']) \
&& (@rc['default']['texpdf_font']=~/\S{3,}/) \
? @rc['default']['texpdf_font']
: 'Liberation Sans'
end
def sans # not used
(defined? @rc['default']['texpdf_font_sans']) \
&& (@rc['default']['texpdf_font_sans']=~/\S{3,}/) \
? @rc['default']['texpdf_font_sans']
: 'Liberation Sans'
end
def serif # not used
(defined? @rc['default']['texpdf_font_serif']) \
&& (@rc['default']['texpdf_font_serif']=~/\S{3,}/) \
? @rc['default']['texpdf_font_serif']
: 'Liberation Serif'
end
def mono
(defined? @rc['default']['texpdf_font_mono']) \
&& (@rc['default']['texpdf_font_mono']=~/\S{3,}/) \
? @rc['default']['texpdf_font_mono']
: 'Liberation Mono'
end
self
end
self
end
def path_rel_links
def html_scroll_2
if @env.output_dir_structure.by_language_code?
'../../'
elsif @env.output_dir_structure.by_filetype?
'../'
else
'../'
end
end
def html_seg_2
if @env.output_dir_structure.by_language_code?
'../../../'
elsif @env.output_dir_structure.by_filetype?
'../../'
else
'../'
end
end
def html_scroll_1
if @env.output_dir_structure.by_language_code?
'../'
elsif @env.output_dir_structure.by_filetype?
'../'
else
'./'
end
end
def html_seg_1
if @env.output_dir_structure.by_language_code?
'../../'
elsif @env.output_dir_structure.by_filetype?
'../../'
else
'./'
end
end
def default_output_css
if @env.output_dir_structure.by_language_code?
'../../'
elsif @env.output_dir_structure.by_filetype?
'../'
else
'../'
end
end
def html_scroll_css
default_output_css
end
def xhtml_css
default_output_css
end
def xml_css
default_output_css
end
def html_seg_css
if @env.output_dir_structure.by_language_code?
'../../../'
elsif @env.output_dir_structure.by_filetype?
'../../'
else
'../'
end
end
def manifest_css
if @env.output_dir_structure.by_language_code?
'../../_sisu/css'
elsif @env.output_dir_structure.by_filetype?
''
else
'../'
end
end
self
end
def path #dir
def home
@sys.home
end
def sisurc_path
GetInit.instance.sisu_yaml.rc_path
end
def pwd
@sys.pwd
end
def stub_pwd
@stub_pwd
end
def stub_txt
@stub_txt
end
def stub_html
@stub_html
end
def stub_epub
@stub_epub
end
def stub_odt
@stub_odt
end
def stub_pdf
@stub_pdf
end
def stub_manifest
@stub_manifest
end
def stub_set_manifest
@stub_set_manifest
end
def stub_src
@stub_src
end
def stub_pod
@stub_pod
end
def stub_md_harvest
@stub_set_manifest
end
def etc
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
GetInit.instance.sisu_yaml.rc_path
end
def man #check use
(defined? @rc['webserv']['man']) \
? "#{webserv}/#{@rc['webserv']['man']}"
: defaults[:webserv_man]
end
def webserv_path #testing, check need, remove
webserv
end
def webserv #separation required for webrick which cannot use path.output (different requirements as no file is passed)
man_path=if @@man_path.nil?
man_path=if defined? @rc['webserv']['path'] \
and @rc['webserv']['path'] =~/\S\S+/
man_path=@@man_path=File.expand_path(@rc['webserv']['path'])
else defaults[:webserv_path]
end
else @@man_path
end
man_path_head=man_path.gsub(/(\S+)\/[^\/\s]+$/,'\1')
unless FileTest.directory?(man_path)
FileUtils::mkdir_p(man_path) if File.writable?("#{man_path_head}/.")
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
unless FileTest.directory?(defaults[:output_local])
FileUtils::mkdir_p(defaults[:output_local])
end
defaults[:output_local]
end
end
def webserv_stub_ensure
FileUtils::mkdir_p(path.webserv) unless FileTest.directory?(path.webserv)
FileUtils::mkdir_p("#{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
r=Px[:lng_lst].join('|')
u=/.+?\/([^\/]+)(?:\/(?:#{r})$|$)/
base_stub=@sys.pwd.gsub(u,'\1')
"#{path.webserv}/#{base_stub}"
end
def feed
(defined? @rc['webserv']['feed']) \
? ("#{public_output}/#{@rc['webserv']['feed']}")
: (defaults[:webserv_feed])
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 cgi
(defined? @rc['webserv']['cgi']) \
? "#{@rc['webserv']['cgi']}"
: (defaults[:webserv_cgi])
end
def php
(defined? @rc['webserv']['php']) \
? "#{public_output}/#{@rc['webserv']['php']}"
: (defaults[:webserv_php])
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_sisu_includes
"#{share}/image"
end
def image_source_include #image repository source directory
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']}"
elsif FileTest.directory?("#{@@pwd}/#{defaults[:image_stub]}")==true
"#{@@pwd}/#{defaults[:image_stub]}"
else
"#{share}/image"
end
end
def image_external
"#{processing}/external_document/image"
end
def image_source_include_local
if FileTest.directory?(defaults[:image_local]); defaults[:image_local]
end
end
def image_source_include_remote
if FileTest.directory?(image_external); image_external
end
end
self
end
def processing_path
def encoding
pth="#{processing}/#{defaults[:processing_encoding]}"
FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
pth
end
def processing_base_tmp
defaults[:processing_path_tmp_base]
end
def tmp_root_dir
defaults[:processing_dir_tmp_root]
end
def root_dir
proposed_path_base=if defined? @rc['processing']['path'] \
and not @rc['processing']['path'].nil? \
and not @rc['processing']['path'].empty?
x=if @rc['processing']['path'] =~/^(?:~|home)$/
home #fix
else @rc['processing']['path']
end
else nil
end
proposed_dir=if defined? @rc['processing']['dir'] \
and not @rc['processing']['dir'].nil? \
and not @rc['processing']['dir'].empty?
@rc['processing']['dir']
else defaults[:processing_dir]
end
path=if proposed_path_base \
and FileTest.directory?(proposed_path_base) \
and File.writable?("#{proposed_path_base}/.")
x=if proposed_dir
"#{proposed_path_base}/#{proposed_dir}"
else
"#{proposed_path_base}/#{defaults[:processing_dir]}"
end
else defaults[:processing_dir_tmp_root]
end
end
def usr_dir?
case root_dir
when /^\/home/; false
else true
end
end
def stub_dir
(usr_dir?) \
? ("#{root_dir}/#{user}/#{stub_pwd}")
: ("#{root_dir}/#{stub_pwd}") # see defaults[:processing_path]
end
def processing #processing directory, used/needed for sisu work files, has sub-directories (dal,tex etc)
unless FileTest.directory?(root_dir)
FileUtils::mkdir_p(root_dir)
File.chmod(0777,root_dir)
end
if usr_dir?
processing_path_usr="#{root_dir}/#{user}"
FileUtils::mkdir_p(processing_path_usr) unless FileTest.directory?(processing_path_usr)
File.chmod(0700,processing_path_usr)
end
FileUtils::mkdir_p(stub_dir) unless FileTest.directory?(stub_dir)
File.chmod(0700,stub_dir)
path_processing=[stub_dir,defaults[:processing_path],defaults[:processing_path_home]]
processing=nil
path_processing.each do |v| #
processing=v
unless FileTest.directory?(processing)
puts "a processing directory (#{processing}) is being created for use by sisu"
FileUtils::mkdir_p(processing)
File.chmod(0700,processing)
end
break
end
processing
end
def dal
pth=if defined? @rc['processing']['dal'] \
and not @rc['processing']['dal'].nil? \
and not @rc['processing']['dal'].empty?
"#{processing}/#{@rc['processing']['dal']}"
else "#{processing}/#{defaults[:processing_dal]}"
end
FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
pth
end
def tune
pth=if defined? @rc['processing']['tune'] \
and not @rc['processing']['tune'].nil? \
and not @rc['processing']['tune'].empty?
"#{processing}/#{@rc['processing']['tune']}"
else "#{processing}/#{defaults[:processing_tune]}"
end
FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
pth
end
def composite_file
pth=processing_path.dal #"#{processing}/composite"
FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
pth
end
def git
pth=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
unless FileTest.directory?(pth)
FileUtils::mkdir_p(pth)
File.chmod(0700,pth)
end
pth
end
def odf_pth
pth="#{processing}/odf/#{@fns}"
pth
end
def odf
odt
end
def odt
pth=odf_pth + '/odt'
FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
pth
end
def odf
pth="#{processing}/odf"
FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
pth
end
def odt_bld
FileUtils::rm_rf(processing_path.odt)
FileUtils::mkdir_p(processing_path.odt) unless FileTest.directory?(processing_path.odt)
FileUtils::mkdir_p("#{processing_path.odt}/Configurations2") unless FileTest.directory?("#{processing_path.odt}/Configurations2")
FileUtils::mkdir_p("#{processing_path.odt}/META-INF") unless FileTest.directory?("#{processing_path.odt}/META-INF")
FileUtils::mkdir_p("#{processing_path.odt}/Pictures") unless FileTest.directory?("#{processing_path.odt}/Pictures")
FileUtils::mkdir_p("#{processing_path.odt}/Thumbnails") unless FileTest.directory?("#{processing_path.odt}/Thumbnails")
processing_path.odt
end
def epub
"#{processing}/epub/#{@fnb}"
end
def epub_bld #(md)
FileUtils::rm_rf(processing_path.epub) if FileTest.directory?(processing_path.epub)
FileUtils::mkdir_p(processing_path.epub) unless FileTest.directory?(processing_path.epub)
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)
pth="#{processing_path.epub}/#{Ep[:d_oebps]}/image"
FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
src="#{path.share}/image"
images=%W[bullet_09.png arrow_next_red.png arrow_prev_red.png arrow_up_red.png]
images.each do |i| #move to avoid repeated tests
FileUtils::cp("#{src}/#{i}","#{pth}/#{i}") unless FileTest.file?("#{pth}/#{i}")
end
pth
end
def tex
pth=if defined? @rc['processing']['latex'] \
and not @rc['processing']['latex'].nil? \
and not @rc['processing']['latex'].empty?
"#{processing}/#{@rc['processing']['latex']}"
else "#{processing}/#{defaults[:processing_latex]}"
end
FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
pth
end
def texi
pth=if defined? @rc['processing']['texinfo'] \
and not @rc['processing']['texinfo'].nil? \
and not @rc['processing']['texinfo'].empty?
"#{processing}/#{@rc['processing']['texinfo']}"
else "#{processing}/#{defaults[:processing_texinfo]}"
end
FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
pth
end
def texinfo #texinfo webserv, check
"#{processing}/#{defaults[:processing_texinfo]}"
end
def manpage
"#{path.output}/man"
end
def lout
pth=if defined? @rc['processing']['lout'] \
and not @rc['processing']['lout'].nil? \
and not @rc['processing']['lout'].empty?
"#{processing}/#{@rc['processing']['lout']}"
else "#{processing}/#{defaults[:processing_lout]}"
end
FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
pth
end
def sql
pth="#{processing}/sql"
FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
pth
end
def sqlite
pth=if defined? @rc['processing']['sqlite'] \
and not @rc['processing']['sqlite'].nil? \
and not @rc['processing']['sqlite'].empty?
"#{processing}/#{@rc['processing']['sqlite']}"
else "#{processing}/#{defaults[:processing_sqlite]}"
end
FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
pth
end
def postgresql
pth=if defined? @rc['processing']['postgresql'] \
and not @rc['processing']['postgresql'].nil? \
and not @rc['processing']['postgresql'].empty?
"#{processing}/#{@rc['processing']['postgresql']}"
else "#{processing}/#{defaults[:processing_postgresql]}"
end
FileUtils::mkdir_p(pth) unless FileTest.directory?(pth)
pth
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'] =~/https?:\/\//
"#{@rc['webserv']['url_root']}/#{@stub_pwd}"
elsif defined? @rc['webserv']['url_root'] \
and @rc['webserv']['url_root'] =~/localhost/
"http://localhost/#{@stub_pwd}"
else "file://#{path.output}"
end
end
def remote
root
end
def txt
"#{root}/txt"
end
def html
"#{root}/html"
end
def epub
"#{root}/epub"
end
def odt
"#{root}/odt"
end
def pdf
"#{root}/pdf"
end
def src_txt
"#{root}/src"
end
def src_pod
"#{root}/pod"
end
def pot
"#{root}/po4a/pot"
end
def po
"#{root}/po4a/po"
end
def webserv_host_base
if defined? @rc['webserv']['host']
case @rc['webserv']['host']
when /https?:\/\//; @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.opt.cmd.inspect=~/-F/ \
and @md.opt.mod.inspect=~/port=(\d+)/
$1
else
if defined? @rc['webserv_cgi']['port']
if @rc['webserv_cgi']['port'].nil? \
and (defined? @md.opt.mod \
and not @md.opt.mod.nil? \
and @md.opt.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 defined? @md.opt \
and @md.opt.cmd.inspect=~/-F/ \
and @md.opt.mod.inspect=~/port=(\d+)/
$1
else
if defined? @rc['webserv_cgi']['port']
if @rc['webserv_cgi']['port'].nil? \
and (defined? @md.opt.mod \
and not @md.opt.mod.nil? \
and @md.opt.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'] =~ /https?:\/\//) ? '' : 'http://') #check https? missing
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=~/https?:\/\//) ? '' : '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'] =~ /https?:\/\//) ? '' : '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=~/https?:\/\//) ? '' : '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
if defined? @rc['webserv_cgi']['host'] \
and not @rc['webserv_cgi']['host'].nil?
http=if @rc['webserv_cgi']['host'] =~/http:\/\//
'http://'
elsif @rc['webserv_cgi']['host'] =~/https:\/\//
'https://'
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 defined? @rc['webserv']['url_root'] \
and @rc['webserv']['url_root'] =~/http/
# needed for alternative output dir structures, fixes manifest url links, check may cause problems elsewhere
@rc['webserv']['url_root']
elsif 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}"
elsif webserv_port_cgi =~/\S+/
"#{url.hostname}:#{webserv_port_cgi}"
else
url.hostname
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 /https?:\/\//; @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']['sisu']['title'] \
and @rc['search']['sisu']['title'] =~/\S+/
@rc['search']['sisu']['title']
else %{(SiSU (generated sample) search form}
end
end
def output_tell #BROKEN Revisit 2011-02
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
"#{Xx[:html_relative2]}/_sisu/image"
end
#def images
# '../_sisu/image'
#end
def images_local
if FileTest.directory?(path.image_source_include)
path.image_source_include
else
if @@local_image==true
cmd=@cmd ? @cmd : ''
SiSU_Screen::Ansi.new(cmd,"WARNING - no local image directory or images:", defaults[:image_local] ).warn unless cmd =~/q/
@@local_image=false
end
url.images
end
end
def images_external
if FileTest.directory?(image_external)
if @@image_flag
images=Dir.glob("#{image_external}/*.{png,jpg,gif}")
pth="#{path.webserv}/#{@stub_pwd}"
FileUtils::mkdir_p("#{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
"#{Xx[:html_relative2]}/_sisu/image_external"
else
if @@local_image==true
SiSU_Screen::Ansi.new(@cmd,"WARNING - image directory for external images or no such images:", :image_external ).warn unless @cmd =~/q/
@@local_image=false
end
url.images_external
end
end
def images_epub
'./image'
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 'sha256'
end
else 'sha256'
end
end
def length
case digest.type
when /sha256/; 64
when /md5/; 32
else 64
end
end
def pattern
"[0-9a-f]{#{digest.length}}" #/[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
((defined? @rc['program_select']['pdf_viewer']) \
&& @rc['program_select']['pdf_viewer'] =~/\S\S+/) \
? @rc['program_select']['pdf_viewer']
: 'pdf-viewer' #'evince'
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' #'firefox' 'iceweasel' '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' #'lynx' 'links' 'links2' 'elinks' 'w3m'
end
end
def console_www_browser
web_browser
end
def epub_viewer
((defined? @rc['program_select']['epub_viewer']) \
&& @rc['program_select']['epub_viewer'] =~/\S\S+/) \
? @rc['program_select']['epub_viewer']
: 'ebook-viewer' #'calibre' 'fbreader'
end
def xml_viewer
((defined? @rc['program_select']['xml_viewer']) \
&& @rc['program_select']['xml_viewer'] =~/\S\S+/) \
? @rc['program_select']['xml_viewer']
: text_editor
end
def xml_editor
xml_viewer
end
def odf_viewer
((defined? @rc['program_select']['odf_viewer']) \
&& @rc['program_select']['odf_viewer'] =~/\S\S+/) \
? @rc['program_select']['odf_viewer']
: 'lowriter' #'odf-viewer','oowriter'
end
def manpage_viewer
'man'
end
def manpage_generator
((defined? @rc['program_select']['man']) \
&& @rc['program_select']['man'] =~/\S\S+/) \
? @rc['program_select']['man']
: 'nroff -man' #'nroff -man' #'groff -man -Tascii'
end
def texinfo
((defined? @rc['program_select']['info_viewer']) \
&& @rc['program_select']['info_viewer'] =~/\S\S+/) \
? @rc['program_select']['info_viewer']
: 'pinfo -f' #'pinfo -f' 'info' 'tkinfo'
end
def file_encoding
is=(defined? @rc['program_set']['file_encoding']) ? @rc['program_set']['encoding'] : ''
(is.nil? || is==true) ? 'encoding' : is
end
def wc #wordcount
is=(defined? @rc['program_set']['wc']) ? @rc['program_set']['wc'] : ''
(is.nil? || is==true) ? 'wc' : is
end
def tidy
is=(defined? @rc['program_set']['tidy']) ? @rc['program_set']['tidy'] : nil
(is.nil? || is==true) ? 'tidy' : is
end
def rmagick
is=(defined? @rc['program_set']['rmagick']) ? @rc['program_set']['rmagick'] : nil
(is.nil? || is==true) ? 'rmagick' : is
end
def rexml #should be part of ruby 1.8 but apparently not always
is=(defined? @rc['program_set']['rexml']) ? @rc['program_set']['rexml'] : ''
(is.nil? || is==true) ? 'rexml' : is
end
def pdflatex
is=(defined? @rc['program_set']['pdflatex']) ? @rc['program_set']['pdflatex'] : ''
(is.nil? || is==true) ? 'pdflatex' : is
end
def postgresql
is=(defined? @rc['program_set']['postgresql']) ? @rc['program_set']['postgresql'] : ''
(is.nil? || is==true) ? 'postgresql' : is
end
def sqlite
is=(defined? @rc['program_set']['sqlite']) ? @rc['program_set']['sqlite'] : ''
(is.nil? || is==true) ? 'sqlite' : is
end
self
end
def i18n
def language # language settings
m=/.+\/\S+?\~(\S+)/
pwd=Dir.pwd
conf=(defined? @rc['default']['language']) ? @rc['default']['language'] : nil
l=if pwd=~ m; pwd[m,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::StandardiseLanguage.new(l)
end
#def multilingual
# x=(defined? @rc['output_structure']['multilingual'] \
# && @rc['output_structure']['multilingual'] ==true) \
# ? true : false
#end
#def bundle
# x=(defined? @rc['output_structure']['bundle'] \
# && @rc['output_structure']['bundle'] ==true) \
# ? true : false
#end
def lang_filename(l)
@lang={}
x=if output_dir_structure.by_language_code?
(( defined? @rc['default']['language_file']) \
&& @rc['default']['language_file'] != nil) \
? @rc['default']['language_file']
: 1
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
(defined? @rc['default']['papersize']) \
? @rc['default']['papersize'].downcase
: (defaults[:papersize].downcase)
end
def odf_structure
FileUtils::rm_rf(processing_path.processing_path.odf_pth)
FileUtils::mkdir_p(processing_path.processing_path.odf_pth)
system("unzip -q #{path.share}/#{SiSU_version_dir}/odf/odt.zip -d #{processing_path.odf_pth}")
end
def sisupod_gen(fns_pod)
sisupod_gen_v3(fns_pod)
end
def sisupod_gen_v3(fns_pod)
pwd=Dir.pwd
sisupod_processing_path="#{processing_path.processing}/sisupod"
if FileTest.directory?(sisupod_processing_path) \
or FileTest.file?(sisupod_processing_path)
FileUtils::rm_rf(sisupod_processing_path)
end
unless FileTest.directory?(sisupod_processing_path)
FileUtils::mkdir_p(sisupod_processing_path)
end
f_pod=if FileTest.file?("#{Dir.pwd}/#{fns_pod}")
"#{Dir.pwd}/#{fns_pod}"
elsif FileTest.file?(fns_pod)
fns_pod
end
if f_pod \
&& FileTest.file?(f_pod)
tree=(SiSU_Env::SystemCall.new.program_found?('tree')) \
? "tree #{processing_path.processing}/sisupod"
: ''
if FileTest.directory?(processing_path.processing)
Dir.chdir(processing_path.processing)
system(%{tar xJf #{f_pod}})
Dir.chdir(pwd)
end
#system(tree) #enable if (/[vVM]/)
else
SiSU_Screen::Ansi.new('',"file not found: #{fns_pod}").warn unless @cmd=~/q/
end
sisupod_processing_path
end
def sisupod_gen_v2(fns_pod)
pwd=Dir.pwd
sisupod_processing_path="#{processing_path.processing}/sisupod"
if FileTest.directory?(sisupod_processing_path) \
or FileTest.file?(sisupod_processing_path)
FileUtils::rm_rf(sisupod_processing_path)
end
unless FileTest.directory?(sisupod_processing_path)
FileUtils::mkdir_p(sisupod_processing_path)
end
(FileTest.file?(fns_pod)) \
? system("unzip -q #{fns_pod} -d #{processing_path.processing}")
: (SiSU_Screen::Ansi.new('',"file not found: #{fns_pod}").warn unless @cmd=~/q/)
sisupod_processing_path
end
end
class InfoProcessingFlag
attr_accessor :color,:cf_0,:cf_1,:cf_2,:cf_3,:cf_4,:cf_5
def initialize
@rc=GetInit.instance.sisu_yaml.rc
end
def color #processing flag shortcuts
(defined? @rc['flag']['color']) ? @rc['flag']['color'] : false
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 '-NQhewpotbxXyYv'
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 '-Qhewpoty'
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 '-NQhewpotbxXy'
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 '-NQhewpotbxXyY'
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 '-NQhewpotbxXDyY --update'
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 '-NQhewpotbxXDyYv --update'
end
end
end
class InfoSettings < InfoEnv
def permission?(prog) #program defaults
(defined? @rc['permission_set'][prog]) \
? @rc['permission_set'][prog]
: false
end
def program?(prog) #program defaults
(defined? @rc['program_set'][prog]) \
? @rc['program_set'][prog]
: false
end
end
class FileMap < InfoEnv
attr_accessor :local_sisu_source
def initialize(opt='') #watch / REVIEW
super()
@opt=opt #,opt.fns,opt.cmd
@env=(@opt.fns && !(@opt.fns.empty?) \
? (SiSU_Env::InfoEnv.new(@opt.fns))
: (SiSU_Env::InfoEnv.new('dummy.sst')))
if @opt.cmd =~/m/; @md=SiSU_Param::Parameters.new(@opt).get
end
ft=[]
if @md \
and defined? @md.fn \
and @md.fn # used for by_language_code?
if @md.opt.cmd =~ /[hH]/
ft << @md.fn[:html]
end
if @md.opt.cmd =~ /w/ \
and @md.opt.cmd !~ /[hH]/
ft << @md.fn[:concordance]
end
if @md.opt.cmd =~ /y/ \
and @md.opt.cmd !~ /[hH]/
ft << @md.fn[:manifest]
end
if @md.opt.cmd =~ /[at]/; ft << @md.fn[:plain]
end
if @md.opt.cmd =~ /b/; ft << @md.fn[:xhtml]
end
if @md.opt.cmd =~ /e/; ft << @md.fn[:epub]
end
if @md.opt.cmd =~ /g/; ft << @md.fn[:wiki]
end
if @md.opt.cmd =~ /i/; ft << @md.fn[:manpage]
end
if @md.opt.cmd =~ /N/; ft << @md.fn[:digest]
end
if @md.opt.cmd =~ /o/; ft << @md.fn[:odf]
end
if @md.opt.cmd =~ /O/; ft << @md.fn[:oai_pmh]
end
if @md.opt.cmd =~ /p/; ft << @md.fn[:pdf_l] << @md.fn[:pdf_p]
end
if @md.opt.cmd =~ /s/; ft << @md.fns
end
if @md.opt.cmd =~ /S/; ft << @md.fn[:sisupod] << '.kdi'
end
if @md.opt.cmd =~ /x/; ft << @md.fn[:sax]
end
if @md.opt.cmd =~ /X/; ft << @md.fn[:dom]
end
if @md.opt.cmd =~ /G/; ft << @md.fn[:pot]
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 =~ /a/; ft << 'plain.txt' << '??.plain.txt' << 'plain.??.txt'
end
if @opt.cmd =~ /b/; ft << 'scroll.xhtml' << '??.scroll.xhtml' << 'scroll.??.xhtml'
end
if @opt.cmd =~ /e/; ft << @fnb << '.epub'
end
if @opt.cmd =~ /g/; ft << 'wiki.txt' << '??.wiki.txt' << 'wiki.??.txt'
end
if @opt.cmd =~ /i/; ft << '.1' << '??.man.1' << 'man.??.1'
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 =~ /O/; ft << 'oai_pmh.xml'
end
if @opt.cmd =~ /p/; ft << 'landscape.pdf' << 'portrait.pdf' << '.pdf'
end
if @opt.cmd =~ /s/; ft << '.sst' << '.ssi' << '.ssm'
end
if @opt.cmd =~ /S/; ft << '.zip' << '.kdi'
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.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=(@fnb && !(@fnb.empty?) \
? "#{@env.path.output}/#{@fnb}"
: @env.path.output)
@source_path_epub=(@fnb && !(@fnb.empty?) \
? "#{@env.path.output}/epub"
: @env.path.output_epub)
@source_path_src=(@fnb && !(@fnb.empty?) \
? "#{@env.path.output}/src"
: @env.path.output_src)
@source_path_pod=(@fnb && !(@fnb.empty?) \
? "#{@env.path.output}/pod"
: @env.path.output_pod)
@source_path_harvest=(@fnb && !(@fnb.empty?) \
? "#{@env.path.output}/manifest"
: @env.path.output_harvest)
@local_sisu_source=(@filetypes =~/\S/) \
? "#{@source_path}/#{@filetypes}"
: @source_path
end
end
class CleanOutput
require 'fileutils'
include FileUtils::Verbose
def initialize(opt)
@opt=opt
z=SiSU_Env::FileMap.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::InfoEnv.new
end
def zap
def main_output
(@zap !~/\/\//) \
? (FileUtils::rm_rf(@zap) if FileTest.directory?(@zap))
: (puts 'suspect zap request, ignored')
end
def site_map
if @opt.fnb \
and not @opt.fnb.empty?
sm="#{@env.path.output}/sitemaps/sitemap_#{@opt.fnb}.xml"
FileUtils::rm(sm) if FileTest.file?(sm)
end
end
def epub
if @opt.fnb \
and not @opt.fnb.empty?
sm="#{@env.path.output}/epub/#{@opt.fnb}.epub"
FileUtils::rm(sm) if FileTest.file?(sm)
end
end
def src # consider
if @opt.fnb \
and not @opt.fnb.empty?
sm="#{@env.path.output}/src/pod/#{@opt.fns}.txz"
FileUtils::rm(sm) if FileTest.file?(sm)
sm="#{@env.path.output}/src/#{@opt.fns}"
FileUtils::rm(sm) if FileTest.file?(sm)
end
end
self
end
end
class InfoRemoteHost
def initialize
@rc=GetInit.instance.sisu_yaml.rc
end
def remote_host #see InfoRemote remote_host_base_general
r=[]
r=if (defined? @rc['remote'] \
and @rc['remote'].class==Array)
r_array=@rc['remote']
r_array.each_with_index do |renv,i|
r[i]={}
if defined? renv['user'] \
and defined? renv['host']
end
r[i][:user]=renv['user']
r[i][:host]=renv['host']
r[i][:path]=if defined? renv['path']
renv['path']
else ''
end
r[i][:name]="#{r[i][:user]}@#{r[i][:host]}:#{r[i][:path]}"
end
r
elsif (defined? @rc['remote'] \
and @rc['remote'].class==Hash \
and defined? @rc['remote']['user'] \
and defined? @rc['remote']['host'])
r[0]={}
r[0][:user]=@rc['remote']['user']
r[0][:host]=@rc['remote']['host']
r[0][:path]=if defined? @rc['remote']['path']
@rc['remote']['path']
else ''
end
r[0][:name]="#{r[0][:user]}@#{r[0][:host]}:#{r[0][:path]}"
r
else
r[0]={}
r[0][:name]='.'
r[0][:user]=''
r[0][:host]=''
r[0][:path]=''
#puts "no remote host or user"
r
end
end
def rhost
def r1
(defined? SiSU_Env::InfoRemoteHost.new.remote_host[0][:name]) \
? (SiSU_Env::InfoRemoteHost.new.remote_host[0][:name])
: nil
end
def r2
(defined? SiSU_Env::InfoRemoteHost.new.remote_host[1][:name]) \
? (SiSU_Env::InfoRemoteHost.new.remote_host[1][:name])
: nil
end
def r3
(defined? SiSU_Env::InfoRemoteHost.new.remote_host[2][:name]) \
? (SiSU_Env::InfoRemoteHost.new.remote_host[2][:name])
: nil
end
def r4
(defined? SiSU_Env::InfoRemoteHost.new.remote_host[3][:name]) \
? (SiSU_Env::InfoRemoteHost.new.remote_host[3][:name])
: nil
end
def r5
(defined? SiSU_Env::InfoRemoteHost.new.remote_host[4][:name]) \
? (SiSU_Env::InfoRemoteHost.new.remote_host[4][:name])
: nil
end
def r6
(defined? SiSU_Env::InfoRemoteHost.new.remote_host[5][:name]) \
? (@ls + SiSU_Env::InfoRemoteHost.new.remote_host[5][:name])
: nil
end
self
end
end
class InfoRemote < FileMap
@@flag_remote=false
require 'socket'
def initialize(opt)
super(opt) #
@opt=opt
@rc=GetInit.instance.sisu_yaml.rc
end
def remote_host_base_general
SiSU_Env::InfoRemoteHost.new.remote_host
end
def remote_host_base
remote_host_base_general.each do |remote_conn|
@@flag_remote=true if remote_conn[:name] =~/\S+?@\S+/
end
remote_host_base_general
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
def document
self.remote_host_base.each do |remote_conn|
local_gen=@source_path
remote_gen=case @opt.cmd
when /u/; "#{remote_conn[:name]}/#{@env.path.stub_pwd}/." #creates remote directory tree, this is not the usual function of u
when /[abhHNopwxXy]/; "#{remote_conn[:name]}/#{@env.path.stub_pwd}/#{@fnb}/."
else "#{remote_conn[:name]}/#{@env.path.stub_pwd}/."
end
local_epub=@source_path_epub
local_src=@source_path_src
local_pod=@source_path_pod
remote_epub="#{remote_conn[:name]}/#{@env.path.stub_epub}/."
remote_src="#{remote_conn[:name]}/#{@env.path.stub_src}/."
remote_pod="#{remote_conn[:name]}/#{@env.path.stub_pod}/."
src_txt=@opt.fnc
src_pod=@opt.fncb.gsub(/(\.ss[mt])(?:\.sst)?$/,'\1.txz')
if (local_gen =~/\S/ \
and local_gen !~/\/\//) \
and (remote_gen =~/\S/ \
and remote_gen !~/\/\//) \
and @@flag_remote==true \
and @opt.cmd !~/U/
SiSU_Env::SystemCall.new(local_gen,remote_gen).scp
if FileTest.file?("#{local_src}/#{src_txt}")
SiSU_Env::SystemCall.new("#{local_src}/#{src_txt}",remote_src).scp
end
if FileTest.file?("#{local_pod}/#{src_pod}")
SiSU_Env::SystemCall.new("#{local_src}/#{src_pod}",remote_pod).scp
end
if FileTest.file?("#{local_epub}/#{@opt.fnb}.epub")
SiSU_Env::SystemCall.new("#{local_epub}/#{@opt.fnb}.epub",remote_epub,@opt.cmd).scp
end
elsif @opt.cmd =~/U/
puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
puts "#{local_gen} -> #{remote_gen}"
if FileTest.file?("#{local_src}/#{src_doc}")
puts "#{local_src}/#{src_doc}* -> #{remote_src}"
end
if FileTest.file?("#{local_pod}/#{src_doc}.txz")
puts "#{local_pod}/#{src_doc}* -> #{remote_pod}"
end
else
puts 'suspect scp request, ignored'
puts "#{local_gen} -> #{remote_gen} remote flag: #{@@flag_remote}"
puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
end
end
end
def site_base #base site
self.remote_host_base.each do |remote_conn|
local=@source_path
remote="#{remote_conn[:name]}/#{@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: #{local} -> #{remote}"
SiSU_Env::SystemCall.new("#{local}/#{@env.path.style}/",remote).scp
elsif @opt.cmd =~/U/
puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
puts "begin scp_base: #{local} -> #{remote}"
puts "#{local}/#{@env.path.style}/ -> #{remote}"
else puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
end
end
end
def site_base_all #base site
self.remote_host_base.each do |remote_conn|
local=@source_path
remote="#{remote_conn[:name]}/#{@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: #{local} -> #{remote}"
SiSU_Env::SystemCall.new("#{local}/_sisu/image_sys/",remote).scp
SiSU_Env::SystemCall.new("#{local}/_sisu/image/",remote).scp
SiSU_Env::SystemCall.new("#{local}/#{@env.path.style}/",remote).scp
elsif @opt.cmd =~/U/
puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
puts "scp_base_all: #{local} -> #{remote}"
puts "#{local}/_sisu/image_sys/ -> #{remote}"
puts "#{local}/_sisu/image/ -> #{remote}"
puts "#{local}/#{@env.path.style}/ -> #{remote}"
else puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
end
end
end
self
end
def images_from_skin
skin=SiSU_Env::InfoSkin.new(@md).select
skin_array=nil
skin_images_array=[]
if skin
skin_array=IO.readlines(skin,"\n")
skin_array.each do |l|
if l !~/^#/
if l =~/([a-z0-9._-]+\.(?:png|jpg|gif))/i
skin_images_array << $1
end
end
end
end
skin_images_array
end
def rsync
@f=SiSU_Env::FileOp.new(@md)
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"
remote_gen="#{remote_conn[:name]}/#{@env.path.stub_pwd}/."
remote_rel=remote_conn[:name] + '/' + @f.output_path.stub.rcp
src_txt=@opt.fnc
if (local_gen =~/\S/ \
and local_gen !~/\/\//) \
and (remote_gen =~/\S/ \
and remote_gen !~/\/\//) \
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'
inp=[]
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/ \
|| @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/ \
|| @opt.cmd =~/^-R[mqvVM]*$/) \
&& FileTest.file?(@f.place_file.epub.dir)
inp << @f.place_file.epub.rel
end
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/ \
|| @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
&& FileTest.file?(@f.place_file.xhtml.dir)
inp << @f.place_file.xhtml.rel
end
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/ \
|| @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]/ \
|| @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
&& FileTest.file?(@f.place_file.txt.dir)
inp << @f.place_file.txt.rel
end
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/ \
|| @opt.cmd =~/^-[mqvVM]*I[mqvVM]*$/) \
&& FileTest.file?(@f.place_file.info.dir)
inp << @f.place_file.info.rel
end
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/ \
|| @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
&& FileTest.file?(@f.place_file.src.dir)
inp << @f.place_file.src.rel
end
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/ \
|| @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/)
inp << @f.output_path.pdf.rel + '/' + @opt.fnb + '*'
end
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/ \
|| @opt.cmd =~/^-[mqvVM]*R[mqvVM]*$/) \
&& FileTest.file?(@f.place_file.manifest.dir)
inp << @f.place_file.manifest.rel
end
local_gen=if inp.length > 0
inp.join(' ')
else ''
end
local_css,images,images_external,images_system='','','',''
images_gen=images=images_skin=images_system=local_css=''
if @opt.cmd =~/[hwbxX]/ \
&& (defined? @md.ec[:image]) \
&& (@md.ec[:image].length > 0)
images=@f.place_file.images.rel + '/' + @md.ec[:image].join(" #{@f.output_path.images.rel}/")
end
if @opt.cmd =~/[yhwbxX]/ \
&& (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 \
&& images_from_skin.length > 0
images_skin=@f.place_file.images.rel + '/' + images_from_skin.join(" #{@f.output_path.images.rel}/")
end
end
begin
##create file structure without copying files?:
##rsync -av -f"+ */" -f"- *" @f.output_path.base.dir remote:./path/.
#local_dirs=%{-f"+ */" -f"- *" #{@f.output_path.base.dir}/*}
#SiSU_Env::SystemCall.new(local_dirs,remote_gen,@opt.cmd).rsync
local=local_gen + ' ' + images + ' ' + images_skin + ' ' + images_system + ' ' + local_css
SiSU_Env::SystemCall.new(local,remote_rel,@opt.cmd).rsync('--relative',@f.output_path.base.dir)
rescue
p __LINE__.to_s + ':' + __FILE__
local_dirs=%{--include='*/' --exclude='*' #{@f.output_path.base.dir}}
SiSU_Env::SystemCall.new(local_dirs,remote_gen,@opt.cmd).rsync
end
elsif @opt.cmd =~/U/
puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
puts "#{local_gen} -> #{remote_gen}"
if FileTest.file?("#{local_src}/#{src_doc}") \
or FileTest.file?("#{local_src}/#{src_doc}.txz")
puts "#{local_src}/#{src_doc}* -> #{remote_src}"
end
else
puts 'suspect rsync request, ignored'
puts "#{local_gen} -> #{remote_gen} remote flag: #{@@flag_remote}"
puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
end
end
end
def site_base #base site
ldest="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu"
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"
if defined? @rc['permission_set']['remote_base_site'] \
and @rc['permission_set']['remote_base_site'] \
and @@flag_remote==true \
and @opt.cmd !~/U/
SiSU_Env::SystemCall.new("#{image_sys}","#{remote_conf}").rsync
SiSU_Env::SystemCall.new("#{images}","#{remote_conf}").rsync
SiSU_Env::SystemCall.new("#{ldest}","#{remote}").rsync
elsif @opt.cmd =~/U/
puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
puts "rsync_base: #{local} -> #{remote}"
puts "#{local}/_sisu/image -> #{remote}"
puts "#{local}/_sisu/image_sys/ -> #{remote}"
puts "#{local}/#{@env.path.style}/ -> #{remote}"
else puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
end
end
end
def site_base_sync
self.remote_host_base.each do |remote_conn|
local=@source_path
remote="#{remote_conn[:name]}/#{@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/
delete_extra_files='--delete' # '--delete-after'
puts "begin rsync_base_sync: #{local} -> #{remote}"
SiSU_Env::SystemCall.new("#{local}/_sisu/image_sys/",remote).rsync(delete_extra_files)
SiSU_Env::SystemCall.new("#{local}/_sisu/image/",remote).rsync(delete_extra_files)
SiSU_Env::SystemCall.new("#{local}/#{@env.path.style}/",remote).rsync(delete_extra_files)
elsif @opt.cmd =~/U/
puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
puts "rsync_base_sync: #{local} -> #{remote}"
puts "#{local}/_sisu/image_sys/ -> #{remote}"
puts "#{local}/_sisu/image/ -> #{remote}"
puts "#{local}/#{@env.path.style}/ -> #{remote}"
else puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
end
end
end
self
end
def rsync_sitemaps #sitemap directory
self.remote_host_base.each do |remote_conn|
local="#{@source_path}/sitemapindex.xml"
remote="#{remote_conn[:name]}/#{@env.path.stub_pwd}/."
if @@flag_remote
delete_extra_files='--delete' # '--delete-after'
SiSU_Env::SystemCall.new(local,remote).rsync(delete_extra_files)
elsif @opt.cmd =~/U/
puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
puts "rsync_sitemaps: #{local} -> #{remote}"
else puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
end
end
end
def rsync_harvest
self.remote_host_base.each do |remote_conn|
local=@source_path_harvest
remote="#{remote_conn[:name]}/#{@env.path.stub_pwd}/."
if @@flag_remote
delete_extra_files='--delete' # '--delete-after'
SiSU_Env::SystemCall.new(local,remote).rsync(delete_extra_files)
elsif @opt.cmd =~/U/
puts "#{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
puts "rsync_sitemaps: #{local} -> #{remote}"
else puts "permission not granted #{__FILE__} #{__LINE__}" if @opt.cmd =~/M/
end
end
end
end
class InfoVersion }
end
def html_seg
%{ }
end
def html_tables
%{ }
end
def xhtml_epub
%{ }
end
def epub
xhtml_epub
end
def xhtml
%{}
end
def xml_sax
%{}
end
def xml_dom
%{}
end
end
class CreateSite < InfoEnv
require_relative 'css' # css.rb
include SiSU_Style
def initialize(cmd)
@cmd=cmd
@env=SiSU_Env::InfoEnv.new
@home,@pwd=ENV['HOME'],ENV['PWD'] #@pwd=Dir.pwd
@rc=GetInit.instance.sisu_yaml.rc
@vz=SiSU_Env::GetInit.instance.skin
@vz_home=SiSU_Viz::Home.new
end
def homepage
home_pages_manually_created=nil
@env.sys.rc_path.each do |v|
home_pages_manually_created=Dir.glob("#{v}/home/*.html")
if home_pages_manually_created.length > 0
break
end
end
FileUtils::mkdir_p("#{@env.path.webserv}/#{@env.path.stub_pwd}") unless FileTest.directory?("#{@env.path.webserv}/#{@env.path.stub_pwd}")
if home_pages_manually_created
FileUtils.cp(home_pages_manually_created,"#{@env.path.webserv}/#{@env.path.stub_pwd}")
else
doc_skin=nil
sk_doc='doc/skin_sisu.rb'
@env.sys.rc_path.each do |v| #document skin priority 1
if FileTest.file?("#{v}/skin/#{sk_doc}")
doc_skin="#{v}/skin/#{sk_doc}"
load doc_skin
break
end
end
filename_homepage=File.new("#{@env.path.webserv}/#{@env.path.stub_pwd}/index.html",'w')
filename_homepage_toc=File.new("#{@env.path.webserv}/#{@env.path.stub_pwd}/toc.html",'w')
filename_homepage << @vz_home.homepage
filename_homepage_toc << @vz_home.homepage
end
end
def cp_images(src_path,dest_path)
if FileTest.directory?(src_path)
FileUtils::cd(src_path)
source=Dir.glob("*.{png,jpg,gif,ico}")
FileUtils::mkdir_p(dest_path) unless FileTest.directory?(dest_path)
FileUtils::chmod(0755,dest_path)
source.each do |i|
FileUtils::cp_r(i,"#{dest_path}/#{i}")
FileUtils::chmod(0644,"#{dest_path}/#{i}")
end
FileUtils::cd(@pwd)
else puts "\tWARN, did not find - #{src_path}"
end
end
def cp_local_images
src="#{@pwd}/_sisu/image"
dest="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image"
cp_images(src,dest)
end
def cp_external_images
src="#{@env.processing_path.processing}/external_document/image"
dest="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image_external"
if FileTest.directory?(src)
cp_images(src,dest)
end
end
def cp_webserver_images
src=@env.path.image_source
dest="#{@env.path.webserv}/_sisu/image"
cp_images(src,dest)
end
def cp_webserver_images_local #this should not have been necessary
src=@env.path.image_source
dest="#{@env.path.webserv}/#{@env.path.stub_pwd}/_sisu/image"
cp_images(src,dest)
end
def cp_base_images #fix images
src="#{@env.path.share}/image"
dest="#{@env.path.webserv}/_sisu/image_sys"
cp_images(src,dest)
end
def cp_css
FileUtils::mkdir_p("#{@env.path.output}/#{@env.path.style}") unless FileTest.directory?("#{@env.path.output}/#{@env.path.style}")
css_path=['/etc/sisu/css',"#{@home}/.sisu/css","#{@pwd}/_sisu/css"] #BROKEN
if defined? @rc['permission_set']['css_modify'] \
and @rc['permission_set']['css_modify']
SiSU_Screen::Ansi.new(@cmd,"modify is css set to: #{@rc['permission_set']['css_modify']}").warn if @cmd=~/[MV]/
css_path.each do |x|
if FileTest.directory?(x)
FileUtils::cd(x)
source=Dir.glob("*.{css}")
source.each do |i|
FileUtils::cp(i,"#{@env.path.output}/#{@env.path.style}")
end
FileUtils::cd(@pwd)
end
end
else SiSU_Screen::Ansi.new(@cmd,"modify css is not set or is set to: false").warn if @cmd=~/[MV]/
end
fn_css=SiSU_Env::CSS_Default.new
css=SiSU_Style::CSS.new
path_style="#{@env.path.output}/#{@env.path.style}"
FileUtils::mkdir_p(path_style) unless FileTest.directory?(path_style)
style=File.new("#{path_style}/#{fn_css.homepage}",'w')
style << css.homepage
style.close
style=File.new("#{path_style}/#{fn_css.html_tables}",'w')
style << css.html_tables
style.close
style=File.new("#{path_style}/#{fn_css.html}",'w')
style << css.html
style.close
style=File.new("#{path_style}/#{fn_css.xml_sax}",'w')
style << css.xml_sax
style.close
style=File.new("#{path_style}/#{fn_css.xml_dom}",'w')
style << css.xml_dom
style=File.new("#{path_style}/#{fn_css.docbook_xml}",'w')
style << css.docbook_xml
style.close
style=File.new("#{path_style}/#{fn_css.xhtml}",'w')
style << css.xhtml
style=File.new("#{path_style}/#{fn_css.harvest}",'w')
style << css.harvest
style.close
end
end
end
module SiSU_Screen
require_relative 'screen_text_color' # screen_text_color.rb
end
module SiSU_Errors
require_relative 'errors' # errors.rb
end
__END__
https? intro check 2007-09-22
fns_array=unless fns =~/\.ssm.sst$/
if RUBY_VERSION < '1.9'
IO.readlines(fns,'')
else IO.readlines(fns,'r:utf-8')
end
else
if RUBY_VERSION < '1.9'
IO.readlines("#{processing_path.composite_file}/#{fns}",'')
else IO.readlines("#{processing_path.composite_file}/#{fns}",'r:utf-8')
end
end