delano-rye 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -4,7 +4,17 @@ TODO
4
4
 
5
5
  * Re-implement Rye::Rap as an Observable StringIO object for dynamic printing of output.
6
6
  * Fingerprints: ssh-keygen -l -f id_rsa_repos.pub
7
- * Add S3 support for Rye::Box.upload / download
7
+
8
+
9
+ #### 0.8.2 (2009-06-23) #############################
10
+
11
+ * FIXED: Rye::Box.switch_user will disconnect but not create a new connection.
12
+ * FIXED: Rye::Cmd#add_command hard coded argument handling for blocks
13
+ * CHANGE: Rye::Rap#to_s now returns stdout.join($/)
14
+ * CHANGE: Regexp workaround for remote password prompts is now case insensitive.
15
+ * ADDED: Rye::Cmd#string_upload and Rye::Cmd#string_download
16
+ * ADDED: Rye.shell example to README (thanks rogerdpack)
17
+
8
18
 
9
19
  #### 0.8.1 (2009-06-22) #############################
10
20
 
data/README.rdoc CHANGED
@@ -70,8 +70,7 @@ By default, Rye:Set connects to each machine sequentially in the order they were
70
70
  dir_upload = "#{Rye.sysinfo.tmpdir}/rye-upload/"
71
71
  dir_download = "#{Rye.sysinfo.tmpdir}/rye-download/"
72
72
 
73
- rbox.file_upload("#{RYE_HOME}/README.rdoc",
74
- "#{RYE_HOME}/LICENSE.txt", dir_upload)
73
+ rbox.file_upload("#{RYE_HOME}/README.rdoc", "#{RYE_HOME}/LICENSE.txt", dir_upload)
75
74
 
76
75
  applejack = StringIO.new("Some in-memory content")
77
76
  rbox.file_upload(applejack, "#{dir_upload}/applejack.txt")
@@ -84,6 +83,27 @@ By default, Rye:Set connects to each machine sequentially in the order they were
84
83
 
85
84
  p filecontent.read
86
85
 
86
+ == EXAMPLE 5 -- Local processes
87
+
88
+ For local processes, you can bypass <tt>Rye::Box</tt> and execute commands directly with <tt>Rye.shell</tt>:
89
+
90
+ Rye.shell :uptime # => 11:02 up 16:01, 3 users
91
+
92
+
93
+ The first argument must be the command name and the remaining arguments are sent directly as arguments to the command. They're not escaped like with <tt>Rye::Box</tt> so you can use the asterisk, environment variables, pipes, and redirects etc. Also note that you can specify single character switches as symbols and you can separate arguments or put them into a single String.
94
+
95
+ Rye.shell :ls, '*'
96
+ Rye.shell :ls, '-l $HOME'
97
+ Rye.shell :ls, :l, '$HOME > $TMPDIR/crazy.txt'
98
+
99
+ The return value is a Rye::Rap object (just like with Rye::Box) so you have access to the exit code and STDERR output:
100
+
101
+ ret = Rye.shell :ls, 'nofile'
102
+ ret.exit_code # => 1
103
+ ret.stderr # => "sh: nofile: No such file or directory"
104
+ ret.class # => Rye::Rap
105
+
106
+
87
107
 
88
108
  == About Safe-Mode
89
109
 
data/bin/try CHANGED
@@ -199,4 +199,19 @@ filecontent.rewind
199
199
  p filecontent.read
200
200
 
201
201
 
202
+ puts %Q(
203
+ # ------------------------------------------------------------------
204
+ # EXAMPLE 7 -- LOCAL PROCESSES
205
+ #)
206
+
207
+ p Rye.shell :uptime
208
+
209
+ p Rye.shell :ls, '*'
210
+ p Rye.shell :ls, '-l $HOME'
211
+ p Rye.shell :ls, :l, '$HOME > crazy.txt'
212
+
213
+ ret = Rye.shell :ls, 'nofile'
214
+ p ret.exit_code # => 1
215
+ p ret.stderr # => "sh: nofile: No such file or directory"
216
+ p ret.class # => Rye::Rap
202
217
 
data/lib/rye.rb CHANGED
@@ -43,7 +43,7 @@ module Rye
43
43
  extend self
44
44
 
45
45
  unless defined?(SYSINFO)
46
- VERSION = "0.8.1".freeze
46
+ VERSION = "0.8.2".freeze
47
47
  SYSINFO = SysInfo.new.freeze
48
48
  end
49
49
 
data/lib/rye/box.rb CHANGED
@@ -190,13 +190,14 @@ module Rye
190
190
  # * +newuser+ The username to reconnect as
191
191
  #
192
192
  # NOTE: if there is an open connection, it's disconnected
193
- # and a new one is opened for the given user.
193
+ # but not reconnected because it's possible it wasn't
194
+ # connected yet in the first place (if you create the
195
+ # instance with default settings for example)
194
196
  def switch_user(newuser)
195
197
  return if newuser.to_s == self.user.to_s
196
198
  @rye_opts ||= {}
197
199
  @rye_opts[:user] = newuser
198
200
  disconnect
199
- connect
200
201
  end
201
202
 
202
203
 
@@ -787,7 +788,7 @@ module Rye
787
788
  if type == :stderr
788
789
  # NOTE: Use sudo to test this since it prompts for a passwords.
789
790
  # Use sudo -K to kill the user's timestamp (ask for a password every time)
790
- if data =~ /Password:/
791
+ if data =~ /password:/i
791
792
  ret = Annoy.get_user_input("Password: ", '*')
792
793
  raise Rye::NoPassword if ret.nil?
793
794
  channel.send_data "#{ret}\n"
data/lib/rye/cmd.rb CHANGED
@@ -112,6 +112,23 @@ module Rye;
112
112
  # NOTE: Changes to current working directory with +cd+ or +[]+ are ignored.
113
113
  def file_download(*files); net_scp_transfer!(:download, *files); end
114
114
 
115
+ # Shorthand for +file_download('remote/path').string+
116
+ #
117
+ # Returns a String containing the content of all remote *files*.
118
+ def string_download(*files)
119
+ net_scp_transfer!(:download, *files).string
120
+ end
121
+ alias_method :str_download, :string_download
122
+
123
+ # Shorthand for +file_upload(StringIO.new('file content'), 'remote/path')+
124
+ #
125
+ # Uploads the content of the String +str+ to +remote_path+. Returns nil
126
+ def string_upload(str, remote_path)
127
+ net_scp_transfer!(:upload, StringIO.new(str), remote_path)
128
+ end
129
+ alias_method :str_upload, :string_upload
130
+
131
+
115
132
  # Append +newcontent+ to remote +filepath+. If the file doesn't exist
116
133
  # it will be created. If +backup+ is specified, +filepath+ will be
117
134
  # copied to +filepath-previous+ before appending.
@@ -120,7 +137,7 @@ module Rye;
120
137
  self.cp filepath, "#{filepath}-previous" if backup
121
138
  file_content = self.file_download filepath
122
139
  end
123
-
140
+
124
141
  file_content ||= StringIO.new
125
142
  if newcontent.is_a?(StringIO)
126
143
  newcontent.rewind
@@ -132,6 +149,12 @@ module Rye;
132
149
  self.file_upload file_content, filepath
133
150
  end
134
151
 
152
+ #--
153
+ #def file_modify(filepath, regexp, replace=nil, &block)
154
+ # raise "File not found: #{filepath}" unless self.file_exists?(filepath)
155
+ #end
156
+ #++
157
+
135
158
  # Does +path+ from the current working directory?
136
159
  def file_exists?(path)
137
160
  begin
@@ -204,8 +227,6 @@ module Rye;
204
227
  # An optional block can be provided which will be called instead
205
228
  # of calling a system command.
206
229
  def Cmd.add_command(meth, path=nil, *hard_args, &block)
207
-
208
- path ||= meth.to_s
209
230
  if block
210
231
  hard_args.unshift(path) unless path.nil? # Don't lose an argument
211
232
  define_method(meth) do |*args|
@@ -214,6 +235,7 @@ module Rye;
214
235
  block.call(*local_args)
215
236
  end
216
237
  else
238
+ path ||= meth.to_s
217
239
  define_method(meth) do |*args|
218
240
  local_args = hard_args.clone
219
241
  local_args += args
data/lib/rye/rap.rb CHANGED
@@ -85,13 +85,10 @@ module Rye;
85
85
  end
86
86
  def code; @exit_code; end
87
87
 
88
- # Returns the first element if there it's the only
89
- # one, otherwise the value of Array#to_s
90
- def to_s
91
- return self.first if self.size == 1
92
- return "" if self.size == 0
93
- super
94
- end
88
+ # Returns the first element if there's only the
89
+ # one, an empty String if there's none. Returns
90
+ # the value of self.join($/) otherwise.
91
+ def to_s; self.join $/; end
95
92
 
96
93
  # Output STDOUT content to (remote) +path+
97
94
  # This works like a shell redirect so the file contents are
data/rye.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  @spec = Gem::Specification.new do |s|
2
2
  s.name = "rye"
3
3
  s.rubyforge_project = "rye"
4
- s.version = "0.8.1"
4
+ s.version = "0.8.2"
5
5
  s.summary = "Rye: Safely run SSH commands on a bunch of machines at the same time (from Ruby)."
6
6
  s.description = s.summary
7
7
  s.author = "Delano Mandelbaum"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delano-rye
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Delano Mandelbaum