executioner 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -1
- data/README.rdoc +72 -0
- data/Rakefile +9 -0
- data/VERSION.yml +2 -2
- data/executioner.gemspec +6 -4
- data/lib/executioner.rb +39 -3
- data/test/executioner_test.rb +7 -0
- data/test/scripts/load_executioner_without_home.rb +3 -0
- metadata +19 -5
data/.gitignore
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
pkg
|
1
|
+
pkg
|
2
|
+
html
|
data/README.rdoc
CHANGED
@@ -0,0 +1,72 @@
|
|
1
|
+
= Executioner
|
2
|
+
|
3
|
+
Executioner is a module you can include in your classes to run binaries from
|
4
|
+
your Ruby code.
|
5
|
+
|
6
|
+
class Recording
|
7
|
+
include Executioner
|
8
|
+
executable :lame, :switch_stdout_and_stderr => true
|
9
|
+
|
10
|
+
def transcode
|
11
|
+
lame("--abr 128 -m s #{filename} #{filename_as_mp3}")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
==== Specifying a binary
|
16
|
+
|
17
|
+
By default Executioner looks in Executioner::SEARCH_PATHS for the binary.
|
18
|
+
|
19
|
+
executable :sh
|
20
|
+
|
21
|
+
If the binary is installed in a specific location you might want to
|
22
|
+
specify the entire path to the executable.
|
23
|
+
|
24
|
+
executable :import, :path => App.root_path + 'scripts/import'
|
25
|
+
|
26
|
+
And when you need to specify environment variables for the executable you
|
27
|
+
can do so as well.
|
28
|
+
|
29
|
+
executable :migrate, :env => { 'ENV' => 'PRODUCTION' }
|
30
|
+
|
31
|
+
If you need more elaborate rules to pick a specific path for a binary you
|
32
|
+
can specify a block that selects the right one.
|
33
|
+
|
34
|
+
executable :gcc, :select_if => lambda { |path|
|
35
|
+
File.ftype(path) != 'link' and !path.start_with?('/opt')
|
36
|
+
}
|
37
|
+
|
38
|
+
==== Reading output
|
39
|
+
|
40
|
+
Executioner reads either +stdout+ or +stderr+ and returns it from the call to
|
41
|
+
the binary. In the example presented above a call to +lame+ would return the
|
42
|
+
entire output to +stderr+ produced by Lame.
|
43
|
+
|
44
|
+
lame("--work") # => "lame: unrecognized option --work"
|
45
|
+
|
46
|
+
==== Exceptions
|
47
|
+
|
48
|
+
A call to a binary raises a +ProcessError+ when the output stream is empty and
|
49
|
+
there is stuff in the error stream. An +ExecutableNotFoundError+ is raised when
|
50
|
+
the executable can't be found in the path.
|
51
|
+
|
52
|
+
==== Queues
|
53
|
+
|
54
|
+
Executioner uses popen3 to run a subprocess with the executable. Starting a
|
55
|
+
process takes some time so if you're running lots of short commands you can
|
56
|
+
probably win some time by executing them from a queue.
|
57
|
+
|
58
|
+
executable :ppane, :use_queue => true
|
59
|
+
|
60
|
+
Now calling +ls+ will queue the command instead of executing it. You can execute
|
61
|
+
the entire queue by calling +execute_queued+.
|
62
|
+
|
63
|
+
ppane('add ~/Code/project')
|
64
|
+
ppane('register')
|
65
|
+
execute_queued
|
66
|
+
|
67
|
+
==== Logging
|
68
|
+
|
69
|
+
If you want to log everything Executioner does, you can assign a logger instance
|
70
|
+
to Executioner.logger.
|
71
|
+
|
72
|
+
Executioner.logger = Rails.logger
|
data/Rakefile
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rake/testtask'
|
2
|
+
require 'rake/rdoctask'
|
2
3
|
|
3
4
|
task :default => :test
|
4
5
|
|
@@ -7,6 +8,14 @@ Rake::TestTask.new do |t|
|
|
7
8
|
t.verbose = true
|
8
9
|
end
|
9
10
|
|
11
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
12
|
+
rdoc.title = 'Executioner'
|
13
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
14
|
+
rdoc.rdoc_files.include('README.rdoc')
|
15
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
16
|
+
end
|
17
|
+
|
18
|
+
|
10
19
|
begin
|
11
20
|
require 'jeweler'
|
12
21
|
Jeweler::Tasks.new do |s|
|
data/VERSION.yml
CHANGED
data/executioner.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{executioner}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Eloy Duran"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-04-21}
|
13
13
|
s.description = %q{Execute CLI utilities}
|
14
14
|
s.email = %q{eloy@fngtps.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,15 +26,17 @@ Gem::Specification.new do |s|
|
|
26
26
|
"executioner.gemspec",
|
27
27
|
"lib/executioner.rb",
|
28
28
|
"test/executioner_test.rb",
|
29
|
+
"test/scripts/load_executioner_without_home.rb",
|
29
30
|
"test/test_helper.rb"
|
30
31
|
]
|
31
32
|
s.homepage = %q{http://fingertips.github.com}
|
32
33
|
s.rdoc_options = ["--charset=UTF-8"]
|
33
34
|
s.require_paths = ["lib"]
|
34
|
-
s.rubygems_version = %q{1.3.
|
35
|
+
s.rubygems_version = %q{1.3.7}
|
35
36
|
s.summary = %q{Execute CLI utilities}
|
36
37
|
s.test_files = [
|
37
38
|
"test/executioner_test.rb",
|
39
|
+
"test/scripts/load_executioner_without_home.rb",
|
38
40
|
"test/test_helper.rb"
|
39
41
|
]
|
40
42
|
|
@@ -42,7 +44,7 @@ Gem::Specification.new do |s|
|
|
42
44
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
45
|
s.specification_version = 3
|
44
46
|
|
45
|
-
if Gem::Version.new(Gem::
|
47
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
46
48
|
else
|
47
49
|
end
|
48
50
|
else
|
data/lib/executioner.rb
CHANGED
@@ -5,9 +5,14 @@ module Executioner
|
|
5
5
|
class ProcessError < ExecutionerError; end
|
6
6
|
class ExecutableNotFoundError < ExecutionerError; end
|
7
7
|
|
8
|
-
SEARCH_PATHS = %
|
8
|
+
SEARCH_PATHS = %w(/bin /usr/bin /usr/local/bin /opt/homebrew/bin /opt/local/bin)
|
9
|
+
begin
|
10
|
+
SEARCH_PATHS.unshift(File.expand_path('~/bin'))
|
11
|
+
rescue ArgumentError
|
12
|
+
end
|
9
13
|
|
10
14
|
class << self
|
15
|
+
# Assign a logger if you want to log commands and options.
|
11
16
|
attr_accessor :logger
|
12
17
|
|
13
18
|
def included(klass)
|
@@ -55,6 +60,36 @@ module Executioner
|
|
55
60
|
end
|
56
61
|
|
57
62
|
module ClassMethods
|
63
|
+
# Register an executable with the class.
|
64
|
+
#
|
65
|
+
# executable :ppane
|
66
|
+
#
|
67
|
+
# You can configure the environment to use for each call to the executable.
|
68
|
+
#
|
69
|
+
# executable :rails, :env => { 'RAILS_ENV' => 'production' }
|
70
|
+
#
|
71
|
+
# In case the executable is outside regular paths, you can specify a
|
72
|
+
# particular path.
|
73
|
+
#
|
74
|
+
# executable :heap, :path => '/Developer/usr/bin/heap'
|
75
|
+
#
|
76
|
+
# The method you use to call the binary returns it's output in a a string
|
77
|
+
# sometimes the useful information is in +stderr+ instead of +stdout+.
|
78
|
+
# This happens sometimes in application which show progress. You can
|
79
|
+
# switch the output streams to capture +stderr+ instead of +stdout+.
|
80
|
+
#
|
81
|
+
# executable :lame, :switch_stdout_and_stderr => true
|
82
|
+
#
|
83
|
+
# If you have some particular need to select a specific path over another
|
84
|
+
# you can select it using a proc.
|
85
|
+
#
|
86
|
+
# executable :gcc, :select_if => { |e| File.ftype(e) != 'link' }
|
87
|
+
# executable :gcc, :select_if => { |e| e.start_with?('/Developer') }
|
88
|
+
#
|
89
|
+
# Both symbols and strings are allowed for names.
|
90
|
+
#
|
91
|
+
# executable 'aclocal-1.10'
|
92
|
+
#
|
58
93
|
def executable(executable, options={})
|
59
94
|
options[:switch_stdout_and_stderr] ||= false
|
60
95
|
options[:use_queue] ||= false
|
@@ -85,12 +120,13 @@ module Executioner
|
|
85
120
|
class_eval "def #{executable.gsub(/-/, '_')}(args, options = {}); #{body}; end", __FILE__, __LINE__
|
86
121
|
end
|
87
122
|
|
123
|
+
# Finds the first occurence of the specified executable in Executioner::SEARCH_PATHS
|
88
124
|
def find_executable(executable, advance_from = nil)
|
89
125
|
search_paths = Executioner::SEARCH_PATHS
|
90
126
|
search_paths = search_paths[(search_paths.index(advance_from) + 1)..-1] if advance_from
|
91
127
|
|
92
|
-
if executable_in_path = search_paths.find { |path| File.exist?
|
93
|
-
File.join
|
128
|
+
if executable_in_path = search_paths.find { |path| File.exist?(File.join(path, executable)) }
|
129
|
+
File.join(executable_in_path, executable)
|
94
130
|
end
|
95
131
|
end
|
96
132
|
module_function :find_executable
|
data/test/executioner_test.rb
CHANGED
@@ -195,4 +195,11 @@ describe "Executioner, class methods" do
|
|
195
195
|
@object.doesnotexistforsure 'right?'
|
196
196
|
}.should.raise Executioner::ExecutableNotFoundError
|
197
197
|
end
|
198
|
+
|
199
|
+
it "should work when there is no home directory in the environment" do
|
200
|
+
ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
|
201
|
+
lambda {
|
202
|
+
@object.execute("#{ruby} #{File.expand_path('../scripts/load_executioner_without_home.rb', __FILE__)}")
|
203
|
+
}.should.not.raise
|
204
|
+
end
|
198
205
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: executioner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 17
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Eloy Duran
|
@@ -9,7 +15,7 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2011-04-21 00:00:00 +02:00
|
13
19
|
default_executable:
|
14
20
|
dependencies: []
|
15
21
|
|
@@ -32,6 +38,7 @@ files:
|
|
32
38
|
- executioner.gemspec
|
33
39
|
- lib/executioner.rb
|
34
40
|
- test/executioner_test.rb
|
41
|
+
- test/scripts/load_executioner_without_home.rb
|
35
42
|
- test/test_helper.rb
|
36
43
|
has_rdoc: true
|
37
44
|
homepage: http://fingertips.github.com
|
@@ -43,24 +50,31 @@ rdoc_options:
|
|
43
50
|
require_paths:
|
44
51
|
- lib
|
45
52
|
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
46
54
|
requirements:
|
47
55
|
- - ">="
|
48
56
|
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
49
60
|
version: "0"
|
50
|
-
version:
|
51
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
52
63
|
requirements:
|
53
64
|
- - ">="
|
54
65
|
- !ruby/object:Gem::Version
|
66
|
+
hash: 3
|
67
|
+
segments:
|
68
|
+
- 0
|
55
69
|
version: "0"
|
56
|
-
version:
|
57
70
|
requirements: []
|
58
71
|
|
59
72
|
rubyforge_project:
|
60
|
-
rubygems_version: 1.3.
|
73
|
+
rubygems_version: 1.3.7
|
61
74
|
signing_key:
|
62
75
|
specification_version: 3
|
63
76
|
summary: Execute CLI utilities
|
64
77
|
test_files:
|
65
78
|
- test/executioner_test.rb
|
79
|
+
- test/scripts/load_executioner_without_home.rb
|
66
80
|
- test/test_helper.rb
|