Class: GitMedia::Transport::Scp
- Defined in:
- lib/git-media/transport/scp.rb
Instance Method Summary collapse
- #exist?(file) ⇒ Boolean
- #get_file(sha, to_file) ⇒ Object
- #get_unpushed(files) ⇒ Object
-
#initialize(user, host, path, port) ⇒ Scp
constructor
A new instance of Scp.
- #put_file(sha, from_file) ⇒ Object
- #read? ⇒ Boolean
- #result ⇒ Object
- #write? ⇒ Boolean
Methods inherited from Base
Constructor Details
#initialize(user, host, path, port) ⇒ Scp
Returns a new instance of Scp.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/git-media/transport/scp.rb', line 14 def initialize(user, host, path, port) @user = user @host = host @path = path unless port === "" @sshport = "-p#{port}" end unless port === "" @scpport = "-P#{port}" end end |
Instance Method Details
#exist?(file) ⇒ Boolean
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/git-media/transport/scp.rb', line 26 def exist?(file) @file = file if Integer(result) == 1 puts file + " exists" return true else puts file + " doesn't exists" return false end end |
#get_file(sha, to_file) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/git-media/transport/scp.rb', line 46 def get_file(sha, to_file) from_file = @user+"@"+@host+":"+File.join(@path, sha) `scp #{@scpport} "#{from_file}" "#{to_file}"` if $? == 0 puts sha+" downloaded" return true end puts sha+" download fail" return false end |
#get_unpushed(files) ⇒ Object
72 73 74 75 76 |
# File 'lib/git-media/transport/scp.rb', line 72 def get_unpushed(files) files.select do |f| !self.exist?(File.join(@path, f)) end end |
#put_file(sha, from_file) ⇒ Object
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/git-media/transport/scp.rb', line 61 def put_file(sha, from_file) to_file = @user+"@"+@host+":"+File.join(@path, sha) `scp #{@scpport} "#{from_file}" "#{to_file}"` if $? == 0 puts sha+" uploaded" return true end puts sha+" upload fail" return false end |
#read? ⇒ Boolean
42 43 44 |
# File 'lib/git-media/transport/scp.rb', line 42 def read? return true end |
#result ⇒ Object
38 39 40 |
# File 'lib/git-media/transport/scp.rb', line 38 def result `ssh #{@user}@#{@host} #{@sshport} [ -f "#{@file}" ] && echo 1 || echo 0` end |
#write? ⇒ Boolean
57 58 59 |
# File 'lib/git-media/transport/scp.rb', line 57 def write? return true end |