sambala 0.8.2 → 0.8.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.
- data/lib/sambala.rb +10 -2
- data/lib/sambala_gardener.rb +20 -5
- metadata +2 -2
data/lib/sambala.rb
CHANGED
@@ -49,8 +49,16 @@ class Sambala
|
|
49
49
|
# :password => 'eggman',
|
50
50
|
# :threads => 2 )
|
51
51
|
def initialize(options={:domain => '', :host => '', :user => '', :password => '', :threads => 1})
|
52
|
-
|
53
|
-
|
52
|
+
begin
|
53
|
+
options[:threads] = 4 if options[:threads] > 4
|
54
|
+
options[:init_timeout] = options[:threads] * 2
|
55
|
+
@options = options; gardener_ok
|
56
|
+
rescue SmbInitError
|
57
|
+
raise SmbInitError.exception("Failed smbclient initialisation")
|
58
|
+
rescue
|
59
|
+
@gardener.close unless @gardener.nil? || @gardener.class != 'Gardener'
|
60
|
+
raise RuntimeError.exception("Unknown Process Failed!!")
|
61
|
+
end
|
54
62
|
end
|
55
63
|
# The +cd+ instance method takes only one argument, the path to which you wish to change directory
|
56
64
|
# Its one of the only implemented command where queue mode is not available, for the simple reason that
|
data/lib/sambala_gardener.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
class Sambala
|
2
|
+
class SmbInitError < StandardError; end
|
2
3
|
# The Sambala::Gardener module bings Abundance into Sambala.
|
3
4
|
# A bunch of mixins used inside Sambala to access Abundance Non-Blocking Threading.
|
4
5
|
# These methods are a higher level abstraction of Abundance methods,
|
@@ -56,13 +57,27 @@ class Sambala
|
|
56
57
|
def exec_queue(command,data)
|
57
58
|
@gardener.seed("#{command} #{data}").integer? ? [true,true] : [false,false]
|
58
59
|
end
|
60
|
+
|
61
|
+
# The +gardener_ok+ method does the +init_gardener+ invocation, degrading the options parameters until
|
62
|
+
# it initializes, or raise SmbInitError exception after 4 try.
|
63
|
+
def gardener_ok
|
64
|
+
init = []
|
65
|
+
catch :gardener do
|
66
|
+
4.times do |num|
|
67
|
+
init_gardener; init = @init_status = @gardener.init_status
|
68
|
+
init.map! { |result| result[:success] }
|
69
|
+
throw :gardener if init.uniq.size == 1 and init[0] == true
|
70
|
+
@gardener.close; @gardener = nil
|
71
|
+
@options[:threads] -= 1 unless @options[:threads] == 1; @options[:init_timeout] += 1
|
72
|
+
end
|
73
|
+
raise SmbInitError.exception("Couldn't set smbclient properly")
|
74
|
+
end
|
75
|
+
end
|
59
76
|
|
60
77
|
# The +init_gardener+ method initialize a gardener class object
|
61
78
|
def init_gardener
|
62
|
-
|
63
|
-
|
64
|
-
@gardener = Abundance.gardener(:seed_size => 8192, :rows => @options[:threads], :init_timeout => @options[:threads] + 1) do
|
65
|
-
PTY.spawn("smbclient //#{@options[:host]}/#{@options[:share]} #{@options[:password]} -U #{@options[:user]}") do |r,w,pid|
|
79
|
+
@gardener = Abundance.gardener(:seed_size => 8192, :rows => @options[:threads], :init_timeout => @options[:init_timeout]) do
|
80
|
+
PTY.spawn("smbclient //#{@options[:host]}/#{@options[:share]} #{@options[:password]} -W #{@options[:domain]} -U #{@options[:user]}") do |r,w,pid|
|
66
81
|
w.sync = true
|
67
82
|
$expect_verbose = false
|
68
83
|
|
@@ -70,7 +85,7 @@ class Sambala
|
|
70
85
|
loop do
|
71
86
|
r.expect(/.*\xD\xAsmb:[ \x5C]*\x3E.*/) do |text|
|
72
87
|
if text != nil
|
73
|
-
Abundance.init_status(true,"#{text.inspect}")
|
88
|
+
text[0] =~ /.*Server=.*/i ? Abundance.init_status(true,"#{text.inspect}") : Abundance.init_status(false,"#{text.inspect}")
|
74
89
|
throw :init
|
75
90
|
end
|
76
91
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sambala
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Louis-Philippe Perron
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-12-
|
12
|
+
date: 2008-12-16 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|