virtualbox 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/virtualbox.rb +1 -0
- data/lib/virtualbox/command.rb +7 -0
- data/lib/virtualbox/ext/platform.rb +21 -0
- data/lib/virtualbox/global.rb +19 -12
- data/test/virtualbox/command_test.rb +24 -0
- data/test/virtualbox/ext/platform_test.rb +42 -0
- data/test/virtualbox/global_test.rb +42 -1
- data/virtualbox.gemspec +5 -2
- metadata +6 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.3
|
data/lib/virtualbox.rb
CHANGED
data/lib/virtualbox/command.rb
CHANGED
@@ -93,6 +93,13 @@ module VirtualBox
|
|
93
93
|
# the ruby mailing list. I'm not sure how well it works but so far
|
94
94
|
# it hasn't failed!
|
95
95
|
def shell_escape(str)
|
96
|
+
if Platform.windows?
|
97
|
+
# Special case for windows. This is probably not 100% bullet proof
|
98
|
+
# but it gets the job done until we find trouble
|
99
|
+
str = "\"#{str}\"" if str =~ /\s/
|
100
|
+
return str
|
101
|
+
end
|
102
|
+
|
96
103
|
str.to_s.gsub(/(?=[^a-zA-Z0-9_.\/\-\x7F-\xFF\n])/n, '\\').
|
97
104
|
gsub(/\n/, "'\n'").
|
98
105
|
sub(/^$/, "''")
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VirtualBox
|
2
|
+
class Platform
|
3
|
+
class <<self
|
4
|
+
def mac?
|
5
|
+
platform.include?("darwin")
|
6
|
+
end
|
7
|
+
|
8
|
+
def windows?
|
9
|
+
platform.include?("mswin") || platform.include?("mingw")
|
10
|
+
end
|
11
|
+
|
12
|
+
def linux?
|
13
|
+
platform.include?("linux")
|
14
|
+
end
|
15
|
+
|
16
|
+
def platform
|
17
|
+
RUBY_PLATFORM.downcase
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/virtualbox/global.rb
CHANGED
@@ -54,15 +54,7 @@ module VirtualBox
|
|
54
54
|
# The path to the global VirtualBox XML configuration file. This is
|
55
55
|
# entirely system dependent and can be set with {vboxconfig=}. The default
|
56
56
|
# is guessed based on the platform.
|
57
|
-
|
58
|
-
# TODO: Windows
|
59
|
-
@@vboxconfig = if RUBY_PLATFORM.downcase.include?("darwin")
|
60
|
-
"~/Library/VirtualBox/VirtualBox.xml"
|
61
|
-
elsif RUBY_PLATFORM.downcase.include?("linux")
|
62
|
-
"~/.VirtualBox/VirtualBox.xml"
|
63
|
-
else
|
64
|
-
"Unknown"
|
65
|
-
end
|
57
|
+
@@vboxconfig = nil
|
66
58
|
|
67
59
|
relationship :vms, VM, :lazy => true
|
68
60
|
relationship :media, Media
|
@@ -96,21 +88,36 @@ module VirtualBox
|
|
96
88
|
@@vboxconfig = value
|
97
89
|
end
|
98
90
|
|
91
|
+
# Returns the path to the virtual box configuration file. If the path
|
92
|
+
# has not yet been set, it attempts to infer it based on the
|
93
|
+
# platform ruby is running on.
|
94
|
+
def vboxconfig
|
95
|
+
return @@vboxconfig unless @@vboxconfig.nil?
|
96
|
+
|
97
|
+
if Platform.mac?
|
98
|
+
"~/Library/VirtualBox/VirtualBox.xml"
|
99
|
+
elsif Platform.linux? || Platform.windows?
|
100
|
+
"~/.VirtualBox/VirtualBox.xml"
|
101
|
+
else
|
102
|
+
"Unknown"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
99
106
|
# Returns the XML document of the configuration. This will raise an
|
100
107
|
# {Exceptions::ConfigurationException} if the vboxconfig file doesn't
|
101
108
|
# exist.
|
102
109
|
#
|
103
110
|
# @return [Nokogiri::XML::Document]
|
104
111
|
def config
|
105
|
-
raise Exceptions::ConfigurationException.new("The path to the global VirtualBox config must be set. See Global.vboxconfig=") unless File.exist?(File.expand_path(
|
106
|
-
Command.parse_xml(File.expand_path(
|
112
|
+
raise Exceptions::ConfigurationException.new("The path to the global VirtualBox config must be set. See Global.vboxconfig=") unless File.exist?(File.expand_path(vboxconfig))
|
113
|
+
Command.parse_xml(File.expand_path(vboxconfig))
|
107
114
|
end
|
108
115
|
|
109
116
|
# Expands path relative to the configuration file.
|
110
117
|
#
|
111
118
|
# @return [String]
|
112
119
|
def expand_path(path)
|
113
|
-
File.expand_path(path, File.dirname(
|
120
|
+
File.expand_path(path, File.dirname(vboxconfig))
|
114
121
|
end
|
115
122
|
end
|
116
123
|
|
@@ -54,6 +54,30 @@ class CommandTest < Test::Unit::TestCase
|
|
54
54
|
assert_equal "400", VirtualBox::Command.shell_escape(400)
|
55
55
|
end
|
56
56
|
end
|
57
|
+
|
58
|
+
context "unix" do
|
59
|
+
setup do
|
60
|
+
VirtualBox::Platform.stubs(:windows?).returns(false)
|
61
|
+
end
|
62
|
+
|
63
|
+
should "convert properly" do
|
64
|
+
assert_equal "foo\\ bar", VirtualBox::Command.shell_escape("foo bar")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "windows" do
|
69
|
+
setup do
|
70
|
+
VirtualBox::Platform.stubs(:windows?).returns(true)
|
71
|
+
end
|
72
|
+
|
73
|
+
should "wrap strings with spaces in quotes" do
|
74
|
+
assert_equal '"foo bar"', VirtualBox::Command.shell_escape("foo bar")
|
75
|
+
end
|
76
|
+
|
77
|
+
should "just return the string if it has no spaces" do
|
78
|
+
assert_equal "foo:bar", VirtualBox::Command.shell_escape('foo:bar')
|
79
|
+
end
|
80
|
+
end
|
57
81
|
end
|
58
82
|
|
59
83
|
context "executing commands" do
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
2
|
+
require 'virtualbox/ext/platform'
|
3
|
+
|
4
|
+
class PlatformTest < Test::Unit::TestCase
|
5
|
+
context "mac" do
|
6
|
+
should "return true if it contains darwin" do
|
7
|
+
success = ["i386-darwin", "i686-darwin10", "imadarwin"]
|
8
|
+
success.each do |item|
|
9
|
+
VirtualBox::Platform.stubs(:platform).returns(item)
|
10
|
+
assert VirtualBox::Platform.mac?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "windows" do
|
16
|
+
should "return true if it contains mswin" do
|
17
|
+
success = ["i386-mswin32", "i686-mswin64", "imswin"]
|
18
|
+
success.each do |item|
|
19
|
+
VirtualBox::Platform.stubs(:platform).returns(item)
|
20
|
+
assert VirtualBox::Platform.windows?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
should "return true if it contains mingw" do
|
25
|
+
success = ["i386-mingw32", "i686-mingw64", "mingw"]
|
26
|
+
success.each do |item|
|
27
|
+
VirtualBox::Platform.stubs(:platform).returns(item)
|
28
|
+
assert VirtualBox::Platform.windows?
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "linux" do
|
34
|
+
should "return true if it contains linux" do
|
35
|
+
success = ["i386-linux", "i686-linux241", "linux"]
|
36
|
+
success.each do |item|
|
37
|
+
VirtualBox::Platform.stubs(:platform).returns(item)
|
38
|
+
assert VirtualBox::Platform.linux?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,6 +1,46 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
2
|
|
3
3
|
class GlobalTest < Test::Unit::TestCase
|
4
|
+
context "the virtualbox config file path" do
|
5
|
+
setup do
|
6
|
+
VirtualBox::Global.vboxconfig = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
teardown do
|
10
|
+
VirtualBox::Global.vboxconfig = "foo"
|
11
|
+
end
|
12
|
+
|
13
|
+
should "return the path if its set" do
|
14
|
+
VirtualBox::Global.vboxconfig = "foo"
|
15
|
+
assert_equal "foo", VirtualBox::Global.vboxconfig
|
16
|
+
end
|
17
|
+
|
18
|
+
should "return Mac-path if on mac" do
|
19
|
+
VirtualBox::Platform.stubs(:mac?).returns(true)
|
20
|
+
assert_equal "~/Library/VirtualBox/VirtualBox.xml", VirtualBox::Global.vboxconfig
|
21
|
+
end
|
22
|
+
|
23
|
+
should "return Windows-path if on windows" do
|
24
|
+
VirtualBox::Platform.stubs(:mac?).returns(false)
|
25
|
+
VirtualBox::Platform.stubs(:windows?).returns(true)
|
26
|
+
assert_equal "~/.VirtualBox/VirtualBox.xml", VirtualBox::Global.vboxconfig
|
27
|
+
end
|
28
|
+
|
29
|
+
should "return Linux-path if on linux" do
|
30
|
+
VirtualBox::Platform.stubs(:mac?).returns(false)
|
31
|
+
VirtualBox::Platform.stubs(:windows?).returns(false)
|
32
|
+
VirtualBox::Platform.stubs(:linux?).returns(true)
|
33
|
+
assert_equal "~/.VirtualBox/VirtualBox.xml", VirtualBox::Global.vboxconfig
|
34
|
+
end
|
35
|
+
|
36
|
+
should "return 'unknown' otherwise" do
|
37
|
+
VirtualBox::Platform.stubs(:mac?).returns(false)
|
38
|
+
VirtualBox::Platform.stubs(:windows?).returns(false)
|
39
|
+
VirtualBox::Platform.stubs(:linux?).returns(false)
|
40
|
+
assert_equal "Unknown", VirtualBox::Global.vboxconfig
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
4
44
|
context "getting the global config" do
|
5
45
|
should "only get it once, then cache" do
|
6
46
|
VirtualBox::Global.expects(:config).returns(mock_xml_doc).once
|
@@ -26,6 +66,7 @@ class GlobalTest < Test::Unit::TestCase
|
|
26
66
|
|
27
67
|
context "parsing configuration XML" do
|
28
68
|
setup do
|
69
|
+
VirtualBox::Command.stubs(:vboxconfig).returns("foo")
|
29
70
|
File.stubs(:exist?).returns(true)
|
30
71
|
VirtualBox::Command.stubs(:parse_xml)
|
31
72
|
end
|
@@ -63,7 +104,7 @@ class GlobalTest < Test::Unit::TestCase
|
|
63
104
|
|
64
105
|
context "expanding path" do
|
65
106
|
setup do
|
66
|
-
VirtualBox::Global.vboxconfig
|
107
|
+
VirtualBox::Global.stubs(:vboxconfig).returns("/foo/bar/baz.rb")
|
67
108
|
end
|
68
109
|
|
69
110
|
should "expand the path properly" do
|
data/virtualbox.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{virtualbox}
|
8
|
-
s.version = "0.5.
|
8
|
+
s.version = "0.5.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Mitchell Hashimoto"]
|
12
|
-
s.date = %q{2010-03-
|
12
|
+
s.date = %q{2010-03-16}
|
13
13
|
s.description = %q{Create and modify virtual machines in VirtualBox using pure ruby.}
|
14
14
|
s.email = %q{mitchell.hashimoto@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
|
|
37
37
|
"lib/virtualbox/command.rb",
|
38
38
|
"lib/virtualbox/dvd.rb",
|
39
39
|
"lib/virtualbox/exceptions.rb",
|
40
|
+
"lib/virtualbox/ext/platform.rb",
|
40
41
|
"lib/virtualbox/ext/subclass_listing.rb",
|
41
42
|
"lib/virtualbox/extra_data.rb",
|
42
43
|
"lib/virtualbox/forwarded_port.rb",
|
@@ -60,6 +61,7 @@ Gem::Specification.new do |s|
|
|
60
61
|
"test/virtualbox/attached_device_test.rb",
|
61
62
|
"test/virtualbox/command_test.rb",
|
62
63
|
"test/virtualbox/dvd_test.rb",
|
64
|
+
"test/virtualbox/ext/platform_test.rb",
|
63
65
|
"test/virtualbox/ext/subclass_listing_test.rb",
|
64
66
|
"test/virtualbox/extra_data_test.rb",
|
65
67
|
"test/virtualbox/forwarded_port_test.rb",
|
@@ -91,6 +93,7 @@ Gem::Specification.new do |s|
|
|
91
93
|
"test/virtualbox/attached_device_test.rb",
|
92
94
|
"test/virtualbox/command_test.rb",
|
93
95
|
"test/virtualbox/dvd_test.rb",
|
96
|
+
"test/virtualbox/ext/platform_test.rb",
|
94
97
|
"test/virtualbox/ext/subclass_listing_test.rb",
|
95
98
|
"test/virtualbox/extra_data_test.rb",
|
96
99
|
"test/virtualbox/forwarded_port_test.rb",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
8
|
+
- 3
|
9
|
+
version: 0.5.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mitchell Hashimoto
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-16 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- lib/virtualbox/command.rb
|
62
62
|
- lib/virtualbox/dvd.rb
|
63
63
|
- lib/virtualbox/exceptions.rb
|
64
|
+
- lib/virtualbox/ext/platform.rb
|
64
65
|
- lib/virtualbox/ext/subclass_listing.rb
|
65
66
|
- lib/virtualbox/extra_data.rb
|
66
67
|
- lib/virtualbox/forwarded_port.rb
|
@@ -84,6 +85,7 @@ files:
|
|
84
85
|
- test/virtualbox/attached_device_test.rb
|
85
86
|
- test/virtualbox/command_test.rb
|
86
87
|
- test/virtualbox/dvd_test.rb
|
88
|
+
- test/virtualbox/ext/platform_test.rb
|
87
89
|
- test/virtualbox/ext/subclass_listing_test.rb
|
88
90
|
- test/virtualbox/extra_data_test.rb
|
89
91
|
- test/virtualbox/forwarded_port_test.rb
|
@@ -139,6 +141,7 @@ test_files:
|
|
139
141
|
- test/virtualbox/attached_device_test.rb
|
140
142
|
- test/virtualbox/command_test.rb
|
141
143
|
- test/virtualbox/dvd_test.rb
|
144
|
+
- test/virtualbox/ext/platform_test.rb
|
142
145
|
- test/virtualbox/ext/subclass_listing_test.rb
|
143
146
|
- test/virtualbox/extra_data_test.rb
|
144
147
|
- test/virtualbox/forwarded_port_test.rb
|