Module FPM::Util
In: lib/fpm/util/tar_writer.rb
lib/fpm/util.rb
lib/fpm/util/tar_writer.rb
lib/fpm/util.rb

Some utility functions

Methods

Classes and Modules

Class FPM::Util::ExecutableNotFound
Class FPM::Util::ProcessFailed
Class FPM::Util::TarWriter

Public Instance methods

Get an array containing the recommended ‘ar’ command for this platform and the recommended options to quickly create/append to an archive without timestamps or uids (if possible).

Get an array containing the recommended ‘ar’ command for this platform and the recommended options to quickly create/append to an archive without timestamps or uids (if possible).

Return whether the command returned by ar_cmd can create deterministic archives

Return whether the command returned by ar_cmd can create deterministic archives

execmd([env,] cmd [,opts])

Execute a command as a child process. The function allows to:

  • pass environment variables to child process,
  • communicate with stdin, stdout and stderr of the child process via pipes,
  • retrieve execution‘s status code.

—- EXAMPLE 1 (simple execution)

if execmd([‘which’, ‘python’]) == 0

  p "Python is installed"

end

—- EXAMPLE 2 (custom environment variables)

execmd({:PYTHONPATH=>’/home/me/foo’}, [ ‘python’, ’-m’, ‘bar’])

—- EXAMPLE 3 (communicating via stdin, stdout and stderr)

script = <<PYTHON import sys sys.stdout.write("normal output\n") sys.stdout.write("narning or error\n") PYTHON status = execmd(‘python’) do |stdin,stdout,stderr|

  stdin.write(script)
  stdin.close
  p "STDOUT: #{stdout.read}"
  p "STDERR: #{stderr.read}"

end p "STATUS: #{status}"

—- EXAMPLE 4 (additional options)

execmd([‘which’, ‘python’], :process=>true, :stdin=>false, :stderr=>false) do |process,stdout|

 p = stdout.read.chomp
 process.wait
 if (x = process.exit_code) == 0
   p "PYTHON: #{p}"
 else
   p "ERROR:  #{x}"
 end

end

OPTIONS:

  :process (default: false) -- pass process object as the first argument the to block,
  :stdin   (default: true)  -- pass stdin object of the child process to the block for writting,
  :stdout  (default: true)  -- pass stdout object of the child process to the block for reading,
  :stderr  (default: true)  -- pass stderr object of the child process to the block for reading,

execmd([env,] cmd [,opts])

Execute a command as a child process. The function allows to:

  • pass environment variables to child process,
  • communicate with stdin, stdout and stderr of the child process via pipes,
  • retrieve execution‘s status code.

—- EXAMPLE 1 (simple execution)

if execmd([‘which’, ‘python’]) == 0

  p "Python is installed"

end

—- EXAMPLE 2 (custom environment variables)

execmd({:PYTHONPATH=>’/home/me/foo’}, [ ‘python’, ’-m’, ‘bar’])

—- EXAMPLE 3 (communicating via stdin, stdout and stderr)

script = <<PYTHON import sys sys.stdout.write("normal output\n") sys.stdout.write("narning or error\n") PYTHON status = execmd(‘python’) do |stdin,stdout,stderr|

  stdin.write(script)
  stdin.close
  p "STDOUT: #{stdout.read}"
  p "STDERR: #{stderr.read}"

end p "STATUS: #{status}"

—- EXAMPLE 4 (additional options)

execmd([‘which’, ‘python’], :process=>true, :stdin=>false, :stderr=>false) do |process,stdout|

 p = stdout.read.chomp
 process.wait
 if (x = process.exit_code) == 0
   p "PYTHON: #{p}"
 else
   p "ERROR:  #{x}"
 end

end

OPTIONS:

  :process (default: false) -- pass process object as the first argument the to block,
  :stdin   (default: true)  -- pass stdin object of the child process to the block for writting,
  :stdout  (default: true)  -- pass stdout object of the child process to the block for reading,
  :stderr  (default: true)  -- pass stderr object of the child process to the block for reading,

wrapper around mknod ffi calls

wrapper around mknod ffi calls

Is the given program in the system‘s PATH?

Is the given program in the system‘s PATH?

Run a command safely in a way that gets reports useful errors.

Run a command safely in a way that gets reports useful errors.

Run a command safely in a way that captures output and status.

Run a command safely in a way that captures output and status.

Get the recommended ‘tar’ command for this platform.

Get the recommended ‘tar’ command for this platform.

Return whether the command returned by tar_cmd can create deterministic archives

Return whether the command returned by tar_cmd can create deterministic archives

[Validate]