Class: SiSU_Sys_Call::SystemCall

Inherits:
Object
  • Object
show all
Defined in:
lib/sisu/se_programs.rb

Direct Known Subclasses

SiSU_Env::SystemCall

Constant Summary collapse

@@locale_flag =
false

Instance Method Summary collapse

Constructor Details

#initialize(input = '', output = '', opt_or_cmd = '') ⇒ SystemCall

Returns a new instance of SystemCall.



64
65
66
67
68
69
70
71
# 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

Instance Method Details

#create_pg_db(dbname_stub = nil) ⇒ Object

createdb



220
221
222
223
224
225
226
227
228
229
230
231
232
# 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

#cvsObject

cvs for document markup data



125
126
127
128
129
130
131
132
133
134
# 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 = '') ⇒ Object

file encoding



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# 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

#graphicsmagickObject

graphicsmagick is a image manipulation program



258
259
260
261
262
263
264
# 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

#imagemagickObject

found



251
252
253
254
255
256
257
# 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') ⇒ Object

convert from latex to pdf



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# 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

#localeObject

locales utf8 or other



76
77
78
79
80
81
# File 'lib/sisu/se_programs.rb', line 76

def locale                         #locales utf8 or other
  unless @@locale_flag
    @@locale_flag=true
  end
  @sys.locale
end

#makeinfoObject

texinfo



313
314
315
316
317
318
319
320
# 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) ⇒ Object

md5 dgst



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# 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

#opensslObject

openssl for digests



155
156
157
158
159
160
161
162
163
164
# 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

#po4aObject

po4a



135
136
137
138
139
140
141
142
143
144
# 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) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
75
# 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

#psqlObject

psql



210
211
212
213
214
215
216
217
218
219
# 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

#qrencodeObject

qrcode - for generating QR code



240
241
242
243
244
245
246
247
248
249
250
# 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

#rcsObject

rcs for document markup data



115
116
117
118
119
120
121
122
123
124
# 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 = '') ⇒ Object

trang - convert between different schema languages for XML



233
234
235
236
237
238
239
# 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

#rmObject



354
355
356
357
358
359
360
361
# 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) ⇒ Object



325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# 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

#scpObject



321
322
323
324
# File 'lib/sisu/se_programs.rb', line 321

def scp
  puts "scp -Cr #{@input} #{@output}" if @cmd =~/[vVM]/
  puts "scp disabled"
end

#sha256(filename) ⇒ Object

sha dgst



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# 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) ⇒ Object

sha dgst



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# 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_engineObject



272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# 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

#wcObject

word count



102
103
104
105
106
107
108
109
110
111
112
113
114
# 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?Boolean

tidy - check for well formed xml xhtml etc.

Returns:

  • (Boolean)


265
266
267
268
269
270
271
# 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

#zipObject

zip



145
146
147
148
149
150
151
152
153
154
# 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