class SiSU_Sys_Call::SystemCall

Public Class Methods

new(input='',output='',opt_or_cmd='') click to toggle source
# File lib/sisu/se_programs.rb, line 64
def initialize(input='',output='',opt_or_cmd='')
  @input,@output=input,output
  (opt_or_cmd.is_a?(SiSU_Commandline::Options)) \
  ? (@cmd,@opt=opt_or_cmd.cmd,opt_or_cmd)
  : (@cmd,@opt=opt_or_cmd,nil) #cmd.is_a?(String)
  @prog=SiSU_Env::InfoProgram.new
  @sys=SiSU_Info_Sys::InfoSystem.instance
end

Public Instance Methods

create_pg_db(dbname_stub=nil) click to toggle source
# File lib/sisu/se_programs.rb, line 220
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}")
  : (STDERR.puts "\t*WARN* #{program} is not available #{program_ref}")
end
cvs() click to toggle source
# File lib/sisu/se_programs.rb, line 125
def cvs                            #cvs for document markup data
  program='cvs'
  program_ref="\n\t\tdocument version information requested"
  if program_found?(program); true
  else
    SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
      warn("#{program} is not installed #{program_ref}")
    false
  end
end
file_encoding(filename,act='') click to toggle source
# File lib/sisu/se_programs.rb, line 82
def file_encoding(filename,act='') #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=encoding.gsub(/#{fnsp}:(\s+|$)/,'')
    encoding=if encoding \
    and not encoding.empty?
      encoding
    else 'UTF-8 assumed, encoding undetermined'
    end
    if act[:verbose_plus][:set] ==:on \
    or  act[:maintenance][:set] ==:on
      puts encoding
    end
    encoding
  else
    'UTF-8 assumed, file encoding check program unavailable'
  end
end
graphicsmagick() click to toggle source
# File lib/sisu/se_programs.rb, line 258
def graphicsmagick                #graphicsmagick is a image manipulation program
  program='gm'
  #program_ref="\n\t\tsee <http://www.graphicsmagick.org/>"
  found=(program_found?(program)) ? true : false
  #STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}" unless found
  found
end
imagemagick() click to toggle source
# File lib/sisu/se_programs.rb, line 251
def imagemagick                    #imagemagick is a image manipulation program
  program='identify'
  #program_ref="\n\t\tsee <http://www.imagemagick.org/>"
  found=(program_found?(program)) ? true : false
  #STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}" unless found
  found
end
latex2pdf(md,papersize='a4') click to toggle source
# File lib/sisu/se_programs.rb, line 289
def latex2pdf(md,papersize='a4')   #convert from latex to pdf
  tell=if @cmd =~/[MV]/
    ''
  elsif @cmd =~/[v]/
    %q{2>&1 | grep -v ' WARNING '}
  else %q{2>&1 | grep -v '$'}
  end
  mode='batchmode' #mode='nonstopmode'
  texpdf=tex2pdf_engine
  if @pdfetex_flag
    texpdf_cmd=case texpdf
    when /xetex/
      %{#{texpdf} -interaction=#{mode} -fmt=xelatex -papersize="#{papersize}" #{@input} #{tell}\n}
    when /xelatex/
      %{#{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 STDERR.puts "\t*WARN* none of the following programs are installed: #{@texpdf}"
  end
end
locale() click to toggle source
# File lib/sisu/se_programs.rb, line 76
def locale                         #locales utf8 or other
  unless @@locale_flag
    @@locale_flag=true
  end
  @sys.locale
end
makeinfo() click to toggle source
# File lib/sisu/se_programs.rb, line 313
def makeinfo                       #texinfo
  program='makeinfo'
  options='' #'--force' #''
  program_ref="\n\t\tsee http://www.gnu.org/software/texinfo/"
  (program_found?(program)) \
  ? system("#{program} #{options} #{@input}\n")
  : (STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}")
end
md5(filename) click to toggle source
# File lib/sisu/se_programs.rb, line 165
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
    SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
      warn("#{program} is not installed #{program_ref}")
    false
  end
end
openssl() click to toggle source
# File lib/sisu/se_programs.rb, line 155
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
    SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
      warn("#{program} is not installed #{program_ref}")
    false
  end
end
po4a() click to toggle source
# File lib/sisu/se_programs.rb, line 135
def po4a                           #po4a
  program='po4a'
  program_ref="\n\t\tpo4a"
  if program_found?(program); true
  else
    SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
      warn("#{program} is not installed #{program_ref}")
    false
  end
end
program_found?(program) click to toggle source
# File lib/sisu/se_programs.rb, line 72
def program_found?(program)
  found=`which #{program} 2>&1` #`whereis #{program}`
  (found =~/bin\/#{program}\b/) ? true : false
end
psql() click to toggle source
# File lib/sisu/se_programs.rb, line 210
def psql                           #psql
  program='psql'
  program_ref="\n\t\tpsql requested"
  if program_found?(program); true
  else
    SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
      warn("#{program} is not installed #{program_ref}")
    false
  end
end
qrencode() click to toggle source
# File lib/sisu/se_programs.rb, line 240
def qrencode                       #qrcode - for generating QR code
  program='qrencode'
  program_ref="\n\t\tsee <http://megaui.net/fukuchi/works/qrencode/index.en.html>"
  found=(program_found?(program)) ? true : false
  found \
  ? (system(%{
      echo "#{@input}" | #{program} -s 3 -o #{@output}
    }))
  : (STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}" if @cmd =~/V/)
  #found
end
rcs() click to toggle source
# File lib/sisu/se_programs.rb, line 115
def rcs                            #rcs for document markup data
  program='rcs'
  program_ref="\n\t\tdocument version information requested"
  if program_found?(program); true
  else
    SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
      warn("#{program} is not installed #{program_ref}")
    false
  end
end
relaxng(cmd='') click to toggle source
# File lib/sisu/se_programs.rb, line 233
def relaxng(cmd='')                #trang - convert between different schema languages for XML
  program='trang'
  program_ref="\n\t\tsee <http://www.thaiopensource.com/relaxng/trang.html>"
  (program_found?(program)) \
  ? system("#{program} #{@input} #{@output}")
  : (STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}" if cmd =~/V/)
end
rm() click to toggle source
# File lib/sisu/se_programs.rb, line 354
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                           STDERR.puts "\t*WARN* operation ignored"
  end
end
rsync(action='',chdir=nil) click to toggle source
# File lib/sisu/se_programs.rb, line 325
def rsync(action='',chdir=nil)
  program='rsync'
  if program_found?(program)
    vb=if @cmd =~/q/; 'q'
    elsif @cmd =~/v/; 'v'
    else              ''
    end
    cX=SiSU_Screen::Ansi.new(@cmd).cX
    msg=(@cmd =~/q/) ? '' : %{ && echo " #{cX.grey}OK: #{@input} -> #{@output}#{cX.off}"}
    amp=(@opt \
    && @opt.files.length > 1) \
    ? ''
    : ((@cmd =~/[vVM]/) ? '' : '&')
    rsync_cmd="rsync -az#{vb} #{action} #{@input} #{@output}"
    puts rsync_cmd if @cmd =~/[vVM]/
    dir_change=dir_return=nil
    if not chdir.nil? \
    && chdir != Dir.pwd
      dir_change=Dir.chdir(chdir)
      dir_return=Dir.pwd
    end
    dir_change if dir_change
    system("
      #{rsync_cmd} #{msg} #{amp}
    ")
    dir_return if dir_return
  else STDERR.puts "\t*WARN* #{program} not found"
  end
end
scp() click to toggle source
# File lib/sisu/se_programs.rb, line 321
def scp
  puts "scp -Cr #{@input} #{@output}" if @cmd =~/[vVM]/
  puts "scp disabled"
end
sha256(filename) click to toggle source
# File lib/sisu/se_programs.rb, line 180
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
    SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
      warn("#{program} is not installed #{program_ref}")
    false
  end
end
sha512(filename) click to toggle source
# File lib/sisu/se_programs.rb, line 195
def sha512(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 -sha512 #{File.basename(filename)}}.strip #use file name without file path
    Dir.chdir(pwd)
    dgst.scan(/\S+/)
  else
    SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
      warn("#{program} is not installed #{program_ref}")
    false
  end
end
tex2pdf_engine() click to toggle source
# File lib/sisu/se_programs.rb, line 272
def tex2pdf_engine
  progs=['xetex','xelatex','pdflatex','pdfetex','pdftex']
  @pdfetex_flag=false
  @cmd ||=''
  @texpdf=nil
  progs.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=progs.join(', ')
  end
  @texpdf
end
wc() click to toggle source
# File lib/sisu/se_programs.rb, line 102
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
well_formed?() click to toggle source
# File lib/sisu/se_programs.rb, line 265
def well_formed?                   #tidy - check for well formed xml xhtml etc.
  program=@prog.tidy
  program_ref="\n\t\tsee <http://tidy.sourceforge.net/>"
  (program_found?(program)) \
  ? system("#{@prog.tidy} -xml #{@input} > #{@output}")
  : (STDERR.puts "\t*WARN* #{program} is not installed #{program_ref}")
end
zip() click to toggle source
# File lib/sisu/se_programs.rb, line 145
def zip                            #zip
  program='zip'
  program_ref="\n\t\tused to in the making of number of file formats, odf, epub"
  if program_found?(program); true
  else
    SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
      mark("*WARN* #{program} is not installed #{program_ref}")
    false
  end
end