schroot 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4afb334d0392c2fece917bd556b440fc9ad6d176
4
- data.tar.gz: 75ddbcbf2e08d790a50d00d1a1def897a6ddcd2a
3
+ metadata.gz: 4a0c0b5f738ac94f2f9654bc3c28ff112cd9d418
4
+ data.tar.gz: a4911cd4cacb8733ea288ba98ee86bb5950e1751
5
5
  SHA512:
6
- metadata.gz: 74f6c50acf2010df3c67fffcbc0ff6563db360af013b5a89f2be42cac3164370084682cbcbe8f7249a69d78acaff9eda2ad558626d4c6d78859234f910da7cf2
7
- data.tar.gz: 9bc659b87783e2680e963dc694831827e333cbb93b1755d5b16d1dbfcdbcd291228212ce14904dac766cf2521ba352d36e4d1e07dd8b7607fe873f94282138d4
6
+ metadata.gz: 85f36a9bec55db7c30d6fcd59984b6ff0b4b0fdc68e8343c9b2fc88a51d38c435ad0252aa46724b87b0bb5ea003455768fa5d88499937adf742b8a9f71022cce
7
+ data.tar.gz: 5cff5dcd73a03e7a35743b2a72a9f6fd1a3ee83beec29b85274e38992becf20d09bd8e9c65e482251c289acafc642be4e5c5f0a0a14ea9803e2643e1c301fbc2
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Schroot
1
+ # Schroot [![Gem Version](https://badge.fury.io/rb/schroot.png)](http://badge.fury.io/rb/schroot)
2
2
 
3
3
  Schroot gem allows to create `schroot` sessions and execute commands in the chroot environment from ruby code.
4
4
 
@@ -8,6 +8,7 @@ module Schroot
8
8
  CONF_D='/etc/schroot/chroot.d/'
9
9
  CONF_D_PREFIX='99ruby-'
10
10
 
11
+
11
12
  class SchrootError < StandardError
12
13
  end
13
14
 
@@ -16,7 +17,7 @@ module Schroot
16
17
  chroots = {}
17
18
  files = [BASE_CONF]
18
19
  Dir.entries(CONF_D).each do |file|
19
- files << (CONF_D+CONF_D_PREFIX+file) unless %w(. ..).include? file
20
+ files << (CONF_D+file) unless %w(. ..).include? file
20
21
  end
21
22
  files.each do |file|
22
23
  stream = File.open(file, 'r')
@@ -76,6 +77,30 @@ module Schroot
76
77
  return true
77
78
  end
78
79
 
80
+ # Installs base Debian system, into chroot using debootstrap
81
+ #
82
+ # @example
83
+ # bootstrap('my_chroot', 'testing', log: Logger.new(STDOUT))
84
+ # @param name [String] VM's name (should be defined in schroot config)
85
+ # @param release [String] Release to install (e.g. 'sid', 'jessie', 'stable')
86
+ # @param mirror [String] What debian mirror should we use
87
+ # @param log [Logger] Where should be put bootstrap logs
88
+ def self.bootstrap (name, release, mirror: 'http://http.debian.net/debian/', log: Logger.new(nil), &block)
89
+ chroots = read_config
90
+ directory = chroots[name]['directory']
91
+ if directory and ::File.exists? directory
92
+ command = "debootstrap #{release} #{directory} #{mirror}"
93
+ log.info 'Running `%s`' % command
94
+ Open3.popen2e(command) do |stdin, stdout_and_stderr, wait_thr|
95
+ log.info 'PID: %s' % wait_thr.pid
96
+ while line = stdout_and_stderr.gets do
97
+ log.debug line.strip
98
+ end
99
+ log.info 'Exited with %s' % wait_thr.value
100
+ end
101
+ end
102
+ end
103
+
79
104
  # Removes chroot from .../chroot.d/ directory
80
105
  #
81
106
  # @example
@@ -126,7 +151,7 @@ module Schroot
126
151
  raise SchrootError, 'Schroot binary is missing!'
127
152
  end
128
153
  @logger.info('Done!')
129
- return stream
154
+ stream
130
155
  end
131
156
 
132
157
  def command(cmd, user, preserve_environment)
@@ -150,12 +175,13 @@ module Schroot
150
175
  #
151
176
  # @example
152
177
  # session.run("uname -a",
153
- # :user => 'rainbowdash',
154
- # :preserve_environment => true) do |stdin, stdout, stderr, wait_thr|
178
+ # user: 'rainbowdash',
179
+ # preserve_environment: true) do |stdin, stdout, stderr, wait_thr|
155
180
  # puts wait_thr.pid, wait_thr.value, stdout.read
156
181
  # end
157
182
  # @param cmd [String] command to run
158
183
  # @param user [String] user
184
+ # @param preserve_environment [Bool] Should we preserve environment variables
159
185
  def run(cmd, user: nil, preserve_environment: nil, &block)
160
186
  safe_run(command(cmd, user, preserve_environment)) do |stdin, stout, stderr, wait_thr|
161
187
  if block_given?
@@ -165,6 +191,29 @@ module Schroot
165
191
  end
166
192
  end
167
193
 
194
+ # Copies file from or to the chroot
195
+ #
196
+ # @param what [String] Source path
197
+ # @param where [String] Destination path
198
+ # @param whence [Symbol] Defines where should we dst file: from host (:host) or from chroot (:chroot)
199
+ def copy(what, where, whence: :host, recursive: false)
200
+ if whence == :host
201
+ where = File.join(@location, where)
202
+ elsif whence == :chroot
203
+ what = File.join(@location, what)
204
+ else
205
+ return nil
206
+ end
207
+ flags = ''
208
+ if recursive
209
+ flags << '-r'
210
+ end
211
+
212
+ safe_run('cp %s %s %s' % [flags, cwhat, where]) do |stdin, stout, stderr, wait_thr|
213
+ wait_thr.value
214
+ end
215
+ end
216
+
168
217
  # Clones current session
169
218
  #
170
219
  # @return [Object] new session object
@@ -175,15 +224,15 @@ module Schroot
175
224
  # Starts the session of `chroot_name` chroot
176
225
  #
177
226
  # @param chroot_name [String] name of configured chroot
178
- # @return [String] schroot session id
179
- # A string representing schroot session id.
227
+ # @return [String] A string representing schroot session id.
180
228
  def start(chroot_name = 'default')
181
229
  @logger.debug('Starting chroot session')
182
230
  stop if @session
183
231
  ObjectSpace.define_finalizer(self, proc { stop })
184
- state = safe_run('schroot -b -c %s' % chroot_name) do |stdin, stdout, stderr, wait_thr|
232
+ safe_run('schroot -b -c %s' % chroot_name) do |stdin, stdout, stderr, wait_thr|
185
233
  wait_thr.value
186
234
  @session = stdout.gets.strip
235
+ @session
187
236
  end
188
237
 
189
238
  @chroot = chroot_name
@@ -204,7 +253,6 @@ module Schroot
204
253
  @logger.debug('Session %s of %s should be stopped' % [@session, @chroot])
205
254
  @location = nil
206
255
  @session = nil
207
-
208
256
  end
209
257
 
210
258
  # Sets log object
@@ -216,5 +264,4 @@ module Schroot
216
264
  private :safe_run, :command
217
265
  attr_reader :session, :location, :chroot, :logger
218
266
  end
219
-
220
267
  end
@@ -1,3 +1,3 @@
1
1
  module Schroot
2
- VERSION = "0.0.8"
2
+ VERSION = '0.0.9'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schroot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniil Guzanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-20 00:00:00.000000000 Z
11
+ date: 2014-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler