sambala 0.8.9 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sambala.rb +60 -55
- data/test/tc_sambala_main.rb +60 -5
- metadata +2 -2
data/lib/sambala.rb
CHANGED
@@ -62,50 +62,47 @@ class Sambala
|
|
62
62
|
|
63
63
|
# The +cd+ instance method takes only one argument, the path to which you wish to change directory
|
64
64
|
# === Parameters
|
65
|
-
# *
|
65
|
+
# * _to_ = the path to change directory to
|
66
66
|
# === Interactive Returns
|
67
67
|
# * _boolean_ = confirms if +cd+ operation completed successfully
|
68
68
|
# === Example
|
69
|
-
# samba.cd(
|
70
|
-
def cd(
|
71
|
-
execute_all('cd',
|
69
|
+
# samba.cd('aFolder/anOtherFolder/') # => true
|
70
|
+
def cd(to='.')
|
71
|
+
execute_all('cd',to)
|
72
72
|
end
|
73
73
|
|
74
|
-
# The +du+ instance does exactly what _du_ usually does: estimates file space usage.
|
75
|
-
# === Parameters
|
76
|
-
# * :queue = sets queue processing mode. Defaults to interactive mode when no option given.
|
74
|
+
# The +du+ instance method does exactly what _du_ usually does: estimates file space usage.
|
77
75
|
# === Interactive Returns
|
78
76
|
# * _string_ = +du+ command results
|
79
77
|
# === Example
|
80
78
|
# puts samba.du # => 34923 blocks of size 2097152. 27407 blocks available
|
81
79
|
# Total number of bytes: 59439077
|
82
|
-
def du
|
83
|
-
execute('du', '',
|
80
|
+
def du
|
81
|
+
execute('du', '', false)[1]
|
84
82
|
end
|
85
83
|
|
86
84
|
# The +del+ instance method delete files on smb shares
|
87
85
|
# === Parameters
|
88
|
-
# *
|
89
|
-
# *
|
86
|
+
# * _mask_ = the mask matching the file to be deleted inside the current working directory.
|
87
|
+
# * _queue_ = sets queue processing mode. Defaults to interactive mode when no option given.
|
90
88
|
# === Interactive Returns
|
91
89
|
# * _boolean_ = confirms if +del+ operation completed successfully
|
92
90
|
# === Example
|
93
|
-
# samba.del(
|
94
|
-
def del(
|
95
|
-
execute('del',
|
91
|
+
# samba.del('aFile') # => true
|
92
|
+
def del(mask, queue=false)
|
93
|
+
execute('del', mask, queue)[0]
|
96
94
|
end
|
97
95
|
alias rm del
|
98
96
|
# The exist? instance method is borrowed from Ruby File Class idiome.
|
99
97
|
# It is used to test the presence of files or directories on the server
|
100
98
|
# === Parameters
|
101
|
-
# *
|
102
|
-
# * :queue = sets queue processing mode. Defaults to interactive mode when no option given.
|
99
|
+
# * _mask_ = the mask matching the file or directory to look for.
|
103
100
|
# === Interactive Returns
|
104
101
|
# * _boolean_ = confirm the presence of a matching file or directory
|
105
102
|
# === Example
|
106
|
-
# samba.exist?(
|
107
|
-
def exist?(
|
108
|
-
execute('ls',
|
103
|
+
# samba.exist?('aFile') # => true
|
104
|
+
def exist?(mask)
|
105
|
+
execute('ls', mask, false)[0]
|
109
106
|
end
|
110
107
|
|
111
108
|
# The +get+ instance method copy files from smb shares.
|
@@ -125,13 +122,13 @@ class Sambala
|
|
125
122
|
|
126
123
|
# The +lcd+ instance method changes the current working directory on the local machine to the directory specified.
|
127
124
|
# === Parameters
|
128
|
-
# *
|
125
|
+
# * _to_ = the path to change directory to
|
129
126
|
# === Interactive Returns
|
130
127
|
# * _boolean_ = confirms if +cd+ operation completed successfully
|
131
128
|
# === Example
|
132
|
-
# samba.lcd(
|
133
|
-
def lcd(
|
134
|
-
execute_all('lcd',
|
129
|
+
# samba.lcd('aLocalFolder/anOtherFolder/') # => true
|
130
|
+
def lcd(to='.')
|
131
|
+
execute_all('lcd', to)
|
135
132
|
end
|
136
133
|
|
137
134
|
# The +lowercase+ method toggles lowercasing of filenames for the get command.
|
@@ -147,15 +144,14 @@ class Sambala
|
|
147
144
|
|
148
145
|
# The method +ls+ or its alias _dir_, list the files and directories matching :mask in the current working directory on the smb server.
|
149
146
|
# === Parameters
|
150
|
-
# *
|
151
|
-
# * :queue = sets queue processing mode. Defaults to interactive mode when no option given.
|
147
|
+
# * _mask_ = the mask matching the file to be listed inside the current working directory.
|
152
148
|
# === Interactive Returns
|
153
149
|
# * _string_ = containing +ls+ command results
|
154
150
|
# === Example
|
155
151
|
# samba.ls # => genpi.rb A 81 Mon Nov 17 22:12:40 2008
|
156
152
|
# 34923 blocks of size 2097152. 27407 blocks available
|
157
|
-
def ls(
|
158
|
-
execute('ls' ,
|
153
|
+
def ls(mask='')
|
154
|
+
execute('ls' ,mask, false)[1]
|
159
155
|
end
|
160
156
|
alias dir ls
|
161
157
|
|
@@ -163,50 +159,50 @@ class Sambala
|
|
163
159
|
# See man page for smbclient to get more on the details of operation
|
164
160
|
# This method has no queue processing option
|
165
161
|
# === Parameters
|
166
|
-
# *
|
162
|
+
# * _mask_ = the matching filter
|
167
163
|
# === Example
|
168
|
-
# samba.mask(
|
169
|
-
def mask(
|
170
|
-
execute_all('mask' ,
|
164
|
+
# samba.mask('filter*') # => true
|
165
|
+
def mask(mask)
|
166
|
+
execute_all('mask' ,mask)
|
171
167
|
end
|
172
168
|
|
173
169
|
# The +mget+ method copy all files matching :mask from the server to the client machine
|
174
170
|
# See man page for smbclient to get more on the details of operation
|
175
171
|
# === Parameters
|
176
|
-
# *
|
177
|
-
# *
|
172
|
+
# * _mask_ = the file matching filter
|
173
|
+
# * _queue_ = sets queue processing mode. Defaults to interactive mode when no option given.
|
178
174
|
# === Interactive Returns
|
179
175
|
# _array_ = [ _booleanSuccess_, _mgetResultMessage_ ]
|
180
176
|
# === Example
|
181
|
-
# samba.mget(
|
182
|
-
def mget(
|
183
|
-
execute('mget' ,
|
177
|
+
# samba.mget('file*') # => [true, "getting file \\file_new.txt of size 3877 as file_new.txt (99.6 kb/s) (average 89.9 kb/s)\r\n"]
|
178
|
+
def mget(mask,queue=false)
|
179
|
+
execute('mget' ,mask, queue)
|
184
180
|
end
|
185
181
|
|
186
182
|
# The method +mkdir+ or its alias _md_, creates a new directory on the server.
|
187
183
|
# === Parameters
|
188
|
-
# *
|
189
|
-
# *
|
184
|
+
# * _path_ = the directory to create
|
185
|
+
# * _queue_ = sets queue processing mode. Defaults to interactive mode when no option given.
|
190
186
|
# === Interactive Returns
|
191
187
|
# * _boolean_ = confirms if +mkdir+ operation completed successfully
|
192
188
|
# === Example
|
193
|
-
# samba.mkdir(
|
194
|
-
def mkdir(
|
195
|
-
execute('mkdir' ,
|
189
|
+
# samba.mkdir('aFolder/aNewFolder') # => true
|
190
|
+
def mkdir(path, queue=false)
|
191
|
+
execute('mkdir' ,path, queue)[0]
|
196
192
|
end
|
197
193
|
alias md mkdir
|
198
194
|
|
199
195
|
# The +mput+ method copy all files matching :mask in the current working directory on the local machine to the server.
|
200
196
|
# See man page for smbclient to get more on the details of operation
|
201
197
|
# === Parameters
|
202
|
-
# *
|
203
|
-
# *
|
198
|
+
# * _mask_ = the file matching filter
|
199
|
+
# * _queue_ = sets queue processing mode. Defaults to interactive mode when no option given.
|
204
200
|
# === Interactive Returns
|
205
201
|
# _array_ = [ _booleanSuccess_, _mputResultMessage_ ]
|
206
202
|
# === Example
|
207
|
-
# samba.mput(
|
208
|
-
def mput(
|
209
|
-
execute('mput' ,
|
203
|
+
# samba.mput('file*') # => [true, "putting file \\file_new.txt of size 1004 as file_new.txt (65.4 kb/s) (average 65.4 kb/s)\r\n"]
|
204
|
+
def mput(mask, queue=false)
|
205
|
+
execute('mput' ,mask, queue)
|
210
206
|
end
|
211
207
|
|
212
208
|
# The +put+ instance method copy files to smb shares.
|
@@ -237,26 +233,35 @@ class Sambala
|
|
237
233
|
|
238
234
|
# The +rmdir+ method deletes the specified directory
|
239
235
|
# === Parameters
|
240
|
-
# *
|
241
|
-
# *
|
236
|
+
# * _path_ = the relative path to the directory to be deleted
|
237
|
+
# * _queue_ = sets queue processing mode. Defaults to interactive mode when no option given.
|
242
238
|
# === Interactive Returns
|
243
239
|
# * _boolean_ = confirms if +rmdir+ operation completed successfully
|
244
240
|
# === Example
|
245
|
-
# samba.rmdir(
|
246
|
-
def rmdir(
|
247
|
-
execute('rmdir' ,
|
241
|
+
# samba.rmdir('mydir') # => true
|
242
|
+
def rmdir(path,queue=false)
|
243
|
+
execute('rmdir' , path, queue)[0]
|
248
244
|
end
|
249
245
|
|
250
246
|
# The +volume+ method returns remote volume information.
|
251
|
-
# === Parameters
|
252
|
-
# * :queue = sets queue processing mode. Defaults to interactive mode when no option given.
|
253
247
|
# === Interactive Returns
|
254
248
|
# * _string_ = containing +volume+ command results
|
255
249
|
# === Example
|
256
250
|
# samba.volume # => "Volume: |geminishare| serial number 0x6d723053"
|
257
|
-
def volume
|
258
|
-
execute('volume' ,'',
|
251
|
+
def volume
|
252
|
+
execute('volume' ,'', false)[1]
|
259
253
|
end
|
254
|
+
|
255
|
+
# The +local+ methods allow shell command execution on the local machine.
|
256
|
+
# === Parameters
|
257
|
+
# * _command_ = the shell comand to be executed locally
|
258
|
+
# === Interactive Returns
|
259
|
+
# * _string_ = the normal return message of the command
|
260
|
+
# === Example
|
261
|
+
# samba.local('mkdir mydir')
|
262
|
+
def local(command)
|
263
|
+
execute('!', command, false)[1]
|
264
|
+
end
|
260
265
|
|
261
266
|
# The +queue_results+ methods collect a done queue items results
|
262
267
|
# === Example
|
data/test/tc_sambala_main.rb
CHANGED
@@ -2,7 +2,17 @@ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
|
|
2
2
|
require 'test/unit'
|
3
3
|
require 'sambala'
|
4
4
|
|
5
|
-
|
5
|
+
TESTFILE = 'sambala_test'
|
6
|
+
TESTDIR = 'sambala_temp'
|
7
|
+
WELCOME = "
|
8
|
+
.|'''.| '|| '||
|
9
|
+
||.. ' .... .. .. .. || ... .... || ....
|
10
|
+
''|||. '' .|| || || || ||' || '' .|| || '' .||
|
11
|
+
. '|| .|' || || || || || | .|' || || .|' ||
|
12
|
+
|'....|' '|..'|' .|| || ||. '|...' '|..'|' .||. '|..'|'
|
13
|
+
|
14
|
+
|
15
|
+
/////////////////////////////////////////////////////////////"
|
6
16
|
|
7
17
|
class TestSambalaMain < Test::Unit::TestCase
|
8
18
|
|
@@ -17,16 +27,20 @@ class TestSambalaMain < Test::Unit::TestCase
|
|
17
27
|
check_mkdir(TESTDIR)
|
18
28
|
check_exist(TESTDIR)
|
19
29
|
check_cd(TESTDIR)
|
30
|
+
|
20
31
|
ls_two = check_ls
|
21
32
|
assert(ls_one != ls_two)
|
33
|
+
check_lcd_put_get
|
22
34
|
# check_exist
|
23
35
|
check_cd('..')
|
24
36
|
check_rmdir(TESTDIR)
|
25
37
|
end
|
26
38
|
|
27
39
|
def teardown
|
40
|
+
@samba.rmdir(TESTDIR) if @samba.exist?(TESTDIR)
|
28
41
|
close = @samba.close
|
29
42
|
assert(close)
|
43
|
+
Dir.rmdir(TESTDIR) if File.exist?(TESTDIR)
|
30
44
|
end
|
31
45
|
|
32
46
|
private
|
@@ -37,6 +51,7 @@ class TestSambalaMain < Test::Unit::TestCase
|
|
37
51
|
end
|
38
52
|
|
39
53
|
def get_samba_param_from_input
|
54
|
+
puts WELCOME
|
40
55
|
puts "I will need you to input some working Samba connection settings..."
|
41
56
|
print "\n"; sleep 1
|
42
57
|
print "host name or IP: "
|
@@ -73,23 +88,63 @@ class TestSambalaMain < Test::Unit::TestCase
|
|
73
88
|
end
|
74
89
|
|
75
90
|
def check_cd(path)
|
76
|
-
cd = @samba.cd(
|
91
|
+
cd = @samba.cd(path)
|
77
92
|
assert_equal(true,cd)
|
78
93
|
end
|
79
94
|
|
80
95
|
def check_exist(path)
|
81
|
-
exist = @samba.exist?(
|
96
|
+
exist = @samba.exist?(path)
|
82
97
|
assert_equal(true,exist)
|
83
98
|
end
|
84
99
|
|
85
100
|
def check_mkdir(path)
|
86
|
-
re = @samba.mkdir(
|
101
|
+
re = @samba.mkdir(path)
|
87
102
|
assert_equal(true,re)
|
88
103
|
end
|
89
104
|
|
90
105
|
def check_rmdir(path)
|
91
|
-
re = @samba.rmdir(
|
106
|
+
re = @samba.rmdir(path)
|
107
|
+
assert_equal(true,re)
|
108
|
+
end
|
109
|
+
|
110
|
+
def check_lcd_put_get
|
111
|
+
before = @samba.local('ls')
|
112
|
+
@samba.local("mkdir #{TESTDIR}")
|
113
|
+
after = @samba.local('ls')
|
114
|
+
assert(before != after)
|
115
|
+
|
116
|
+
re = @samba.lcd(TESTDIR)
|
117
|
+
assert_equal(true,re)
|
118
|
+
before2 = @samba.local('ls')
|
119
|
+
@samba.local("touch #{TESTFILE}")
|
120
|
+
after2 = @samba.local('ls')
|
121
|
+
assert(before2 != after2)
|
122
|
+
|
123
|
+
|
124
|
+
re = @samba.put(:from => TESTFILE, :to => TESTFILE)
|
125
|
+
assert_kind_of(Array,re)
|
126
|
+
assert_equal(true,re[0])
|
127
|
+
|
128
|
+
@samba.local("rm #{TESTFILE}")
|
129
|
+
after2_2 = @samba.local('ls')
|
130
|
+
assert(before2 == after2_2)
|
131
|
+
|
132
|
+
re = @samba.get(:from => TESTFILE, :to => TESTFILE)
|
133
|
+
assert_kind_of(Array,re)
|
134
|
+
assert_equal(true,re[0])
|
135
|
+
|
136
|
+
re = @samba.del(TESTFILE)
|
137
|
+
assert_equal(true,re)
|
138
|
+
|
139
|
+
after2_3 = @samba.local('ls')
|
140
|
+
assert(after2 == after2_3)
|
141
|
+
@samba.local("rm #{TESTFILE}")
|
142
|
+
|
143
|
+
re = @samba.lcd('..')
|
92
144
|
assert_equal(true,re)
|
145
|
+
@samba.local("rmdir #{TESTDIR}")
|
146
|
+
after = @samba.local('ls')
|
147
|
+
assert(before == after)
|
93
148
|
end
|
94
149
|
|
95
150
|
|
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.
|
4
|
+
version: 0.9.0
|
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-
|
12
|
+
date: 2009-01-28 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|