schroot 0.0.2 → 0.0.3
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/README.md +49 -0
- data/Rakefile +15 -0
- data/lib/schroot.rb +23 -2
- data/test/test_schroot.rb +37 -0
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1cbd1e243c8faebe108938506ba91250bcda4a47
|
|
4
|
+
data.tar.gz: 95a0de9e53b9e1fbc5fe1fd8a5aa390044f02721
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 19ec77eef2486c3c77704cd1edc62df255dabcceb2169946a98524ab23a72d650dd1c181facf3caf82ca9762aa9b22e9e15d77c33fff8651c5e2df9b7dfa405f
|
|
7
|
+
data.tar.gz: e983818aa490af8ff537aa15949fc3fb127fbeb4fb2df328f0ac32e4db2970d8eec2ea1a163141456a854d69a17a52d0b81081c32e162c7e046a522687b9db96
|
data/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
ruby-schroot
|
|
2
|
+
============
|
|
3
|
+
|
|
4
|
+
Ruby bindings for debian schroot
|
|
5
|
+
|
|
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
|
+
Currently it just calls schroot binaries.
|
|
10
|
+
Ability to manage chroots (eg create) is coming soon.
|
|
11
|
+
|
|
12
|
+
Usage
|
|
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/`.
|
|
15
|
+
|
|
16
|
+
Little example:
|
|
17
|
+
|
|
18
|
+
[sid]
|
|
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
|
|
27
|
+
|
|
28
|
+
Library installation is pretty simple:
|
|
29
|
+
|
|
30
|
+
$ rake
|
|
31
|
+
$ gem install ./*.gem
|
|
32
|
+
|
|
33
|
+
or just
|
|
34
|
+
|
|
35
|
+
$ rake install
|
|
36
|
+
|
|
37
|
+
Examples
|
|
38
|
+
------
|
|
39
|
+
|
|
40
|
+
```ruby
|
|
41
|
+
irb(main):005:0> require 'schroot'
|
|
42
|
+
=> true
|
|
43
|
+
irb(main):006:0> my_session = Schroot.new('sid')
|
|
44
|
+
=> #<Schroot:0x8ba789c @chroot="sid", @session="sid-19131ba0-84ba-42e5-a2fb-d2d375d61750", @location="/var/lib/schroot/mount/sid-19131ba0-84ba-42e5-a2fb-d2d375d61750">
|
|
45
|
+
irb(main):007:0> stdin, stdout, stderr = my_session.run("echo Hello, World!")
|
|
46
|
+
=> [#<IO:fd 22>, #<IO:fd 24>, #<IO:fd 26>]
|
|
47
|
+
irb(main):008:0> stdout.gets
|
|
48
|
+
=> "Hello, World!\n"
|
|
49
|
+
```
|
data/Rakefile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'rake/testtask'
|
|
2
|
+
|
|
3
|
+
Rake::TestTask.new do |t|
|
|
4
|
+
t.libs << 'test'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
task :build => :test do
|
|
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
|
data/lib/schroot.rb
CHANGED
|
@@ -5,6 +5,7 @@ SCHROOT_BASE="/var/lib/schroot"
|
|
|
5
5
|
class SchrootError < StandardError
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
+
# Schroot session handler
|
|
8
9
|
class Schroot
|
|
9
10
|
def initialize(chroot_name = 'default')
|
|
10
11
|
start(chroot_name)
|
|
@@ -33,15 +34,31 @@ class Schroot
|
|
|
33
34
|
return command.join(" ")
|
|
34
35
|
end
|
|
35
36
|
|
|
37
|
+
# Runs command inside of chroot session.
|
|
38
|
+
# Session must be started before.
|
|
39
|
+
#
|
|
40
|
+
# @example
|
|
41
|
+
# session.run("ping localhost",{:user => 'rainbowdash',:preserve_environment => true})
|
|
42
|
+
# => [#<IO:fd 16>, #<IO:fd 18>, #<IO:fd 20>]
|
|
43
|
+
# @param cmd [String] command to run
|
|
44
|
+
# @param kwargs [Hash] extra args
|
|
45
|
+
# @return [Array<(IO:fd, IO:fd, IO:fd)>] descriptors for stdin, stdout, stderr
|
|
36
46
|
def run(cmd, kwargs = {})
|
|
37
47
|
return safe_run(command(cmd,kwargs))
|
|
38
|
-
# TBD
|
|
39
48
|
end
|
|
40
49
|
|
|
50
|
+
# Clones current session
|
|
51
|
+
#
|
|
52
|
+
# @return [Object] new session object
|
|
41
53
|
def clone
|
|
42
54
|
return Schroot.new(@chroot)
|
|
43
55
|
end
|
|
44
56
|
|
|
57
|
+
# Starts the session of `chroot_name` chroot
|
|
58
|
+
#
|
|
59
|
+
# @param chroot_name [String] name of configured chroot
|
|
60
|
+
# @return [String] schroot session id
|
|
61
|
+
# A string representing schroot session id.
|
|
45
62
|
def start(chroot_name = 'default')
|
|
46
63
|
stop if @session
|
|
47
64
|
command = ['schroot', '-b', '-c', chroot_name]
|
|
@@ -54,10 +71,14 @@ class Schroot
|
|
|
54
71
|
return @session
|
|
55
72
|
end
|
|
56
73
|
|
|
74
|
+
# Stops current chroot session.
|
|
75
|
+
#
|
|
76
|
+
# @param chroot_name [String] name of configured chroot
|
|
77
|
+
# @return [nil] session_id of killed session (should be nil)
|
|
57
78
|
def stop
|
|
58
79
|
stdin, stdout, stderr = safe_run("schroot -e -c %s" % @session)
|
|
59
|
-
@session = nil
|
|
60
80
|
@location = nil
|
|
81
|
+
@session = nil
|
|
61
82
|
end
|
|
62
83
|
|
|
63
84
|
private :safe_run, :command
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'schroot'
|
|
3
|
+
|
|
4
|
+
class SchrootTest < Test::Unit::TestCase
|
|
5
|
+
def test_start
|
|
6
|
+
test = Schroot.new('default')
|
|
7
|
+
print_debug(test,:test)
|
|
8
|
+
|
|
9
|
+
assert_not_nil test.session
|
|
10
|
+
assert_not_nil test.chroot
|
|
11
|
+
assert_not_nil test.location
|
|
12
|
+
|
|
13
|
+
test_clone = test.clone
|
|
14
|
+
print_debug(test_clone,:test_clone)
|
|
15
|
+
|
|
16
|
+
assert_not_nil test_clone.session
|
|
17
|
+
assert_not_nil test_clone.chroot
|
|
18
|
+
assert_not_nil test_clone.location
|
|
19
|
+
|
|
20
|
+
assert_not_equal test.session, test_clone.session
|
|
21
|
+
assert_not_equal test.session, test_clone.location
|
|
22
|
+
assert_equal test.chroot, test_clone.chroot
|
|
23
|
+
|
|
24
|
+
test.stop
|
|
25
|
+
print_debug(test,:stopped)
|
|
26
|
+
|
|
27
|
+
test = Schroot.new
|
|
28
|
+
assert_equal test.run("echo -n 123")[1].gets, "123"
|
|
29
|
+
assert_equal test.run("echo 123")[1].gets, "123\n"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def print_debug(schroot,name = 'chroot')
|
|
33
|
+
print "\n#{name}_session = %s\n" % schroot.session
|
|
34
|
+
print "#{name}_chroot = %s\n" % schroot.chroot
|
|
35
|
+
print "#{name}_location = %s\n" % schroot.location
|
|
36
|
+
end
|
|
37
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniil Guzanov
|
|
@@ -17,6 +17,9 @@ extensions: []
|
|
|
17
17
|
extra_rdoc_files: []
|
|
18
18
|
files:
|
|
19
19
|
- lib/schroot.rb
|
|
20
|
+
- test/test_schroot.rb
|
|
21
|
+
- README.md
|
|
22
|
+
- Rakefile
|
|
20
23
|
homepage: http://rubygems.org/gems/schroot
|
|
21
24
|
licenses:
|
|
22
25
|
- WTFPL
|
|
@@ -41,4 +44,5 @@ rubygems_version: 2.0.14
|
|
|
41
44
|
signing_key:
|
|
42
45
|
specification_version: 4
|
|
43
46
|
summary: Schroot bindings
|
|
44
|
-
test_files:
|
|
47
|
+
test_files:
|
|
48
|
+
- test/test_schroot.rb
|