shellshot 0.4.0 → 0.4.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.rdoc +10 -5
- data/Rakefile +10 -1
- data/VERSION +1 -1
- data/lib/shellshot.rb +11 -7
- data/profile/profile_helper.rb +8 -0
- data/profile/shellshot_profile.rb +41 -0
- data/shellshot.gemspec +5 -3
- data/spec/shellshot_spec.rb +14 -0
- data/spec/spec_helper.rb +2 -3
- metadata +5 -3
data/README.rdoc
CHANGED
@@ -5,13 +5,13 @@ http://dekaft.underlog.org
|
|
5
5
|
|
6
6
|
== DESCRIPTION:
|
7
7
|
|
8
|
-
A small library dealing with the obscurities of shell commands, piping and timeouts.
|
8
|
+
A small library dealing with the obscurities of shell commands, piping and timeouts.
|
9
9
|
Most of the stuff comes from bad experience in http://beanstalkapp.com.
|
10
10
|
|
11
11
|
== FEATURES/PROBLEMS:
|
12
12
|
|
13
13
|
The whole thing would probably not work in Windows. Not my first time I guess.
|
14
|
-
|
14
|
+
The capture of the output hangs if large amount of text is passed (tests captured it at ~10k chars). If you need larger amounts of text, write them in a temp file somewhere.
|
15
15
|
== SYNOPSIS:
|
16
16
|
|
17
17
|
# Basic usage
|
@@ -22,15 +22,20 @@ The whole thing would probably not work in Windows. Not my first time I guess.
|
|
22
22
|
Shellshot.exec "ruby -e %q[ruby -e "puts 'Hello World'"], :stdout => '/tmp/out', :stderr => '/tmp/err'
|
23
23
|
Shellshot.exec "ruby -e %q[ruby -e "puts 'Hello World'"], :stdall => '/tmp/all'
|
24
24
|
|
25
|
-
#
|
26
|
-
|
25
|
+
# Silence standard outputs. false works for stdout, stderr, and stdall
|
26
|
+
Shellshot.exec "ruby -e %q[ruby -e "puts 'Hello World'"], :stdout => false
|
27
|
+
|
28
|
+
# Timeout
|
29
|
+
begin
|
27
30
|
Shellshot.exec "ruby -e 'sleep 10000'", :timeout => 2 # seconds
|
28
31
|
rescue Timeout::Error => e
|
29
|
-
# ...
|
32
|
+
# ...
|
30
33
|
end
|
31
34
|
|
32
35
|
|
33
36
|
== HISTORY:
|
37
|
+
- 0.4.0 Capture stds with pipes
|
38
|
+
- 0.3.0 Raise error on abnormal exits
|
34
39
|
- 0.2.0 Switched to SystemTimer (*not* system_timer) for timeouts. The original was not working after all. Fixed one comment stating the wrong unit.
|
35
40
|
- 0.1.0 Initial release.
|
36
41
|
|
data/Rakefile
CHANGED
@@ -7,7 +7,7 @@ begin
|
|
7
7
|
gem.name = "shellshot"
|
8
8
|
gem.summary = %Q{ruby proxy handling the complexities of system invocations}
|
9
9
|
gem.description = %Q{
|
10
|
-
A small library dealing with the obscurities of shell commands, piping and timeouts.
|
10
|
+
A small library dealing with the obscurities of shell commands, piping and timeouts.
|
11
11
|
Most of the stuff comes from bad experience in http://beanstalkapp.com.
|
12
12
|
}
|
13
13
|
gem.email = "underlog@gmail.com"
|
@@ -52,3 +52,12 @@ Rake::RDocTask.new do |rdoc|
|
|
52
52
|
rdoc.rdoc_files.include('README*')
|
53
53
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
54
|
end
|
55
|
+
|
56
|
+
require 'ruby-prof/task'
|
57
|
+
desc "run the profile tests"
|
58
|
+
Rake::TestTask.new(:profile) do |t|
|
59
|
+
t.libs << "profile"
|
60
|
+
t.pattern = 'profile/*_profile.rb'
|
61
|
+
t.verbose = true
|
62
|
+
t.warning = false
|
63
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/lib/shellshot.rb
CHANGED
@@ -36,7 +36,7 @@ module Shellshot
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def stderr_contents
|
39
|
-
unless stderr_defined?
|
39
|
+
@stderr_contents ||= unless stderr_defined?
|
40
40
|
@stderr_wr.close
|
41
41
|
contents = @stderr_rd.read
|
42
42
|
@stderr_rd.close
|
@@ -47,7 +47,7 @@ module Shellshot
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def stdout_contents
|
50
|
-
unless stdout_defined?
|
50
|
+
@stdout_contents ||= unless stdout_defined?
|
51
51
|
@stdout_wr.close
|
52
52
|
contents = @stdout_rd.read
|
53
53
|
@stdout_rd.close
|
@@ -82,11 +82,11 @@ module Shellshot
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def stderr_location
|
85
|
-
stdall_location || options[:stderr]
|
85
|
+
stdall_location || (options[:stderr] == false ? null_location : options[:stderr])
|
86
86
|
end
|
87
87
|
|
88
88
|
def stdout_location
|
89
|
-
stdall_location || options[:stdout]
|
89
|
+
stdall_location || (options[:stdout] == false ? null_location : options[:stdout])
|
90
90
|
end
|
91
91
|
|
92
92
|
def stderr_descriptor
|
@@ -104,15 +104,15 @@ module Shellshot
|
|
104
104
|
end
|
105
105
|
|
106
106
|
def stderr_defined?
|
107
|
-
|
107
|
+
!stderr_location.nil?
|
108
108
|
end
|
109
109
|
|
110
110
|
def stdout_defined?
|
111
|
-
|
111
|
+
!stdout_location.nil?
|
112
112
|
end
|
113
113
|
|
114
114
|
def stdall_location
|
115
|
-
options[:stdall]
|
115
|
+
options[:stdall] == false ? null_location : options[:stdall]
|
116
116
|
end
|
117
117
|
|
118
118
|
def close_reading_pipes
|
@@ -125,6 +125,10 @@ module Shellshot
|
|
125
125
|
@stdout_rd, @stdout_wr = IO.pipe unless stdout_defined?
|
126
126
|
end
|
127
127
|
|
128
|
+
def null_location
|
129
|
+
"/dev/null"
|
130
|
+
end
|
131
|
+
|
128
132
|
end
|
129
133
|
|
130
134
|
def self.exec(command, options = {})
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/profile_helper')
|
2
|
+
|
3
|
+
class ShellshotProfile < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
RubyProf.measure_mode = RubyProf::WALL_TIME
|
7
|
+
end
|
8
|
+
|
9
|
+
def benchmark(title, &block)
|
10
|
+
puts "#{title} \n"
|
11
|
+
time = Benchmark.measure &block
|
12
|
+
puts "Time spent: #{time.to_s.squeeze.strip} \n"
|
13
|
+
end
|
14
|
+
|
15
|
+
def cmd
|
16
|
+
%q[ruby -e '10000.times { puts "a" }']
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_builtin_exec
|
20
|
+
profile "system" do
|
21
|
+
system("#{cmd} > /dev/null")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_executing_large_stdout
|
26
|
+
profile "Shellshot" do
|
27
|
+
Shellshot.exec cmd #, :stdout => '/dev/null'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def profile(name, &block)
|
32
|
+
time = Benchmark.measure do
|
33
|
+
result = RubyProf.profile &block
|
34
|
+
printer = RubyProf::FlatPrinter.new(result)
|
35
|
+
puts "\n#== #{name} ==\n"
|
36
|
+
printer.print(STDOUT, :min_percent => 10)
|
37
|
+
end
|
38
|
+
puts "Time spent: #{time.to_s.squeeze.strip} \n"
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/shellshot.gemspec
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{shellshot}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Petyo Ivanov"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-01-06}
|
13
13
|
s.description = %q{
|
14
|
-
A small library dealing with the obscurities of shell commands, piping and timeouts.
|
14
|
+
A small library dealing with the obscurities of shell commands, piping and timeouts.
|
15
15
|
Most of the stuff comes from bad experience in http://beanstalkapp.com.
|
16
16
|
}
|
17
17
|
s.email = %q{underlog@gmail.com}
|
@@ -27,6 +27,8 @@ Gem::Specification.new do |s|
|
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
29
|
"lib/shellshot.rb",
|
30
|
+
"profile/profile_helper.rb",
|
31
|
+
"profile/shellshot_profile.rb",
|
30
32
|
"shellshot.gemspec",
|
31
33
|
"spec/shellshot_spec.rb",
|
32
34
|
"spec/spec_helper.rb"
|
data/spec/shellshot_spec.rb
CHANGED
@@ -43,6 +43,20 @@ describe Shellshot do
|
|
43
43
|
cmd.stderr_contents.should == "test"
|
44
44
|
end
|
45
45
|
|
46
|
+
it "should discard stdout and stderr if false passed" do
|
47
|
+
cmd = Shellshot::Command.new
|
48
|
+
cmd.exec %q[ruby -e '$stderr << "test"; $stdout << "test"'], :stdout => false, :stderr => false
|
49
|
+
cmd.stderr_contents.should == ""
|
50
|
+
cmd.stdout_contents.should == ""
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should discard stdout and stderr if stdall = false" do
|
54
|
+
cmd = Shellshot::Command.new
|
55
|
+
cmd.exec %q[ruby -e '$stderr << "test"; $stdout << "test"'], :stdall => false
|
56
|
+
cmd.stderr_contents.should == ""
|
57
|
+
cmd.stdout_contents.should == ""
|
58
|
+
end
|
59
|
+
|
46
60
|
end
|
47
61
|
|
48
62
|
# EOF
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
require File.expand_path(
|
3
2
|
File.join(File.dirname(__FILE__), %w[.. lib shellshot]))
|
4
3
|
|
@@ -6,7 +5,7 @@ require 'tmpdir'
|
|
6
5
|
require 'rubygems'
|
7
6
|
require 'ruby-debug'
|
8
7
|
|
9
|
-
Spec::Matchers.define :be_a_file do
|
8
|
+
Spec::Matchers.define :be_a_file do
|
10
9
|
match do |path|
|
11
10
|
File.exists?(path)
|
12
11
|
end
|
@@ -28,7 +27,7 @@ end
|
|
28
27
|
|
29
28
|
Spec::Runner.configure do |config|
|
30
29
|
config.before(:each) do
|
31
|
-
@tmpdir = Dir.mktmpdir
|
30
|
+
@tmpdir = Dir.mktmpdir
|
32
31
|
Dir.chdir(@tmpdir)
|
33
32
|
end
|
34
33
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shellshot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Petyo Ivanov
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-06 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: "0"
|
34
34
|
version:
|
35
|
-
description: "\n A small library dealing with the obscurities of shell commands, piping and timeouts
|
35
|
+
description: "\n A small library dealing with the obscurities of shell commands, piping and timeouts.\n Most of the stuff comes from bad experience in http://beanstalkapp.com.\n "
|
36
36
|
email: underlog@gmail.com
|
37
37
|
executables: []
|
38
38
|
|
@@ -49,6 +49,8 @@ files:
|
|
49
49
|
- Rakefile
|
50
50
|
- VERSION
|
51
51
|
- lib/shellshot.rb
|
52
|
+
- profile/profile_helper.rb
|
53
|
+
- profile/shellshot_profile.rb
|
52
54
|
- shellshot.gemspec
|
53
55
|
- spec/shellshot_spec.rb
|
54
56
|
- spec/spec_helper.rb
|