scutil 0.4.2 → 0.4.3

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.
@@ -1,6 +1,10 @@
1
1
 
2
2
  ==Changelog
3
3
 
4
+ ===0.4.3 | 2011-03-14
5
+
6
+ * Added preliminary support for a Net::SCP wrapper.
7
+
4
8
  ===0.4.2 | 2011-02-23
5
9
 
6
10
  * Fixed bug when using Ruby 1.8.
@@ -33,6 +33,10 @@ All of this syntactic sugar can be used as a simple class method with
33
33
  Scutil.exec_command, as an instantiable class with Scutil::Exec, or as a mixin
34
34
  with the module Scutil.
35
35
 
36
+ You can now you scutil to manage you Net::SCP connections as well. Two wrapper
37
+ functions will be defined if you have Net::SCP installed. Still in early steps,
38
+ see Scutil::Exec.
39
+
36
40
  ==Synopsis:
37
41
 
38
42
  You can use scutil in a few different ways, for more usage examples see Scutil.
@@ -29,7 +29,7 @@ require 'scutil/connection_cache'
29
29
  require 'scutil/system_connection'
30
30
 
31
31
  module Scutil
32
- SCUTIL_VERSION = '0.4.2'
32
+ SCUTIL_VERSION = '0.4.3'
33
33
 
34
34
  # By default, buffer 10M of data before writing.
35
35
  DEFAULT_OUTPUT_BUFFER_SIZE = 0xA00000
@@ -212,7 +212,6 @@ Define in :scutil_sudo_passwd.", hostname)
212
212
  sudo_passwd_state = :done
213
213
  end
214
214
  when :waiting
215
- # if (data == "\n")
216
215
  if (data =~ passwd_failed_regex)
217
216
  # Bad sudo password
218
217
  raise Scutil::Error.new("[#{conn.host}:#{channel.local_id}] Password failed for sudo.
@@ -16,7 +16,7 @@ module Scutil
16
16
  include Scutil
17
17
  attr_reader :hostname,:username
18
18
 
19
- # Defaults to current user (ENV['USER'] if _username_ is not
19
+ # Defaults to current user (ENV['USER']) if _username_ is not
20
20
  # specified.
21
21
  def initialize(hostname, username=nil, options={})
22
22
  @hostname = hostname
@@ -24,25 +24,21 @@ module Scutil
24
24
  @options = options
25
25
  end
26
26
 
27
- # See Scutil.exec_command. Takes _cmd_ and optionally _output_,
28
- # and _options_. Other arguments specified at class
29
- # initialization.
27
+ # See Scutil.exec_command. Takes _cmd_ and optionally _output_, and
28
+ # _options_. Other arguments specified at class initialization.
30
29
  #
31
- # The _options_ specified here will take precedence over those
32
- # specified in the constructor.
30
+ # The _options_ specified here will take precedence over those specified in
31
+ # the constructor.
33
32
  def exec_command(cmd, output=nil, options={})
34
33
  # Local map has precedence.
35
34
  set_options(options)
36
35
  Scutil.exec_command(@hostname, @username, cmd, output, @options)
37
36
  end
38
37
 
39
- def set_options(options={})
40
- @options.merge!(options)
41
- end
42
-
43
- # Exposes the raw Net:SSH::Connection::Session object associated
44
- # with @hostname.
38
+ # Exposes the raw Net::SSH::Connection::Session object associated
39
+ # with +:hostname+.
45
40
  def conn(pty_needed=false)
41
+ sys_conn = nil
46
42
  conn = nil
47
43
  if Scutil.connection_cache.exists?(@hostname)
48
44
  sys_conn = Scutil.connection_cache.fetch(@hostname)
@@ -51,7 +47,46 @@ module Scutil
51
47
  sys_conn = SystemConnection.new(@hostname, @options)
52
48
  conn = sys_conn.get_connection(@hostname, @username, pty_needed, @options)
53
49
  end
50
+ Scutil.connection_cache << sys_conn
54
51
  conn
55
52
  end
53
+
54
+ # Alter the options set on this instance.
55
+ def set_options(options={})
56
+ @options.merge!(options)
57
+ end
58
+
59
+ begin
60
+ require 'net/scp'
61
+ rescue LoadError
62
+ end
63
+
64
+ if defined? Net::SCP
65
+ # Convenience method for uploading files. Only available if you have
66
+ # Net::SCP. This function simply calls Net::SCP#upload! but reuses the
67
+ # SSH connection if it's available. All options and semantics are
68
+ # identical to Scutil.exec_command and Net::SCP.
69
+ #
70
+ # <em>*NB:* This function currently calls the *blocking* +upload!+
71
+ # function rather than the *non-blocking* _upload_ function. This is by
72
+ # design and will most likely be changed in the near future.</em>
73
+ def upload(local, remote, options={}, &progress)
74
+ set_options options
75
+ conn.scp.upload!(local, remote, options={}, &progress)
76
+ end
77
+
78
+ # Convenience method for downloading files. Only available if you have
79
+ # Net::SCP. This function simply calls Net::SCP#download! but reuses the
80
+ # SSH connection if it's available. All options and semantics are
81
+ # identical to Scutil.exec_command and Net::SCP.
82
+ #
83
+ # <em>*NB:* This function currently calls the *blocking* +download!+
84
+ # function rather than the *non-blocking* +download+ function. This is by
85
+ # design and will most likely be changed in the near future.</em>
86
+ def download(remote, local=nil, options={}, &progress)
87
+ set_options options
88
+ conn.scp.download!(remote, local, options={}, &progress)
89
+ end
90
+ end
56
91
  end
57
92
  end
@@ -1,8 +1,8 @@
1
1
 
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'scutil'
4
- s.version = '0.4.2'
5
- s.date = '2012-02-23'
4
+ s.version = '0.4.3'
5
+ s.date = '2012-03-14'
6
6
  s.summary = 'SSH Command UTILity'
7
7
  s.description = <<-EOF
8
8
  Scutil is a library for conveniently executing commands
@@ -14,7 +14,7 @@ EOF
14
14
  s.homepage = 'http://marcantonio.github.com/scutil'
15
15
  s.rdoc_options << '--title' << 'SSH Command UTILity' << '--main' << 'README.rdoc'
16
16
  s.extra_rdoc_files = ['README.rdoc', 'THANKS.rdoc', 'CHANGELOG.rdoc']
17
- s.add_runtime_dependency 'net-ssh', '>= 2.1.0'
17
+ s.add_runtime_dependency 'net-ssh', '>= 2.1'
18
18
  s.files = %w(
19
19
  lib/scutil.rb
20
20
  lib/scutil/connection_cache.rb
@@ -101,7 +101,7 @@ class TestScutil < Test::Unit::TestCase
101
101
  assert_instance_of(Net::SSH::Connection::Session, conn.connection)
102
102
  assert_nil(conn.pty_connection)
103
103
  end
104
-
104
+
105
105
  def test_pty_requested
106
106
  # XXX: check retvals everywhere!
107
107
  ret_val = @exec.exec_command("sudo " + TRUE_COMMAND)
@@ -161,6 +161,20 @@ class TestScutil < Test::Unit::TestCase
161
161
  assert_match(/\[#{TestScutil.hostname}\]/, @output.string)
162
162
  end
163
163
 
164
+ def test_download_file
165
+ @exec.download("/bin/ls", "./ls-binary")
166
+ conn = Scutil.connection_cache.fetch(TestScutil.hostname)
167
+ assert_not_nil(conn.connection)
168
+ assert_instance_of(Net::SSH::Connection::Session, conn.connection)
169
+ end
170
+
171
+ def test_upload_file
172
+ @exec.upload("./ls-binary", "ls-binary-up")
173
+ conn = Scutil.connection_cache.fetch(TestScutil.hostname)
174
+ assert_not_nil(conn.connection)
175
+ assert_instance_of(Net::SSH::Connection::Session, conn.connection)
176
+ end
177
+
164
178
  # def test_sudo_passwd
165
179
  # ret_val = @exec.exec_command('sudo ' + TRUE_COMMAND, nil, { :scutil_sudo_passwd => "p4ssw0rd", :scutil_sudo_passwd_regex => /^Password:/ })
166
180
  # conn = Scutil.connection_cache.fetch(TestScutil.hostname)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scutil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,19 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-23 00:00:00.000000000 Z
12
+ date: 2012-03-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-ssh
16
- requirement: &19755500 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 2.1.0
21
+ version: '2.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *19755500
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '2.1'
25
30
  description: ! " Scutil is a library for conveniently executing commands \n remotely
26
31
  via SSH.\n"
27
32
  email: marcantoniosr@gmail.com
@@ -67,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
72
  version: '0'
68
73
  requirements: []
69
74
  rubyforge_project:
70
- rubygems_version: 1.8.17
75
+ rubygems_version: 1.8.18
71
76
  signing_key:
72
77
  specification_version: 3
73
78
  summary: SSH Command UTILity