Class: GitMedia::Transport::Scp

Inherits:
Base
  • Object
show all
Defined in:
lib/git-media/transport/scp.rb

Instance Method Summary collapse

Methods inherited from Base

#pull, #push

Constructor Details

#initialize(user, host, path) ⇒ Scp

Returns a new instance of Scp.



14
15
16
17
18
# File 'lib/git-media/transport/scp.rb', line 14

def initialize(user, host, path)
	@user = user
	@host = host
  @path = path
end

Instance Method Details

#exist?(file) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
# File 'lib/git-media/transport/scp.rb', line 20

def exist?(file)
	if `ssh #{@user}@#{@host} [ -f "#{file}" ] && echo 1 || echo 0`.chomp == "1"
	  puts file + " exists"
	  return true
	else
	  puts file + " doesn't exists"
	  return false
	end
end

#get_file(sha, to_file) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/git-media/transport/scp.rb', line 34

def get_file(sha, to_file)
  from_file = @user+"@"+@host+":"+File.join(@path, sha)
	`scp "#{from_file}" "#{to_file}"`
  if $? == 0
	  puts sha+" downloaded"
    return true
  end
	puts sha+" download fail"
  return false
end

#get_unpushed(files) ⇒ Object



60
61
62
63
64
# File 'lib/git-media/transport/scp.rb', line 60

def get_unpushed(files)
  files.select do |f|
    !self.exist?(File.join(@path, f))
  end
end

#put_file(sha, from_file) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/git-media/transport/scp.rb', line 49

def put_file(sha, from_file)
  to_file = @user+"@"+@host+":"+File.join(@path, sha)
	`scp "#{from_file}" "#{to_file}"`
  if $? == 0
	  puts sha+" uploaded"
    return true
  end
	puts sha+" upload fail"
  return false
end

#read?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/git-media/transport/scp.rb', line 30

def read?
	return true
end

#write?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/git-media/transport/scp.rb', line 45

def write?
	return true
end