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_name` chroot.
-
#stop ⇒ nil
Stops current chroot session.
Constructor Details
#initialize(chroot_name = 'default', &block) ⇒ Schroot
Returns a new instance of Schroot.
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/schroot.rb', line 102 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.
204 205 206 |
# File 'lib/schroot.rb', line 204 def chroot @chroot end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
204 205 206 |
# File 'lib/schroot.rb', line 204 def location @location end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
204 205 206 |
# File 'lib/schroot.rb', line 204 def logger @logger end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
204 205 206 |
# File 'lib/schroot.rb', line 204 def session @session end |
Instance Method Details
#clone ⇒ Object
Clones current session
161 162 163 |
# File 'lib/schroot.rb', line 161 def clone return Schroot.new(@chroot) end |
#log(log = @logger) ⇒ Object
Sets log object
198 199 200 201 |
# File 'lib/schroot.rb', line 198 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.
154 155 156 |
# File 'lib/schroot.rb', line 154 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.
170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/schroot.rb', line 170 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.
188 189 190 191 192 193 194 195 |
# File 'lib/schroot.rb', line 188 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 |