pipe-run 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -4
- data/Gemfile.lock +4 -4
- data/Rakefile +4 -12
- data/VERSION +1 -1
- data/lib/em-pipe-run.rb +49 -3
- data/lib/pipe-run.rb +47 -4
- data/pipe-run.gemspec +16 -15
- data/test.rb +26 -0
- metadata +39 -45
data/Gemfile
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
# Add dependencies required to use your gem here.
|
3
3
|
# Example:
|
4
|
-
# gem "depq", ">= 0.4"
|
5
|
-
# gem "hash-utils", ">= 0.7.0"
|
6
4
|
|
7
5
|
# Add dependencies to develop your gem here.
|
8
6
|
# Include everything needed to run rake, tests, features, etc.
|
9
7
|
group :development do
|
10
|
-
gem "bundler", "
|
11
|
-
gem "jeweler", "
|
8
|
+
gem "bundler", ">= 1.0.0"
|
9
|
+
gem "jeweler", ">= 1.5.2"
|
12
10
|
end
|
data/Gemfile.lock
CHANGED
@@ -2,8 +2,8 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
git (1.2.5)
|
5
|
-
jeweler (1.
|
6
|
-
bundler (~> 1.0
|
5
|
+
jeweler (1.6.4)
|
6
|
+
bundler (~> 1.0)
|
7
7
|
git (>= 1.2.5)
|
8
8
|
rake
|
9
9
|
rake (0.8.7)
|
@@ -12,5 +12,5 @@ PLATFORMS
|
|
12
12
|
ruby
|
13
13
|
|
14
14
|
DEPENDENCIES
|
15
|
-
bundler (
|
16
|
-
jeweler (
|
15
|
+
bundler (>= 1.0.0)
|
16
|
+
jeweler (>= 1.5.2)
|
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'rubygems'
|
3
3
|
require 'bundler'
|
4
|
+
|
4
5
|
begin
|
5
6
|
Bundler.setup(:default, :development)
|
6
7
|
rescue Bundler::BundlerError => e
|
@@ -8,15 +9,16 @@ rescue Bundler::BundlerError => e
|
|
8
9
|
$stderr.puts "Run `bundle install` to install missing gems"
|
9
10
|
exit e.status_code
|
10
11
|
end
|
11
|
-
require 'rake'
|
12
12
|
|
13
|
+
require 'rake'
|
13
14
|
require 'jeweler'
|
15
|
+
|
14
16
|
Jeweler::Tasks.new do |gem|
|
15
17
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
16
18
|
gem.name = "pipe-run"
|
17
19
|
gem.homepage = "https://github.com/martinkozak/pipe-run"
|
18
20
|
gem.license = "MIT"
|
19
|
-
gem.summary = '
|
21
|
+
gem.summary = 'Executes shell command and returns its outputs in single call. Both synchronous and asynchronous (with EventMachine) executing is supported.'
|
20
22
|
gem.email = "martinkozak@martinkozak.net"
|
21
23
|
gem.authors = ["Martin Kozák"]
|
22
24
|
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
@@ -25,13 +27,3 @@ Jeweler::Tasks.new do |gem|
|
|
25
27
|
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
28
|
end
|
27
29
|
Jeweler::RubygemsDotOrgTasks.new
|
28
|
-
|
29
|
-
require 'rake/rdoctask'
|
30
|
-
Rake::RDocTask.new do |rdoc|
|
31
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
32
|
-
|
33
|
-
rdoc.rdoc_dir = 'rdoc'
|
34
|
-
rdoc.title = "qrpc #{version}"
|
35
|
-
rdoc.rdoc_files.include('README*')
|
36
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
37
|
-
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/em-pipe-run.rb
CHANGED
@@ -21,7 +21,11 @@ class Pipe
|
|
21
21
|
##
|
22
22
|
# Holds pipe output buffer.
|
23
23
|
#
|
24
|
+
# @returns [String] buffer content
|
25
|
+
# @since 0.3.0
|
26
|
+
#
|
24
27
|
|
28
|
+
attr_accessor :buffer
|
25
29
|
@buffer
|
26
30
|
|
27
31
|
##
|
@@ -61,11 +65,11 @@ class Pipe
|
|
61
65
|
end
|
62
66
|
|
63
67
|
##
|
64
|
-
# Runs the command and
|
65
|
-
# Blocking.
|
68
|
+
# Runs the command and yields its standard output.
|
66
69
|
#
|
67
70
|
# @param [String] command command for run
|
68
71
|
# @param [Proc] block callback for giving back the results
|
72
|
+
# @yield [String] command standard output
|
69
73
|
# @since 0.2.0
|
70
74
|
#
|
71
75
|
|
@@ -73,5 +77,47 @@ class Pipe
|
|
73
77
|
pipe = File.popen(command, "r")
|
74
78
|
EM::attach(pipe, Receiver, block)
|
75
79
|
end
|
76
|
-
|
80
|
+
|
81
|
+
##
|
82
|
+
# Runs the command and yields both its standard output
|
83
|
+
# and error output.
|
84
|
+
#
|
85
|
+
# @param [String] command command for run
|
86
|
+
# @param [Proc] block callback for giving back the results
|
87
|
+
# @yield [String] command standard output
|
88
|
+
# @yield [String] command erroroutput
|
89
|
+
# @since 0.3.0
|
90
|
+
#
|
91
|
+
|
92
|
+
def self.run_nonblock2(command, &block)
|
93
|
+
begin
|
94
|
+
stdin, stdout, stderr = Open3.popen3(command)
|
95
|
+
rescue NameError
|
96
|
+
require "open3"
|
97
|
+
retry
|
98
|
+
end
|
99
|
+
|
100
|
+
outval = nil
|
101
|
+
errval = nil
|
102
|
+
|
103
|
+
yielder = Proc::new do
|
104
|
+
if (not outval.nil?) and (not errval.nil?)
|
105
|
+
yield outval, errval
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
outcall = Proc::new do |_outval|
|
110
|
+
outval = _outval
|
111
|
+
yielder.call()
|
112
|
+
end
|
113
|
+
|
114
|
+
errcall = Proc::new do |_errval|
|
115
|
+
errval = _errval
|
116
|
+
yielder.call()
|
117
|
+
end
|
118
|
+
|
119
|
+
EM::attach(stdout, Receiver, outcall)
|
120
|
+
EM::attach(stderr, Receiver, errcall)
|
121
|
+
end
|
122
|
+
|
77
123
|
end
|
data/lib/pipe-run.rb
CHANGED
@@ -11,20 +11,22 @@ class Pipe
|
|
11
11
|
# Runs the command and returns its standard output.
|
12
12
|
#
|
13
13
|
# If block is given, treat call as non-blocking. In that case,
|
14
|
-
# +em-pipe-run+
|
14
|
+
# loads +em-pipe-run+ and expects EventMachine loaded.
|
15
15
|
#
|
16
16
|
# @param [String] command command for run
|
17
17
|
# @param [Proc] block block for giving back the results
|
18
|
+
# @yield [String] command output
|
18
19
|
# @return [String] command output
|
19
20
|
#
|
20
21
|
|
21
22
|
def self.run(command, &block)
|
22
23
|
if not block.nil?
|
23
|
-
|
24
|
+
begin
|
25
|
+
return self.run_nonblock(command, &block)
|
26
|
+
rescue NoMethodError
|
24
27
|
require "em-pipe-run"
|
28
|
+
retry
|
25
29
|
end
|
26
|
-
|
27
|
-
return self.run_nonblock(command, &block)
|
28
30
|
end
|
29
31
|
|
30
32
|
###
|
@@ -37,4 +39,45 @@ class Pipe
|
|
37
39
|
return result
|
38
40
|
end
|
39
41
|
|
42
|
+
##
|
43
|
+
# Runs the command and returns both standard output
|
44
|
+
# and error output.
|
45
|
+
#
|
46
|
+
# If block is given, treat call as non-blocking. In that case,
|
47
|
+
# loads +em-pipe-run+ and expects EventMachine loaded.
|
48
|
+
#
|
49
|
+
# @param [String] command command for run
|
50
|
+
# @param [Proc] block block for giving back the results
|
51
|
+
# @return [Array] command output and error output
|
52
|
+
# @since 0.3.0
|
53
|
+
#
|
54
|
+
|
55
|
+
def self.run2(command, &block)
|
56
|
+
if not block.nil?
|
57
|
+
begin
|
58
|
+
return self.run_nonblock2(command, &block)
|
59
|
+
rescue NoMethodError
|
60
|
+
require "em-pipe-run"
|
61
|
+
retry
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
###
|
66
|
+
|
67
|
+
begin
|
68
|
+
stdin, stdout, stderr = Open3.popen3(command)
|
69
|
+
rescue NameError
|
70
|
+
require "open3"
|
71
|
+
retry
|
72
|
+
end
|
73
|
+
|
74
|
+
stdin.close()
|
75
|
+
outvalue = stdout.read
|
76
|
+
stdout.close()
|
77
|
+
errvalue = stderr.read
|
78
|
+
stderr.close()
|
79
|
+
|
80
|
+
return [outvalue, errvalue]
|
81
|
+
end
|
82
|
+
|
40
83
|
end
|
data/pipe-run.gemspec
CHANGED
@@ -4,13 +4,13 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "0.
|
7
|
+
s.name = "pipe-run"
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Martin
|
12
|
-
s.date =
|
13
|
-
s.email =
|
11
|
+
s.authors = ["Martin Koz\u{e1}k"]
|
12
|
+
s.date = "2011-11-08"
|
13
|
+
s.email = "martinkozak@martinkozak.net"
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE.txt",
|
16
16
|
"README.md"
|
@@ -25,27 +25,28 @@ Gem::Specification.new do |s|
|
|
25
25
|
"VERSION",
|
26
26
|
"lib/em-pipe-run.rb",
|
27
27
|
"lib/pipe-run.rb",
|
28
|
-
"pipe-run.gemspec"
|
28
|
+
"pipe-run.gemspec",
|
29
|
+
"test.rb"
|
29
30
|
]
|
30
|
-
s.homepage =
|
31
|
+
s.homepage = "https://github.com/martinkozak/pipe-run"
|
31
32
|
s.licenses = ["MIT"]
|
32
33
|
s.require_paths = ["lib"]
|
33
|
-
s.rubygems_version =
|
34
|
-
s.summary =
|
34
|
+
s.rubygems_version = "1.8.11"
|
35
|
+
s.summary = "Executes shell command and returns its outputs in single call. Both synchronous and asynchronous (with EventMachine) executing is supported."
|
35
36
|
|
36
37
|
if s.respond_to? :specification_version then
|
37
38
|
s.specification_version = 3
|
38
39
|
|
39
40
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
40
|
-
s.add_development_dependency(%q<bundler>, ["
|
41
|
-
s.add_development_dependency(%q<jeweler>, ["
|
41
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
42
|
+
s.add_development_dependency(%q<jeweler>, [">= 1.5.2"])
|
42
43
|
else
|
43
|
-
s.add_dependency(%q<bundler>, ["
|
44
|
-
s.add_dependency(%q<jeweler>, ["
|
44
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
45
|
+
s.add_dependency(%q<jeweler>, [">= 1.5.2"])
|
45
46
|
end
|
46
47
|
else
|
47
|
-
s.add_dependency(%q<bundler>, ["
|
48
|
-
s.add_dependency(%q<jeweler>, ["
|
48
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
49
|
+
s.add_dependency(%q<jeweler>, [">= 1.5.2"])
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
data/test.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
4
|
+
|
5
|
+
$:.push("./lib")
|
6
|
+
$:.unshift("./lib")
|
7
|
+
|
8
|
+
require "eventmachine"
|
9
|
+
require "pipe-run"
|
10
|
+
require "em-pipe-run"
|
11
|
+
|
12
|
+
|
13
|
+
EM::run do
|
14
|
+
p Pipe::run("date")
|
15
|
+
p Pipe::run2("date")
|
16
|
+
|
17
|
+
Pipe::run("date") do |out|
|
18
|
+
p out
|
19
|
+
end
|
20
|
+
|
21
|
+
Pipe::run2("date") do |*args|
|
22
|
+
p args
|
23
|
+
end
|
24
|
+
|
25
|
+
p "x"
|
26
|
+
end
|
metadata
CHANGED
@@ -1,50 +1,46 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: pipe-run
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.2.1
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
-
|
7
|
+
authors:
|
8
|
+
- Martin Kozák
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-11-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
17
15
|
name: bundler
|
18
|
-
requirement: &
|
16
|
+
requirement: &20057480 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
21
|
-
- -
|
22
|
-
- !ruby/object:Gem::Version
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
23
21
|
version: 1.0.0
|
24
22
|
type: :development
|
25
23
|
prerelease: false
|
26
|
-
version_requirements: *
|
27
|
-
- !ruby/object:Gem::Dependency
|
24
|
+
version_requirements: *20057480
|
25
|
+
- !ruby/object:Gem::Dependency
|
28
26
|
name: jeweler
|
29
|
-
requirement: &
|
27
|
+
requirement: &20056740 !ruby/object:Gem::Requirement
|
30
28
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
34
32
|
version: 1.5.2
|
35
33
|
type: :development
|
36
34
|
prerelease: false
|
37
|
-
version_requirements: *
|
35
|
+
version_requirements: *20056740
|
38
36
|
description:
|
39
37
|
email: martinkozak@martinkozak.net
|
40
38
|
executables: []
|
41
|
-
|
42
39
|
extensions: []
|
43
|
-
|
44
|
-
extra_rdoc_files:
|
40
|
+
extra_rdoc_files:
|
45
41
|
- LICENSE.txt
|
46
42
|
- README.md
|
47
|
-
files:
|
43
|
+
files:
|
48
44
|
- .document
|
49
45
|
- Gemfile
|
50
46
|
- Gemfile.lock
|
@@ -55,36 +51,34 @@ files:
|
|
55
51
|
- lib/em-pipe-run.rb
|
56
52
|
- lib/pipe-run.rb
|
57
53
|
- pipe-run.gemspec
|
58
|
-
|
54
|
+
- test.rb
|
59
55
|
homepage: https://github.com/martinkozak/pipe-run
|
60
|
-
licenses:
|
56
|
+
licenses:
|
61
57
|
- MIT
|
62
58
|
post_install_message:
|
63
59
|
rdoc_options: []
|
64
|
-
|
65
|
-
require_paths:
|
60
|
+
require_paths:
|
66
61
|
- lib
|
67
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
63
|
none: false
|
69
|
-
requirements:
|
70
|
-
- -
|
71
|
-
- !ruby/object:Gem::Version
|
72
|
-
|
73
|
-
segments:
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
segments:
|
74
69
|
- 0
|
75
|
-
|
76
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
hash: -3085388963954565430
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
72
|
none: false
|
78
|
-
requirements:
|
79
|
-
- -
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version:
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
82
77
|
requirements: []
|
83
|
-
|
84
78
|
rubyforge_project:
|
85
|
-
rubygems_version: 1.
|
79
|
+
rubygems_version: 1.8.11
|
86
80
|
signing_key:
|
87
81
|
specification_version: 3
|
88
|
-
summary:
|
82
|
+
summary: Executes shell command and returns its outputs in single call. Both synchronous
|
83
|
+
and asynchronous (with EventMachine) executing is supported.
|
89
84
|
test_files: []
|
90
|
-
|