sambala 0.9.0 → 0.9.1

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.
@@ -20,6 +20,25 @@
20
20
  # with the +queue_results+ method, returning an array containing your commands and their respective results.
21
21
  #
22
22
  # When in doubt about what each command does, please refer to smbclient man page for help.
23
+ # ///////////////////////////////////////////////////////////////////////////////////////
24
+ #
25
+ # Example:
26
+ #
27
+ # samba = Sambala.new( :domain => 'NTDOMAIN',
28
+ # :host => 'sambaserver',
29
+ # :share => 'sambashare',
30
+ # :user => 'walrus',
31
+ # :password => 'eggman',
32
+ # :threads => 2 )
33
+ #
34
+ # samba.cd('myfolder') # => true
35
+ # samba.put(:from => 'aLocalFile.txt') # => [false, "aLocalFile.txt does not exist\r\n"]
36
+ #
37
+ #
38
+ # For detailed documentation refer to the online ruby-doc:
39
+ # http://sambala.rubyforge.org/ruby-doc/
40
+ #
41
+ # ///////////////////////////////////////////////////////////////////////////////////////
23
42
  #
24
43
  # Author:: lp (mailto:lp@spiralix.org)
25
44
  # Copyright:: 2008 Louis-Philippe Perron - Released under the terms of the MIT license
@@ -56,7 +75,7 @@ class Sambala
56
75
  @options = options; gardener_ok
57
76
  rescue
58
77
  @gardener.close unless @gardener.nil? || @gardener.class != 'Gardener'
59
- raise RuntimeError.exception("Unknown Process Failed!!")
78
+ raise RuntimeError.exception("Unknown Process Failed!! (#{$!.to_s})")
60
79
  end
61
80
  end
62
81
 
@@ -68,7 +87,7 @@ class Sambala
68
87
  # === Example
69
88
  # samba.cd('aFolder/anOtherFolder/') # => true
70
89
  def cd(to='.')
71
- execute_all('cd',to)
90
+ execute_all('cd',clean_path(to))
72
91
  end
73
92
 
74
93
  # The +du+ instance method does exactly what _du_ usually does: estimates file space usage.
@@ -117,7 +136,7 @@ class Sambala
117
136
  # samba.get(:from => 'aFile.txt') # => [true, "getting file \\aFile.txt.rb of size 3877 as test.rb (99.6 kb/s) (average 89.9 kb/s)\r\n"]
118
137
  def get(opts={:from => nil, :to => nil, :queue => false})
119
138
  opts[:to].nil? ? strng = opts[:from] : strng = opts[:from] + ' ' + opts[:to]
120
- execute('get', strng, opts[:queue])
139
+ execute('get', clean_path(strng), opts[:queue])
121
140
  end
122
141
 
123
142
  # The +lcd+ instance method changes the current working directory on the local machine to the directory specified.
@@ -128,7 +147,7 @@ class Sambala
128
147
  # === Example
129
148
  # samba.lcd('aLocalFolder/anOtherFolder/') # => true
130
149
  def lcd(to='.')
131
- execute_all('lcd', to)
150
+ execute_all('lcd', clean_path(to))
132
151
  end
133
152
 
134
153
  # The +lowercase+ method toggles lowercasing of filenames for the get command.
@@ -188,7 +207,7 @@ class Sambala
188
207
  # === Example
189
208
  # samba.mkdir('aFolder/aNewFolder') # => true
190
209
  def mkdir(path, queue=false)
191
- execute('mkdir' ,path, queue)[0]
210
+ execute('mkdir' , clean_path(path), queue)[0]
192
211
  end
193
212
  alias md mkdir
194
213
 
@@ -218,7 +237,7 @@ class Sambala
218
237
 
219
238
  def put(opts={:from => nil, :to => nil, :queue => false})
220
239
  opts[:to].nil? ? strng = opts[:from] : strng = opts[:from] + ' ' + opts[:to]
221
- execute('put' ,strng, opts[:queue])
240
+ execute('put' , clean_path(strng), opts[:queue])
222
241
  end
223
242
 
224
243
  # The +recurse+ method toggles directory recursion
@@ -240,7 +259,7 @@ class Sambala
240
259
  # === Example
241
260
  # samba.rmdir('mydir') # => true
242
261
  def rmdir(path,queue=false)
243
- execute('rmdir' , path, queue)[0]
262
+ execute('rmdir' , clean_path(path), queue)[0]
244
263
  end
245
264
 
246
265
  # The +volume+ method returns remote volume information.
@@ -13,6 +13,19 @@ class Sambala
13
13
  module Gardener
14
14
  require 'timeout'
15
15
 
16
+ # The +clean_path+ method cleans the slashes, as backslashes, for the Windows servers.
17
+ # === Parameters
18
+ # * _path_ = the path to be cleaned
19
+ # === Example
20
+ # cleaned = clean_path('/My/Path/') # => '\My\Path'
21
+ def clean_path(path)
22
+ if @posix_support
23
+ return path
24
+ else
25
+ return path.gsub(/\//,'\\')
26
+ end
27
+ end
28
+
16
29
  # The +execute+ method splits the execution according to the operation mode: queue or interactive.
17
30
  # === Parameters
18
31
  # * _command_ = the command as a string
@@ -68,15 +81,16 @@ class Sambala
68
81
  init_gardener; sleep 1
69
82
  begin
70
83
  Timeout.timeout(2) { @init_status = @gardener.init_status }
71
- init = @init_status
84
+ init = Array.new(@init_status)
72
85
  init.map! { |result| result[:success] }
73
86
  throw :gardener if init.uniq.size == 1 and init[0] == true
74
87
  rescue Timeout::Error
75
88
  end
76
89
  kill_gardener_and_incr
77
90
  end
78
- raise SmbInitError.exception("Couldn't set smbclient properly")
91
+ raise SmbInitError.exception("Couldn't set smbclient properly (#{$!.to_s})")
79
92
  end
93
+ @posix_support = posix?(@init_status[0][:message])
80
94
  end
81
95
 
82
96
  # The +init_gardener+ method initialize a gardener class object
@@ -138,6 +152,14 @@ class Sambala
138
152
  @options[:threads] -= 1 unless @options[:threads] == 1; @options[:init_timeout] += 1
139
153
  end
140
154
 
155
+ def posix?(init_message)
156
+ if init_message =~ /windows/i
157
+ return false
158
+ else
159
+ return true
160
+ end
161
+ end
162
+
141
163
  end
142
164
 
143
165
  end
@@ -4,7 +4,7 @@ require 'sambala'
4
4
 
5
5
  TESTFILE = 'sambala_test'
6
6
  TESTDIR = 'sambala_temp'
7
- WELCOME = "
7
+ WELCOME = <<TITLE
8
8
  .|'''.| '|| '||
9
9
  ||.. ' .... .. .. .. || ... .... || ....
10
10
  ''|||. '' .|| || || || ||' || '' .|| || '' .||
@@ -12,7 +12,8 @@ WELCOME = "
12
12
  |'....|' '|..'|' .|| || ||. '|...' '|..'|' .||. '|..'|'
13
13
 
14
14
 
15
- /////////////////////////////////////////////////////////////"
15
+ /////////////////////////////////////////////////////////////
16
+ TITLE
16
17
 
17
18
  class TestSambalaMain < Test::Unit::TestCase
18
19
 
@@ -31,7 +32,7 @@ class TestSambalaMain < Test::Unit::TestCase
31
32
  ls_two = check_ls
32
33
  assert(ls_one != ls_two)
33
34
  check_lcd_put_get
34
- # check_exist
35
+
35
36
  check_cd('..')
36
37
  check_rmdir(TESTDIR)
37
38
  end
@@ -125,6 +126,8 @@ class TestSambalaMain < Test::Unit::TestCase
125
126
  assert_kind_of(Array,re)
126
127
  assert_equal(true,re[0])
127
128
 
129
+ check_exist(TESTFILE)
130
+
128
131
  @samba.local("rm #{TESTFILE}")
129
132
  after2_2 = @samba.local('ls')
130
133
  assert(before2 == after2_2)
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.9.0
4
+ version: 0.9.1
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: 2009-01-28 00:00:00 -05:00
12
+ date: 2009-02-03 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.3.1
23
+ version: 1.3.2
24
24
  version:
25
25
  description:
26
26
  email: lp@spiralix.org