Class: Schroot
- Inherits:
-
Object
- Object
- Schroot
- Defined in:
- lib/schroot.rb
Overview
Schroot session handler
Instance Attribute Summary collapse
-
#chroot ⇒ Object
readonly
Returns the value of attribute chroot.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
-
#clone ⇒ Object
Clones current session.
-
#initialize(chroot_name = 'default', &block) ⇒ Schroot
constructor
A new instance of Schroot.
-
#log(log = @logger) ⇒ Object
Sets log object.
-
#run(cmd, kwargs = {}) ⇒ Array<(IO:fd, IO:fd, IO:fd)>
Runs command inside of chroot session.
-
#start(chroot_name = 'default') ⇒ String
Starts the session of
chroot_namechroot. -
#stop ⇒ nil
Stops current chroot session.
Constructor Details
#initialize(chroot_name = 'default', &block) ⇒ Schroot
Returns a new instance of Schroot.
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/schroot.rb', line 100 def initialize(chroot_name = 'default', &block) @logger = Logger.new nil if block_given? if block.arity == 1 yield self elsif block.arity == 0 instance_eval &block end end start(chroot_name) end |
Instance Attribute Details
#chroot ⇒ Object (readonly)
Returns the value of attribute chroot.
202 203 204 |
# File 'lib/schroot.rb', line 202 def chroot @chroot end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
202 203 204 |
# File 'lib/schroot.rb', line 202 def location @location end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
202 203 204 |
# File 'lib/schroot.rb', line 202 def logger @logger end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
202 203 204 |
# File 'lib/schroot.rb', line 202 def session @session end |
Instance Method Details
#clone ⇒ Object
Clones current session
159 160 161 |
# File 'lib/schroot.rb', line 159 def clone return Schroot.new(@chroot) end |
#log(log = @logger) ⇒ Object
Sets log object
196 197 198 199 |
# File 'lib/schroot.rb', line 196 def log(log=@logger) @logger = log @logger.debug("Hello there!") end |
#run(cmd, kwargs = {}) ⇒ Array<(IO:fd, IO:fd, IO:fd)>
Runs command inside of chroot session. Session must be started before.
152 153 154 |
# File 'lib/schroot.rb', line 152 def run(cmd, kwargs = {}) return safe_run(command(cmd,kwargs)) end |
#start(chroot_name = 'default') ⇒ String
Starts the session of chroot_name chroot
A string representing schroot session id.
168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/schroot.rb', line 168 def start(chroot_name = 'default') @logger.debug("Starting chroot session") stop if @session command = ['schroot', '-b', '-c', chroot_name] ObjectSpace.define_finalizer(self, proc { stop }) stdin, stdout, stderr = safe_run("schroot -b -c %s" % chroot_name) @chroot = chroot_name @session = stdout.gets.strip stdin, stdout, stderr = safe_run("schroot --location -c session:%s" % @session) @location = stdout.gets.strip @logger.debug("Session %s with %s started in %s" % [@session, @chroot, @location]) return @session end |
#stop ⇒ nil
Stops current chroot session.
186 187 188 189 190 191 192 193 |
# File 'lib/schroot.rb', line 186 def stop @logger.debug("Stopping session %s with %s" % [@session, @chroot]) stdin, stdout, stderr = safe_run("schroot -e -c %s" % @session) @logger.debug("Session %s of %s should be stopped" % [@session, @chroot]) @location = nil @session = nil end |