Skip to content

Commit

Permalink
first listing of files works
Browse files Browse the repository at this point in the history
  • Loading branch information
jashmenn committed Jul 2, 2009
1 parent 9330b70 commit a8e723e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@
coverage
rdoc
pkg
.autosession.vim
26 changes: 21 additions & 5 deletions lib/moveit.rb
@@ -1,10 +1,15 @@
require 'rubygems'
require "has_logger"
require "net/ssh"

# FileUtils for the rest of your storage locations (ssh, s3, hdfs, etc)
module MoveIt
module FileSystem
class Base
include HasLogger

def cleanup
end
end

class POSIX < Base
Expand All @@ -18,6 +23,10 @@ def file_list(cmd)
output = @actor.exec!(cmd)
output.split("\n")
end

def cleanup
@actor.cleanup
end
end
end

Expand All @@ -29,16 +38,17 @@ class Actor

attr_accessor :ssh_options
attr_accessor :connected
attr_accessor :ssh_sesssion
attr_accessor :ssh_session

def initialize(opts={})
@ssh_options = opts[:ssh_options] if opts[:ssh_options]
@ssh_options = opts[:ssh_options] || {}
end

# connect lazily so we can share connections when doing mvs
def exec!(cmd)
connect! unless @connected
if using_ssh?
ssh_session.exec!(cmd)
else
logger.debug(cmd)
`#{cmd}`
Expand All @@ -47,9 +57,11 @@ def exec!(cmd)

def connect!
if using_ssh?
host = ssh_options[:host].delete
user = ssh_options[:user].delete || ENV["USER"]
@ssh_session = Net::SSH.start(host, user, ssh_options)
host = @ssh_options.delete(:host) || "localhost"
user = @ssh_options.delete(:user) || ENV["USER"]
@ssh_options[:logger] ||= self.logger if ENV["DEBUG"]
@ssh_options[:verbose] ||= :debug if ENV["DEBUG"]
@ssh_session = Net::SSH.start(host, user, @ssh_options)
end
@connected = true
end
Expand All @@ -58,6 +70,10 @@ def using_ssh?
ssh_options.keys.size > 0 ? true : false
end

def cleanup
ssh_session.close if ssh_session
end

end

end

0 comments on commit a8e723e

Please sign in to comment.