thor-ssh 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -42,4 +42,9 @@ The test run through vagrant, which seemed logical since we want to test ssh stu
42
42
 
43
43
  ### When you're done
44
44
  cd spec/vagrant
45
- vagrant halt
45
+ vagrant halt
46
+
47
+
48
+ ### TODO:
49
+
50
+ Add upload progress: https://github.com/net-ssh/net-sftp/blob/master/lib/net/sftp/operations/upload.rb
@@ -10,6 +10,7 @@ class Thor
10
10
  invoke_with_conflict_check do
11
11
  @base.destination_files.mkdir_p(File.dirname(destination))
12
12
  @base.destination_files.binwrite(destination, render)
13
+ # @base.destination_files.open(destination, 'wb') { |f| f.write render }
13
14
  end
14
15
  given_destination
15
16
  end
@@ -0,0 +1,61 @@
1
+ require 'thor-ssh/actions/create_file'
2
+ require 'open-uri'
3
+
4
+
5
+ # Class to download a file instead of creating it
6
+ class Thor
7
+ module Actions
8
+ class DownloadFile < CreateFile
9
+ attr_accessor :source
10
+
11
+ def initialize(base, source, destination, config={})
12
+ @source = source
13
+ super(base, destination, config)
14
+ end
15
+
16
+ # def exists?
17
+ # puts "CHECK EXISTS"
18
+ # false
19
+ # end
20
+
21
+ def identical?
22
+ # TODO: find a good way to check if these are identical, then move the file
23
+ # into place depending on user action
24
+ # exists? && @base.destination_files.binread(destination) == render
25
+
26
+ puts "CHECK IDENTICAL"
27
+ false
28
+ end
29
+
30
+ def render
31
+ puts "RENDER: #{source}"
32
+ @render ||= open(source) {|input| input.binmode.read }
33
+ end
34
+
35
+
36
+ def download
37
+ # Check for wget
38
+ if @base.exec("which wget").strip != ''
39
+ # We have wget, download with that
40
+ @base.exec("wget \"#{source}\" -O \"#{destination}\"")
41
+ elsif @base.exec("which curl").strip != ''
42
+ # We have curl, download
43
+ @base.exec("curl -o \"#{destination}\" \"#{source}\"")
44
+ else
45
+ # No program to download remotely
46
+ raise "To download files you need either wget or curl on the remote server"
47
+ end
48
+ end
49
+
50
+ # TODO: invoke_with_conflict_check workes except for diff
51
+ def invoke!
52
+ # invoke_with_conflict_check do
53
+ @base.say_status :download, source
54
+ @base.destination_files.mkdir_p(File.dirname(destination))
55
+ download()
56
+ # end
57
+ given_destination
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,3 +1,5 @@
1
+ require 'thor-ssh/actions/download_file'
2
+
1
3
  class Thor
2
4
  module Actions
3
5
  # TODO: link_file doesn't make since for links into the gem
@@ -9,6 +11,20 @@ class Thor
9
11
  # create_link destination, source, config
10
12
  # end
11
13
 
14
+ # Modifies #get to download files remotely, removes the ability to
15
+ # pass a blcok
16
+ def get(source, *args)
17
+ config = args.last.is_a?(Hash) ? args.pop : {}
18
+ destination = args.first
19
+
20
+ source = File.expand_path(find_in_source_paths(source.to_s)) unless source =~ /^https?\:\/\//
21
+ render = open(source) {|input| input.binmode.read }
22
+
23
+ destination ||= File.basename(source)
24
+
25
+ action DownloadFile.new(self, source, destination, config)
26
+ end
27
+
12
28
 
13
29
  def chmod(path, mode, config={})
14
30
  return unless behavior == :invoke
@@ -1,7 +1,26 @@
1
1
  require 'net/ssh'
2
2
  require 'net/sftp'
3
+ require 'stringio'
3
4
 
4
5
  module ThorSsh
6
+ class RemoteFileWriter
7
+ def initialize(connection, file)
8
+ @connection = connection
9
+ @file = file
10
+ @offset = 0
11
+ end
12
+
13
+ def write(data)
14
+ puts "WRITE: #{data.size} @ #{@offset}"
15
+ # io = StringIO.new(data)
16
+ @connection.sftp.write!(@file, @offset, data)
17
+
18
+ puts "WROTE1"
19
+
20
+ @offset += data.size
21
+ end
22
+ end
23
+
5
24
  class RemoteFile
6
25
  attr_reader :connection
7
26
 
@@ -53,13 +72,37 @@ module ThorSsh
53
72
 
54
73
  # TODO: we should just move this to a more standard thing
55
74
  def binwrite(path, data)
56
- file = connection.sftp.open!(path, 'wb')
75
+ # puts "DATA: #{data.size}"
76
+ # file = connection.sftp.open!(path, 'wb')
77
+ #
78
+ # # Write
79
+ # connection.sftp.write!(file, 0, data)
80
+ #
81
+ # # Close
82
+ # connection.sftp.close!(file)
83
+
84
+ io = StringIO.new(data)
85
+ connection.sftp.upload!(io, path)
86
+ end
87
+
88
+ def file_opened
89
+ puts "COOL)"
90
+ end
91
+
92
+ def open(file_name, mode, &block)
93
+ # Open file
94
+ file = connection.sftp.open(file_name, 'wb', &method(:file_opened))#, {:chunk_size => 4096})
57
95
 
58
- # Write
59
- connection.sftp.write!(file, 0, data)
96
+ file_writer = RemoteFileWriter.new(connection, file)
97
+
98
+ yield(file_writer)
60
99
 
61
100
  # Close
62
- connection.sftp.close!(file)
101
+ connection.sftp.close(file)
102
+
103
+ # , {:chunk_size => 4096}
104
+ # connection.sftp.file.open(file_name, mode, &block)
105
+
63
106
  end
64
107
 
65
108
  def chmod(mode, file_name)
@@ -1,3 +1,3 @@
1
1
  module ThorSsh
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/spec/actions_spec.rb CHANGED
@@ -12,6 +12,7 @@ describe ThorSsh do
12
12
 
13
13
  after do
14
14
  # Close the connection
15
+ # @thor_test.destination_connection.sftp.session.shutdown!
15
16
  @thor_test.destination_connection.close
16
17
  end
17
18
 
@@ -21,6 +22,7 @@ describe ThorSsh do
21
22
  @thor_test = ThorTest.new
22
23
  @thor_test.destination_connection = VagrantManager.connect
23
24
  @thor_test.destination_files.rm_rf(@base_path)
25
+ # @thor_test.destination_connection.sftp.session.shutdown!
24
26
  @thor_test.destination_connection.close
25
27
 
26
28
  end
@@ -92,6 +94,10 @@ describe ThorSsh do
92
94
  @thor_test.destination_files.binread(link_file).should == "Text"
93
95
  end
94
96
 
97
+ it "should download a file remotely" do
98
+ @thor_test.get('http://nginx.org/download/nginx-1.2.0.tar.gz', '/home/vagrant/nginx-1.2.0.tar.gz')
99
+ end
100
+
95
101
  end
96
102
 
97
103
 
@@ -17,6 +17,8 @@ class VagrantManager
17
17
  :paranoid => false,
18
18
  :config => false,
19
19
  :forward_agent => ssh_info[:forward_agent]
20
+ # :verbose => :debug,
21
+ # :timeout => 1
20
22
  }
21
23
 
22
24
  # Check that the private key permissions are valid
@@ -24,6 +26,8 @@ class VagrantManager
24
26
 
25
27
  # Connect to SSH, giving it a few tries
26
28
  return Net::SSH.start(ssh_info[:host], ssh_info[:username], opts)
29
+
30
+ # return Net::SSH.start("127.0.0.1", "vagrant", {:port=>2222, :keys=>["/Users/ryanstout/.vagrant.d/insecure_private_key"], :keys_only=>true, :user_known_hosts_file=>[], :paranoid=>false, :config=>false, :forward_agent=>false, :verbose=>:debug, :timeout=>1})
27
31
  end
28
32
  end
29
33
 
data/thor-ssh.gemspec CHANGED
@@ -14,8 +14,8 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "thor-ssh"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.add_runtime_dependency 'thor', '~> 0.15.2'
17
- gem.add_runtime_dependency 'net-ssh', '= 2.2.2'
18
- gem.add_runtime_dependency 'net-sftp', '= 2.0.5'
17
+ gem.add_runtime_dependency 'net-ssh'#, '= 2.2.2'
18
+ gem.add_runtime_dependency 'net-sftp'#, '= 2.0.5'
19
19
  gem.add_development_dependency 'rspec', '~> 2.10'
20
20
  gem.add_development_dependency 'vagrant', '= 1.0.3'
21
21
  gem.add_development_dependency 'rake', '~> 0.9'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thor-ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-20 00:00:00.000000000 Z
12
+ date: 2012-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -32,33 +32,33 @@ dependencies:
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - '='
35
+ - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: 2.2.2
37
+ version: '0'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - '='
43
+ - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: 2.2.2
45
+ version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: net-sftp
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - '='
51
+ - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
- version: 2.0.5
53
+ version: '0'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - '='
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
- version: 2.0.5
61
+ version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: rspec
64
64
  requirement: !ruby/object:Gem::Requirement
@@ -140,6 +140,7 @@ files:
140
140
  - lib/thor-ssh/actions.rb
141
141
  - lib/thor-ssh/actions/create_file.rb
142
142
  - lib/thor-ssh/actions/create_link.rb
143
+ - lib/thor-ssh/actions/download_file.rb
143
144
  - lib/thor-ssh/actions/empty_directory.rb
144
145
  - lib/thor-ssh/actions/file_manipulation.rb
145
146
  - lib/thor-ssh/actions/inject_into_file.rb
@@ -170,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
171
  version: '0'
171
172
  segments:
172
173
  - 0
173
- hash: -1305954903121655553
174
+ hash: 1765081219719402067
174
175
  required_rubygems_version: !ruby/object:Gem::Requirement
175
176
  none: false
176
177
  requirements:
@@ -179,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
180
  version: '0'
180
181
  segments:
181
182
  - 0
182
- hash: -1305954903121655553
183
+ hash: 1765081219719402067
183
184
  requirements: []
184
185
  rubyforge_project:
185
186
  rubygems_version: 1.8.22