Class: Bwrap::Execution::Popen2e

Inherits:
Object
  • Object
show all
Includes:
Output
Defined in:
lib/bwrap/execution/popen2e.rb

Overview

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Output

debug?, debug_output, error_output, handle_output_options, info_output, quiet?, trace?, trace_output, verb_output, verbose?, warn_output

Constructor Details

#initialize(rootcmd: nil, config: nil) ⇒ Popen2e

Returns a new instance of Popen2e.

Parameters:

  • rootcmd (Array|Symbol) (defaults to: nil)

    Flags used to construct bubblewrap environment

  • config (Bwrap::Config) (defaults to: nil)

    Configuration used to launch the command inside bubblewrap



15
16
17
18
# File 'lib/bwrap/execution/popen2e.rb', line 15

def initialize rootcmd: nil, config: nil
  self.rootcmd = rootcmd
  self.config = config
end

Instance Attribute Details

#dry_run=(value) ⇒ Object (writeonly)

Sets the attribute dry_run

Parameters:

  • value

    the value to set the attribute dry_run to.



11
12
13
# File 'lib/bwrap/execution/popen2e.rb', line 11

def dry_run=(value)
  @dry_run = value
end

Instance Method Details

#child_statusProcess::Status|nil

Only contains ‘Process::Status` if no block has been passed to #popen2e.

Returns:

  • (Process::Status|nil)

    Exit status of the process



93
94
95
# File 'lib/bwrap/execution/popen2e.rb', line 93

def child_status
  @child_status
end

#config=(value) ⇒ Object

Parameters:

  • value (Bwrap::Config)

    Configuration used to launch the command inside bubblewrap



21
22
23
24
25
26
27
28
# File 'lib/bwrap/execution/popen2e.rb', line 21

def config= value
  @config = value

  return unless @config and @rootcmd

  error "Only either rootcmd or config object can be given to popen2e. " \
        "Please set rootcmd to nil if wanting to use config object."
end

#popen2e(*cmd, **kwargs, &block) ⇒ Array<(IO, IO, Thread)>

Note:

Also options accepted by upstream’s ‘Open3.popen2e` are accepted here, in addition to those specified here.

Returns Write and read ‘IO` and a wait thread.

Parameters:

  • kwargs (Hash)

    a customizable set of options

Options Hash (**kwargs):

  • log (Boolean) — default: true

    If true, prints output if verbose flag has been set. And if a log file has been configured, also logs to that file

  • log_callback (Integer) — default: 3

    Semi-internal variable used to tailor caller in debug messages

Yield Returns:

  • In case a block is given, its return value is also returned by popen2e

Returns:

  • (Array<(IO, IO, Thread)>)

    Write and read ‘IO` and a wait thread

See Also:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/bwrap/execution/popen2e.rb', line 61

def popen2e *cmd, **kwargs, &block
  @log            = kwargs.key?(:log)           ? kwargs.delete(:log)           : true
  @log_callback   = kwargs.key?(:log_callback)  ? kwargs.delete(:log_callback)  : 1

  @log_callback += 1 # Passing to another method, so need to add one more.

  self.opts_from_input = cmd
  if kwargs
    @opts ||= {}
    @opts.merge! kwargs
  end

  resolve_actual_command cmd

  return if dry_run?

  open_pipes
  child_io = [ @in_read, @out_write ]
  parent_io = [ @in_write, @out_read ]
  popen_run(@actual_command, child_io, parent_io, &block)
ensure
  if block
    @in_read.close
    @in_write.close
    @out_read.close
    @out_write.close
  end
end

#rootcmd=(value) ⇒ Object

Can be used to implement kind of tag based bubblewrap command things. This system is not well documented, and originally done for purposes of the code where this gem was splitted from.

Probably using #config= instead makes more sense.

Parameters:

  • value (Array|Symbol)

    Flags used to construct bubblewrap environment



37
38
39
40
41
42
43
44
# File 'lib/bwrap/execution/popen2e.rb', line 37

def rootcmd= value
  @rootcmd = value

  return unless @config and @rootcmd

  error "Only either rootcmd or config object can be given to popen2e. " \
        "Please set config to nil if wanting to use rootcmd flags."
end