runnable 0.2.2 → 0.2.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.
- data/VERSION +1 -1
- data/lib/runnable.rb +50 -16
- data/runnable.gemspec +7 -7
- metadata +18 -16
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/lib/runnable.rb
CHANGED
@@ -40,7 +40,13 @@ class Runnable
|
|
40
40
|
attr_reader :group
|
41
41
|
# Directory where process was called from.
|
42
42
|
attr_reader :pwd
|
43
|
-
|
43
|
+
|
44
|
+
# Input file
|
45
|
+
attr_accessor :input
|
46
|
+
|
47
|
+
# Set the output file
|
48
|
+
attr_accessor :output
|
49
|
+
|
44
50
|
# Metaprogramming part of the class
|
45
51
|
|
46
52
|
# Define the parameter style to be used.
|
@@ -96,10 +102,16 @@ class Runnable
|
|
96
102
|
end
|
97
103
|
|
98
104
|
# Store input options
|
99
|
-
@input =
|
105
|
+
@input = String.new
|
100
106
|
|
101
107
|
# Store output options
|
102
|
-
@output =
|
108
|
+
@output = String.new
|
109
|
+
|
110
|
+
# Standar Outputs
|
111
|
+
@std_output = {
|
112
|
+
:out => "",
|
113
|
+
:err => ""
|
114
|
+
}
|
103
115
|
|
104
116
|
# @todo: checks that command is in the PATH
|
105
117
|
# ...
|
@@ -133,10 +145,10 @@ class Runnable
|
|
133
145
|
# Set up the command line
|
134
146
|
command = []
|
135
147
|
command << @command
|
136
|
-
command << @input
|
148
|
+
command << @input
|
137
149
|
command << @options
|
138
150
|
command << @command_line_interface.parse
|
139
|
-
command << @output
|
151
|
+
command << @output
|
140
152
|
command = command.join( " " )
|
141
153
|
|
142
154
|
@pid = Process.spawn( command, { :out => out_wr, :err => err_wr } )
|
@@ -230,10 +242,24 @@ class Runnable
|
|
230
242
|
@run_thread.join if @run_thread.alive?
|
231
243
|
end
|
232
244
|
|
245
|
+
# Check if prcess is running on the system.
|
246
|
+
# @return [Bool] True if process is running, false if it is not.
|
233
247
|
def running?
|
234
248
|
Dir.exists?( "/proc/#{@pid}")
|
235
249
|
end
|
236
250
|
|
251
|
+
# Standar output of command
|
252
|
+
# @return [String] Standar output
|
253
|
+
def std_out
|
254
|
+
@std_output[:out]
|
255
|
+
end
|
256
|
+
|
257
|
+
# Standar error output of the command
|
258
|
+
# @return [String] Standar error output
|
259
|
+
def std_err
|
260
|
+
@std_output[:err]
|
261
|
+
end
|
262
|
+
|
237
263
|
# Calculate the estimated memory usage in Kb.
|
238
264
|
# @return [Number] Estimated mem usage in Kb.
|
239
265
|
def mem
|
@@ -275,18 +301,22 @@ class Runnable
|
|
275
301
|
|
276
302
|
end
|
277
303
|
|
278
|
-
#
|
279
|
-
# @param [String]
|
280
|
-
# @
|
281
|
-
|
282
|
-
|
283
|
-
|
304
|
+
# Estimated bandwidth in kb/s.
|
305
|
+
# @param [String] iface Interface to be scaned.
|
306
|
+
# @param [Number] sample_time Time passed between samples in seconds.
|
307
|
+
# The longest lapse the more accurate stimation.
|
308
|
+
# @return [Number] The estimated bandwidth used.
|
309
|
+
def bandwidth( iface, sample_lapse = 0.1 )
|
310
|
+
file = "/proc/#{@pid}/net/dev"
|
311
|
+
File.open( file ).read =~ /#{iface}:\s+(\d+)\s+/
|
312
|
+
init = $1.to_i
|
313
|
+
|
314
|
+
sleep sample_lapse
|
284
315
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
@output << param
|
316
|
+
File.open( file ).read =~ /#{iface}:\s+(\d+)\s+/
|
317
|
+
finish = $1.to_i
|
318
|
+
|
319
|
+
(finish - init)*(1/sample_lapse)/1024
|
290
320
|
end
|
291
321
|
|
292
322
|
# Convert undefined methods (ruby-like syntax) into parameters
|
@@ -407,7 +437,11 @@ class Runnable
|
|
407
437
|
@output_threads << Thread.new do
|
408
438
|
pipes[0].close
|
409
439
|
|
440
|
+
@std_output[output_name] = ""
|
441
|
+
|
410
442
|
pipes[1].each_line do |line|
|
443
|
+
@std_output[output_name] << line
|
444
|
+
|
411
445
|
File.open("#{@log_path}#{@command}_#{@pid}.log", "a") do |log_file|
|
412
446
|
log_file.puts( "[#{Time.new.inspect} || [STD#{output_name.to_s.upcase} || [#{@pid}]] #{line}" )
|
413
447
|
end
|
data/runnable.gemspec
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{runnable}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [
|
12
|
-
s.date = %q{2011-08-
|
11
|
+
s.authors = ["Rafael García", "Luis Ciudad", "Pedro Navajas", "Javier Aranda"]
|
12
|
+
s.date = %q{2011-08-26}
|
13
13
|
s.description = %q{Convert a executable command in a Ruby-like class you are able to start, define params and send signals (like kill, or stop)}
|
14
|
-
s.email = [
|
14
|
+
s.email = ["rgarcia@nosolosoftware.biz", "lciudad@nosolosoftware.biz", "pnavajas@nosolosoftware.biz", "jaranda@nosolosoftware.biz"]
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"README.markdown"
|
17
17
|
]
|
@@ -26,9 +26,9 @@ Gem::Specification.new do |s|
|
|
26
26
|
"runnable.gemspec"
|
27
27
|
]
|
28
28
|
s.homepage = %q{http://github.com/nosolosoftware/runnable}
|
29
|
-
s.licenses = [
|
30
|
-
s.require_paths = [
|
31
|
-
s.rubygems_version = %q{1.
|
29
|
+
s.licenses = ["GPL-3"]
|
30
|
+
s.require_paths = ["lib"]
|
31
|
+
s.rubygems_version = %q{1.6.2}
|
32
32
|
s.summary = %q{A Ruby gem for execute and control system commands}
|
33
33
|
|
34
34
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: runnable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,11 +12,12 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2011-08-
|
15
|
+
date: 2011-08-26 00:00:00.000000000 +02:00
|
16
|
+
default_executable:
|
16
17
|
dependencies:
|
17
18
|
- !ruby/object:Gem::Dependency
|
18
19
|
name: rake
|
19
|
-
requirement: &
|
20
|
+
requirement: &24798400 !ruby/object:Gem::Requirement
|
20
21
|
none: false
|
21
22
|
requirements:
|
22
23
|
- - ! '>='
|
@@ -24,10 +25,10 @@ dependencies:
|
|
24
25
|
version: 0.8.7
|
25
26
|
type: :development
|
26
27
|
prerelease: false
|
27
|
-
version_requirements: *
|
28
|
+
version_requirements: *24798400
|
28
29
|
- !ruby/object:Gem::Dependency
|
29
30
|
name: yard
|
30
|
-
requirement: &
|
31
|
+
requirement: &24797260 !ruby/object:Gem::Requirement
|
31
32
|
none: false
|
32
33
|
requirements:
|
33
34
|
- - ! '>='
|
@@ -35,10 +36,10 @@ dependencies:
|
|
35
36
|
version: 0.6.8
|
36
37
|
type: :development
|
37
38
|
prerelease: false
|
38
|
-
version_requirements: *
|
39
|
+
version_requirements: *24797260
|
39
40
|
- !ruby/object:Gem::Dependency
|
40
41
|
name: rspec
|
41
|
-
requirement: &
|
42
|
+
requirement: &24796600 !ruby/object:Gem::Requirement
|
42
43
|
none: false
|
43
44
|
requirements:
|
44
45
|
- - ! '>='
|
@@ -46,10 +47,10 @@ dependencies:
|
|
46
47
|
version: 2.5.0
|
47
48
|
type: :development
|
48
49
|
prerelease: false
|
49
|
-
version_requirements: *
|
50
|
+
version_requirements: *24796600
|
50
51
|
- !ruby/object:Gem::Dependency
|
51
52
|
name: cucumber
|
52
|
-
requirement: &
|
53
|
+
requirement: &24795620 !ruby/object:Gem::Requirement
|
53
54
|
none: false
|
54
55
|
requirements:
|
55
56
|
- - ! '>='
|
@@ -57,10 +58,10 @@ dependencies:
|
|
57
58
|
version: 0.10.2
|
58
59
|
type: :development
|
59
60
|
prerelease: false
|
60
|
-
version_requirements: *
|
61
|
+
version_requirements: *24795620
|
61
62
|
- !ruby/object:Gem::Dependency
|
62
63
|
name: jeweler
|
63
|
-
requirement: &
|
64
|
+
requirement: &24794100 !ruby/object:Gem::Requirement
|
64
65
|
none: false
|
65
66
|
requirements:
|
66
67
|
- - ! '>='
|
@@ -68,10 +69,10 @@ dependencies:
|
|
68
69
|
version: 1.6.0
|
69
70
|
type: :development
|
70
71
|
prerelease: false
|
71
|
-
version_requirements: *
|
72
|
+
version_requirements: *24794100
|
72
73
|
- !ruby/object:Gem::Dependency
|
73
74
|
name: bluecloth
|
74
|
-
requirement: &
|
75
|
+
requirement: &24792600 !ruby/object:Gem::Requirement
|
75
76
|
none: false
|
76
77
|
requirements:
|
77
78
|
- - ! '>='
|
@@ -79,7 +80,7 @@ dependencies:
|
|
79
80
|
version: 2.1.0
|
80
81
|
type: :development
|
81
82
|
prerelease: false
|
82
|
-
version_requirements: *
|
83
|
+
version_requirements: *24792600
|
83
84
|
description: Convert a executable command in a Ruby-like class you are able to start,
|
84
85
|
define params and send signals (like kill, or stop)
|
85
86
|
email:
|
@@ -100,6 +101,7 @@ files:
|
|
100
101
|
- lib/runnable/extended.rb
|
101
102
|
- lib/runnable/gnu.rb
|
102
103
|
- runnable.gemspec
|
104
|
+
has_rdoc: true
|
103
105
|
homepage: http://github.com/nosolosoftware/runnable
|
104
106
|
licenses:
|
105
107
|
- GPL-3
|
@@ -115,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
117
|
version: '0'
|
116
118
|
segments:
|
117
119
|
- 0
|
118
|
-
hash:
|
120
|
+
hash: 1440204115093721090
|
119
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
122
|
none: false
|
121
123
|
requirements:
|
@@ -124,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
126
|
version: '0'
|
125
127
|
requirements: []
|
126
128
|
rubyforge_project:
|
127
|
-
rubygems_version: 1.
|
129
|
+
rubygems_version: 1.6.2
|
128
130
|
signing_key:
|
129
131
|
specification_version: 3
|
130
132
|
summary: A Ruby gem for execute and control system commands
|