schroot 0.0.7 → 0.0.8
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 +4 -4
- data/Gemfile +4 -0
- data/LICENSE.txt +13 -0
- data/README.md +58 -60
- data/Rakefile +2 -9
- data/lib/schroot/version.rb +3 -0
- data/lib/schroot.rb +128 -113
- data/schroot.gemspec +25 -0
- data/test/test_schroot.rb +16 -9
- metadata +54 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4afb334d0392c2fece917bd556b440fc9ad6d176
|
|
4
|
+
data.tar.gz: 75ddbcbf2e08d790a50d00d1a1def897a6ddcd2a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 74f6c50acf2010df3c67fffcbc0ff6563db360af013b5a89f2be42cac3164370084682cbcbe8f7249a69d78acaff9eda2ad558626d4c6d78859234f910da7cf2
|
|
7
|
+
data.tar.gz: 9bc659b87783e2680e963dc694831827e333cbb93b1755d5b16d1dbfcdbcd291228212ce14904dac766cf2521ba352d36e4d1e07dd8b7607fe873f94282138d4
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
|
2
|
+
Version 2, December 2004
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2014 Daniil Guzanov <melkor217@gmail.com>
|
|
5
|
+
|
|
6
|
+
Everyone is permitted to copy and distribute verbatim or modified
|
|
7
|
+
copies of this license document, and changing it is allowed as long
|
|
8
|
+
as the name is changed.
|
|
9
|
+
|
|
10
|
+
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
|
11
|
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
12
|
+
|
|
13
|
+
0. You just DO WHAT THE FUCK YOU WANT TO.
|
data/README.md
CHANGED
|
@@ -1,80 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
============
|
|
1
|
+
# Schroot
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
Schroot gem allows to create `schroot` sessions and execute commands in the chroot environment from ruby code.
|
|
5
4
|
|
|
6
|
-
What is it?
|
|
7
|
-
--------
|
|
8
|
-
It's a gem which allows to create `schroot` sessions and execute commands in the chroot environment from ruby code.
|
|
9
5
|
Currently it just calls schroot binaries.
|
|
6
|
+
|
|
10
7
|
Ability to manage chroots (eg create) is coming soon.
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
-------
|
|
14
|
-
Library requires installed chroot binary. All chroots u want to use should be configured in `/etc/schroot/schroot.conf` or `/etc/schroot/conf.d/`.
|
|
9
|
+
## Installation
|
|
15
10
|
|
|
16
|
-
|
|
11
|
+
Add this line to your application's Gemfile:
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
type=directory
|
|
20
|
-
description=Debian sid (unstable)
|
|
21
|
-
union-type=aufs
|
|
22
|
-
directory=/srv/chroot/sid
|
|
23
|
-
users=dan
|
|
24
|
-
groups=dan
|
|
25
|
-
root-groups=root
|
|
26
|
-
aliases=unstable,default
|
|
13
|
+
gem 'schroot'
|
|
27
14
|
|
|
28
|
-
|
|
15
|
+
And then execute:
|
|
29
16
|
|
|
30
|
-
|
|
31
|
-
$ rake
|
|
32
|
-
$ gem install ./*.gem
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
or just
|
|
36
|
-
```bash
|
|
37
|
-
$ rake install
|
|
38
|
-
```
|
|
17
|
+
$ bundle
|
|
39
18
|
|
|
40
|
-
|
|
41
|
-
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install schroot
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
42
24
|
|
|
43
25
|
Simple example:
|
|
44
26
|
|
|
45
27
|
```ruby
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
28
|
+
>> require 'schroot'
|
|
29
|
+
=> true
|
|
30
|
+
>> session = Schroot::Chroot.new('sid')
|
|
31
|
+
=> #<Schroot::Chroot:0x82858b8 @logger=#<Logger:0x8285890 @progname=nil, @level=0, @default_formatter=#<Logger::Formatter:0x828587c @datetime_format=nil>, formatternil, logdevnil, session"sid-8861c7e6-2339-47b3-bdf5-d79435cefea2", chroot"sid", location"/var/lib/schroot/mount/sid-8861c7e6-2339-47b3-bdf5-d79435cefea2"
|
|
32
|
+
>> session.run("uname -a",
|
|
33
|
+
?> :user => 'rainbowdash',
|
|
34
|
+
?> :preserve_environment => true) do |stdin, stdout, stderr, wait_thr|
|
|
35
|
+
?> puts wait_thr.pid, wait_thr.value, stdout.read
|
|
36
|
+
>> end
|
|
37
|
+
30983
|
|
38
|
+
pid 30983 exit 0
|
|
39
|
+
Linux dan-desktop 3.14-1-686-pae #1 SMP Debian 3.14.2-1 (2014-04-28) i686 GNU/Linux
|
|
40
|
+
=> nil
|
|
41
|
+
|
|
54
42
|
```
|
|
55
43
|
Using logger:
|
|
56
44
|
|
|
57
45
|
```ruby
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
46
|
+
>> require 'schroot'
|
|
47
|
+
=> true
|
|
48
|
+
>> session = Schroot::Chroot.new('sid') do
|
|
49
|
+
?> log Logger.new(STDOUT)
|
|
50
|
+
>> end
|
|
51
|
+
D, [2014-05-20T02:06:06.278458 #32663] DEBUG -- : Hello there!
|
|
52
|
+
D, [2014-05-20T02:06:06.278572 #32663] DEBUG -- : Starting chroot session
|
|
53
|
+
I, [2014-05-20T02:06:06.278632 #32663] INFO -- : Executing schroot -b -c sid
|
|
54
|
+
I, [2014-05-20T02:06:06.454060 #32663] INFO -- : Done!
|
|
55
|
+
I, [2014-05-20T02:06:06.454199 #32663] INFO -- : Executing schroot --location -c session:sid-0a254101-12c2-44d6-a1b8-60a88e81b427
|
|
56
|
+
I, [2014-05-20T02:06:06.465670 #32663] INFO -- : Done!
|
|
57
|
+
D, [2014-05-20T02:06:06.465802 #32663] DEBUG -- : Session sid-0a254101-12c2-44d6-a1b8-60a88e81b427 with sid started in /var/lib/schroot/mount/sid-0a254101-12c2-44d6-a1b8-60a88e81b427
|
|
58
|
+
=> #<Schroot::Chroot:0x924f85c @logger=#<Logger:0x924f640 @progname=nil, @level=0, @default_formatter=#<Logger::Formatter:0x924f62c @datetime_format=nil>, formatternil, logdev#<Logger::LogDevice:0x924f604 @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>, mutex#<Logger::LogDevice::LogDeviceMutex:0x924f5f0 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Mutex:0x924f5c8>, session"sid-0a254101-12c2-44d6-a1b8-60a88e81b427", chroot"sid", location"/var/lib/schroot/mount/sid-0a254101-12c2-44d6-a1b8-60a88e81b427"
|
|
59
|
+
>> session.run("whoami") { |stdin, stdout| puts stdout.read }
|
|
60
|
+
I, [2014-05-20T02:06:16.607930 #32663] INFO -- : Executing schroot -r -c sid-0a254101-12c2-44d6-a1b8-60a88e81b427 -- whoami
|
|
61
|
+
dan
|
|
62
|
+
I, [2014-05-20T02:06:16.677187 #32663] INFO -- : Done!
|
|
63
|
+
=> #<Process::Status: pid 329 exit 0>
|
|
64
|
+
>> session.stop
|
|
65
|
+
D, [2014-05-20T02:06:35.798690 #32663] DEBUG -- : Stopping session sid-0a254101-12c2-44d6-a1b8-60a88e81b427 with sid
|
|
66
|
+
I, [2014-05-20T02:06:35.798781 #32663] INFO -- : Executing schroot -e -c sid-0a254101-12c2-44d6-a1b8-60a88e81b427
|
|
67
|
+
I, [2014-05-20T02:06:36.021379 #32663] INFO -- : Done!
|
|
68
|
+
D, [2014-05-20T02:06:36.021518 #32663] DEBUG -- : Session sid-0a254101-12c2-44d6-a1b8-60a88e81b427 of sid should be stopped
|
|
69
|
+
=> nil
|
|
79
70
|
```
|
|
80
71
|
|
|
72
|
+
## Contributing
|
|
73
|
+
|
|
74
|
+
1. Fork it ( https://github.com/melkor217/ruby-schroot/fork )
|
|
75
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
76
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
77
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
78
|
+
5. Create a new Pull Request
|
data/Rakefile
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
+
require "bundler"
|
|
1
2
|
require 'rake/testtask'
|
|
2
3
|
|
|
3
4
|
Rake::TestTask.new do |t|
|
|
4
5
|
t.libs << 'test'
|
|
5
6
|
end
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
system "gem build schroot.gemspec"
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
task :install => :build do
|
|
12
|
-
system "sudo gem install schroot-*.gem"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
task :default => :build
|
|
8
|
+
Bundler::GemHelper.install_tasks
|
data/lib/schroot.rb
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
require 'open3'
|
|
2
2
|
require 'logger'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# @return [Hash] representation of current config
|
|
15
|
-
def self.
|
|
4
|
+
module Schroot
|
|
5
|
+
|
|
6
|
+
SCHROOT_BASE='/var/lib/schroot'
|
|
7
|
+
BASE_CONF='/etc/schroot/schroot.conf'
|
|
8
|
+
CONF_D='/etc/schroot/chroot.d/'
|
|
9
|
+
CONF_D_PREFIX='99ruby-'
|
|
10
|
+
|
|
11
|
+
class SchrootError < StandardError
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# @return [Hash] representation of current config files
|
|
15
|
+
def self.read_config
|
|
16
16
|
chroots = {}
|
|
17
17
|
files = [BASE_CONF]
|
|
18
18
|
Dir.entries(CONF_D).each do |file|
|
|
19
|
-
files << (CONF_D+CONF_D_PREFIX+file) unless
|
|
19
|
+
files << (CONF_D+CONF_D_PREFIX+file) unless %w(. ..).include? file
|
|
20
20
|
end
|
|
21
21
|
files.each do |file|
|
|
22
|
-
stream = File.open(file,
|
|
22
|
+
stream = File.open(file, 'r')
|
|
23
23
|
current = nil
|
|
24
|
-
while
|
|
24
|
+
while line = stream.gets
|
|
25
25
|
if match_name(line)
|
|
26
26
|
current = match_name(line)[1]
|
|
27
|
-
chroots[current.strip] = {
|
|
27
|
+
chroots[current.strip] = {:source => file}
|
|
28
28
|
elsif current and match_param(line)
|
|
29
|
-
param, value = match_param(line)[1],match_param(line)[2]
|
|
29
|
+
param, value = match_param(line)[1], match_param(line)[2]
|
|
30
30
|
chroots[current][param.strip] = value.strip if current
|
|
31
31
|
end
|
|
32
32
|
end
|
|
@@ -36,11 +36,11 @@ class SchrootConfig
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
def self.match_name(name)
|
|
39
|
-
return /^\s*\[([a-z0-9A-Z
|
|
39
|
+
return /^\s*\[([a-z0-9A-Z\-_]+)\]/.match(name)
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def self.match_param(param)
|
|
43
|
-
return /^\s*([a-z0-9A-Z
|
|
43
|
+
return /^\s*([a-z0-9A-Z\-_]+)=(.*)$/.match(param)
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
# Adds new chroot configuration to .../chroot.d/ directory
|
|
@@ -56,17 +56,17 @@ class SchrootConfig
|
|
|
56
56
|
# @param force [Bool] should we override existing config
|
|
57
57
|
# @return [Bool] true if operation has completed successfully
|
|
58
58
|
def self.add(name, kwargs = {}, force=false)
|
|
59
|
-
chroots =
|
|
59
|
+
chroots = read_config
|
|
60
60
|
filename = CONF_D+CONF_D_PREFIX+name
|
|
61
61
|
if (chroots[name] or File.exists?(filename)) and !force
|
|
62
62
|
return false
|
|
63
63
|
else
|
|
64
64
|
begin
|
|
65
|
-
stream = File.open(filename,
|
|
65
|
+
stream = File.open(filename, 'w')
|
|
66
66
|
rescue Errno::EACCES
|
|
67
67
|
raise SchrootError, "Cannot open #{filename} for writing"
|
|
68
68
|
end
|
|
69
|
-
stream.puts
|
|
69
|
+
stream.puts '# Generated automatically with ruby-schroot'
|
|
70
70
|
stream.puts "[#{name}]"
|
|
71
71
|
kwargs.each do |param, value|
|
|
72
72
|
stream.puts "#{param}=#{value}"
|
|
@@ -86,7 +86,7 @@ class SchrootConfig
|
|
|
86
86
|
# @param force [Bool] should we override existing config
|
|
87
87
|
# @return [Bool] true if operation has completed successfully
|
|
88
88
|
def self.remove(name, force=false)
|
|
89
|
-
chroots =
|
|
89
|
+
chroots = read_config
|
|
90
90
|
filename = CONF_D+CONF_D_PREFIX+name
|
|
91
91
|
if (File.exists?(filename) and chroots[name]) or force
|
|
92
92
|
File.delete(filename)
|
|
@@ -95,111 +95,126 @@ class SchrootConfig
|
|
|
95
95
|
return false
|
|
96
96
|
end
|
|
97
97
|
end
|
|
98
|
-
|
|
98
|
+
|
|
99
99
|
|
|
100
100
|
# Schroot session handler
|
|
101
|
-
class
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
101
|
+
class Chroot
|
|
102
|
+
def initialize(chroot_name = 'default', &block)
|
|
103
|
+
@logger = Logger.new nil
|
|
104
|
+
|
|
105
|
+
if block_given?
|
|
106
|
+
if block.arity == 1
|
|
107
|
+
yield self
|
|
108
|
+
elsif block.arity == 0
|
|
109
|
+
instance_eval &block
|
|
110
|
+
end
|
|
110
111
|
end
|
|
111
|
-
end
|
|
112
112
|
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
start(chroot_name)
|
|
114
|
+
end
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
def safe_run(cmd, &block)
|
|
117
|
+
@logger.info('Executing %s' % cmd)
|
|
118
|
+
begin
|
|
119
|
+
stream = Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
|
|
120
|
+
if block_given?
|
|
121
|
+
block.call stdin, stdout, stderr, wait_thr
|
|
122
|
+
end
|
|
123
|
+
wait_thr.value
|
|
124
|
+
end
|
|
125
|
+
rescue Errno::ENOENT
|
|
126
|
+
raise SchrootError, 'Schroot binary is missing!'
|
|
127
|
+
end
|
|
128
|
+
@logger.info('Done!')
|
|
129
|
+
return stream
|
|
122
130
|
end
|
|
123
|
-
|
|
124
|
-
|
|
131
|
+
|
|
132
|
+
def command(cmd, user, preserve_environment)
|
|
133
|
+
raise SchrootError, 'No current session' unless @session
|
|
134
|
+
command = ['schroot', '-r', '-c', @session]
|
|
135
|
+
if user
|
|
136
|
+
command << '-u'
|
|
137
|
+
command << user
|
|
138
|
+
end
|
|
139
|
+
if preserve_environment
|
|
140
|
+
command << '-p'
|
|
141
|
+
end
|
|
142
|
+
command << '--'
|
|
143
|
+
command << cmd
|
|
144
|
+
command.join(' ')
|
|
125
145
|
end
|
|
126
|
-
@logger.info("Done!")
|
|
127
|
-
return stdin, stdout, stderr
|
|
128
|
-
end
|
|
129
146
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
147
|
+
# Runs command inside of chroot session.
|
|
148
|
+
# Invocation is popen3-like
|
|
149
|
+
# Session must be started before executing command.
|
|
150
|
+
#
|
|
151
|
+
# @example
|
|
152
|
+
# session.run("uname -a",
|
|
153
|
+
# :user => 'rainbowdash',
|
|
154
|
+
# :preserve_environment => true) do |stdin, stdout, stderr, wait_thr|
|
|
155
|
+
# puts wait_thr.pid, wait_thr.value, stdout.read
|
|
156
|
+
# end
|
|
157
|
+
# @param cmd [String] command to run
|
|
158
|
+
# @param user [String] user
|
|
159
|
+
def run(cmd, user: nil, preserve_environment: nil, &block)
|
|
160
|
+
safe_run(command(cmd, user, preserve_environment)) do |stdin, stout, stderr, wait_thr|
|
|
161
|
+
if block_given?
|
|
162
|
+
block.call stdin, stout, stderr, wait_thr
|
|
163
|
+
end
|
|
164
|
+
wait_thr.value
|
|
165
|
+
end
|
|
136
166
|
end
|
|
137
|
-
|
|
138
|
-
|
|
167
|
+
|
|
168
|
+
# Clones current session
|
|
169
|
+
#
|
|
170
|
+
# @return [Object] new session object
|
|
171
|
+
def clone
|
|
172
|
+
Chroot.new(@chroot)
|
|
139
173
|
end
|
|
140
|
-
command << '--'
|
|
141
|
-
command << cmd
|
|
142
|
-
return command.join(" ")
|
|
143
|
-
end
|
|
144
174
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
175
|
+
# Starts the session of `chroot_name` chroot
|
|
176
|
+
#
|
|
177
|
+
# @param chroot_name [String] name of configured chroot
|
|
178
|
+
# @return [String] schroot session id
|
|
179
|
+
# A string representing schroot session id.
|
|
180
|
+
def start(chroot_name = 'default')
|
|
181
|
+
@logger.debug('Starting chroot session')
|
|
182
|
+
stop if @session
|
|
183
|
+
ObjectSpace.define_finalizer(self, proc { stop })
|
|
184
|
+
state = safe_run('schroot -b -c %s' % chroot_name) do |stdin, stdout, stderr, wait_thr|
|
|
185
|
+
wait_thr.value
|
|
186
|
+
@session = stdout.gets.strip
|
|
187
|
+
end
|
|
157
188
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
189
|
+
@chroot = chroot_name
|
|
190
|
+
state = safe_run('schroot --location -c session:%s' % @session) do |stdin, stdout, stderr, wait_thr|
|
|
191
|
+
wait_thr.value
|
|
192
|
+
@location = stdout.gets.strip
|
|
193
|
+
end
|
|
194
|
+
@logger.debug('Session %s with %s started in %s' % [@session, @chroot, @location])
|
|
195
|
+
@session
|
|
196
|
+
end
|
|
164
197
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
ObjectSpace.define_finalizer(self, proc { stop })
|
|
175
|
-
stdin, stdout, stderr = safe_run("schroot -b -c %s" % chroot_name)
|
|
176
|
-
@chroot = chroot_name
|
|
177
|
-
@session = stdout.gets.strip
|
|
178
|
-
stdin, stdout, stderr = safe_run("schroot --location -c session:%s" % @session)
|
|
179
|
-
@location = stdout.gets.strip
|
|
180
|
-
@logger.debug("Session %s with %s started in %s" % [@session, @chroot, @location])
|
|
181
|
-
return @session
|
|
182
|
-
end
|
|
198
|
+
# Stops current chroot session.
|
|
199
|
+
#
|
|
200
|
+
# @return [nil] session_id of killed session (should be nil)
|
|
201
|
+
def stop
|
|
202
|
+
@logger.debug('Stopping session %s with %s' % [@session, @chroot])
|
|
203
|
+
safe_run('schroot -e -c %s' % @session)
|
|
204
|
+
@logger.debug('Session %s of %s should be stopped' % [@session, @chroot])
|
|
205
|
+
@location = nil
|
|
206
|
+
@session = nil
|
|
183
207
|
|
|
184
|
-
|
|
185
|
-
#
|
|
186
|
-
# @param chroot_name [String] name of configured chroot
|
|
187
|
-
# @return [nil] session_id of killed session (should be nil)
|
|
188
|
-
def stop
|
|
189
|
-
@logger.debug("Stopping session %s with %s" % [@session, @chroot])
|
|
190
|
-
stdin, stdout, stderr = safe_run("schroot -e -c %s" % @session)
|
|
191
|
-
@logger.debug("Session %s of %s should be stopped" % [@session, @chroot])
|
|
192
|
-
@location = nil
|
|
193
|
-
@session = nil
|
|
208
|
+
end
|
|
194
209
|
|
|
195
|
-
|
|
210
|
+
# Sets log object
|
|
211
|
+
def log(log=@logger)
|
|
212
|
+
@logger = log
|
|
213
|
+
@logger.debug('Hello there!')
|
|
214
|
+
end
|
|
196
215
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
@logger = log
|
|
200
|
-
@logger.debug("Hello there!")
|
|
216
|
+
private :safe_run, :command
|
|
217
|
+
attr_reader :session, :location, :chroot, :logger
|
|
201
218
|
end
|
|
202
219
|
|
|
203
|
-
|
|
204
|
-
attr_reader :session, :location, :chroot, :logger
|
|
205
|
-
end
|
|
220
|
+
end
|
data/schroot.gemspec
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'schroot/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "schroot"
|
|
8
|
+
spec.version = Schroot::VERSION
|
|
9
|
+
spec.authors = ["Daniil Guzanov"]
|
|
10
|
+
spec.email = ["melkor217@gmail.com"]
|
|
11
|
+
spec.summary = %q{Schroot bindings.}
|
|
12
|
+
spec.description = %q{Ruby bindings for schroot.}
|
|
13
|
+
spec.homepage = "https://github.com/melkor217/ruby-schroot"
|
|
14
|
+
spec.license = "WTFPL"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.files.delete ".gitignore"
|
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
|
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
|
23
|
+
spec.add_development_dependency "rake"
|
|
24
|
+
spec.add_development_dependency "rspec"
|
|
25
|
+
end
|
data/test/test_schroot.rb
CHANGED
|
@@ -3,15 +3,15 @@ require 'schroot'
|
|
|
3
3
|
|
|
4
4
|
class SchrootTest < Test::Unit::TestCase
|
|
5
5
|
def test_start
|
|
6
|
-
test = Schroot.new('default')
|
|
7
|
-
print_debug(test
|
|
6
|
+
test = Schroot::Chroot.new('default')
|
|
7
|
+
print_debug(test, :test)
|
|
8
8
|
|
|
9
9
|
assert_not_nil test.session
|
|
10
10
|
assert_not_nil test.chroot
|
|
11
11
|
assert_not_nil test.location
|
|
12
12
|
|
|
13
13
|
test_clone = test.clone
|
|
14
|
-
print_debug(test_clone
|
|
14
|
+
print_debug(test_clone, :test_clone)
|
|
15
15
|
|
|
16
16
|
assert_not_nil test_clone.session
|
|
17
17
|
assert_not_nil test_clone.chroot
|
|
@@ -23,16 +23,23 @@ class SchrootTest < Test::Unit::TestCase
|
|
|
23
23
|
assert_not_nil test_clone.location
|
|
24
24
|
|
|
25
25
|
test.stop
|
|
26
|
-
print_debug(test
|
|
26
|
+
print_debug(test, :stopped)
|
|
27
|
+
|
|
28
|
+
test = Schroot::Chroot.new('default')
|
|
29
|
+
test.run("echo -n 123") do |stdin, stdout, stderr, wait_thrd|
|
|
30
|
+
assert_equal wait_thrd.value, 0
|
|
31
|
+
assert_not_nil wait_thrd.pid
|
|
32
|
+
assert_equal stdout.gets, "123"
|
|
33
|
+
end
|
|
34
|
+
test.run("echo 123") do |stdin, stdout|
|
|
35
|
+
assert_equal stdout.gets, "123\n"
|
|
36
|
+
end
|
|
27
37
|
|
|
28
|
-
test = Schroot.new
|
|
29
|
-
assert_equal test.run("echo -n 123")[1].gets, "123"
|
|
30
|
-
assert_equal test.run("echo 123")[1].gets, "123\n"
|
|
31
38
|
end
|
|
32
39
|
|
|
33
|
-
def print_debug(schroot,name = 'chroot')
|
|
40
|
+
def print_debug(schroot, name = 'chroot')
|
|
34
41
|
print "\n#{name}_session = %s\n" % schroot.session
|
|
35
42
|
print "#{name}_chroot = %s\n" % schroot.chroot
|
|
36
43
|
print "#{name}_location = %s\n" % schroot.location
|
|
37
44
|
end
|
|
38
|
-
end
|
|
45
|
+
end
|
metadata
CHANGED
|
@@ -1,24 +1,71 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: schroot
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.8
|
|
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-
|
|
12
|
-
dependencies:
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
date: 2014-05-20 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.6'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.6'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
description: Ruby bindings for schroot.
|
|
56
|
+
email:
|
|
57
|
+
- melkor217@gmail.com
|
|
15
58
|
executables: []
|
|
16
59
|
extensions: []
|
|
17
60
|
extra_rdoc_files: []
|
|
18
61
|
files:
|
|
62
|
+
- Gemfile
|
|
63
|
+
- LICENSE.txt
|
|
19
64
|
- README.md
|
|
20
65
|
- Rakefile
|
|
21
66
|
- lib/schroot.rb
|
|
67
|
+
- lib/schroot/version.rb
|
|
68
|
+
- schroot.gemspec
|
|
22
69
|
- test/test_schroot.rb
|
|
23
70
|
homepage: https://github.com/melkor217/ruby-schroot
|
|
24
71
|
licenses:
|
|
@@ -43,6 +90,7 @@ rubyforge_project:
|
|
|
43
90
|
rubygems_version: 2.2.2
|
|
44
91
|
signing_key:
|
|
45
92
|
specification_version: 4
|
|
46
|
-
summary: Schroot bindings
|
|
93
|
+
summary: Schroot bindings.
|
|
47
94
|
test_files:
|
|
48
95
|
- test/test_schroot.rb
|
|
96
|
+
has_rdoc:
|