Class: ShrubClient

Inherits:
Object
  • Object
show all
Defined in:
lib/ShrubClient.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, username, password) ⇒ ShrubClient

Returns a new instance of ShrubClient.



4
5
6
7
8
# File 'lib/ShrubClient.rb', line 4

def initialize(url, username, password)
	@url = url
	@username = username
	@password = password
end

Instance Method Details

#convert_slashes(data) ⇒ Object



23
24
25
# File 'lib/ShrubClient.rb', line 23

def convert_slashes(data)
	data.gsub(/\\/, "\\\\\\\\")
end

#copy(local_path, remote_path) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/ShrubClient.rb', line 33

def copy(local_path, remote_path)
	sz = File.size(local_path)
	data = nil
	File.open(local_path, "rb") {|f| data = f.read sz }

	base64_encoded_data = [data].pack('m')
	
	code = "data = \"#{base64_encoded_data}\".unpack('m')[0]; File.open(\"#{convert_slashes(remote_path)}\", \"wb+\") {|f| f.write(data) } "
	return run(code)
end

#dir(remote_path) ⇒ Object



27
28
29
30
31
# File 'lib/ShrubClient.rb', line 27

def dir(remote_path)
	remote_path = convert_slashes(remote_path)
	code = "system(\"dir \\\"#{remote_path}\\\"\")"
	return run(code)
end

#execute(remote_command) ⇒ Object



44
45
46
47
48
# File 'lib/ShrubClient.rb', line 44

def execute(remote_command)
	remote_command = convert_slashes(remote_command)
	code = "system(\"#{remote_command}\")"
	return run(code)
end

#purge(remote_file_path) ⇒ Object



50
51
52
53
54
# File 'lib/ShrubClient.rb', line 50

def purge(remote_file_path)
	remote_file_path = convert_slashes(remote_file_path)
	code = "system(\"del /F /Q #{remote_file_path}\")"
	return run(code)
end

#run(code) ⇒ Object



10
11
12
13
14
# File 'lib/ShrubClient.rb', line 10

def run(code)
	DRb.start_service
	runner = DRbObject.new(nil, @url)
	puts runner.run_code(@username, @password, code)
end

#runfile(filename) ⇒ Object



16
17
18
19
20
21
# File 'lib/ShrubClient.rb', line 16

def runfile(filename)
	size = File.size(filename)
	program = File.open(filename) {|f| f.read(size) }

	return run(program)
end