sproc 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/README.adoc +1 -1
- data/lib/sproc/core.rb +35 -19
- data/lib/sproc/utils.rb +53 -0
- data/lib/sproc/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b21c852197676569f95bf84f37a1e2d070a06ee5fb1bbe1b627e2eb9f83500da
|
|
4
|
+
data.tar.gz: 3f8fe794b2afcb54d50af93e774091ef1fd72e27c221eb2f38a82686ec214f89
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e76140b5a74de9977e60a657ce8c40ad5cf070f3b8c856f954d87ecda0b2cc61a601016b8c8beafd6dd5840dc6dd4cac81eb44b85a3c811fbb38612ea97b0236
|
|
7
|
+
data.tar.gz: e8999dfdf2a0aa3f577d9c3ed49184989595ac545088b506befcea989782f502c8776fbb851746d696679a2dd84453ef8ebce732e69c53346283c01e024e9fd6
|
data/README.adoc
CHANGED
|
@@ -41,4 +41,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
41
41
|
== Code of Conduct
|
|
42
42
|
|
|
43
43
|
Everyone interacting in the Sproc project's codebases, issue trackers, chat rooms and mailing lists is expected
|
|
44
|
-
to follow the [code of conduct](https://github.com/
|
|
44
|
+
to follow the [code of conduct](https://github.com/rillbert/sproc/blob/master/CODE_OF_CONDUCT.adoc).
|
data/lib/sproc/core.rb
CHANGED
|
@@ -4,8 +4,17 @@ require 'shellwords'
|
|
|
4
4
|
require 'open3'
|
|
5
5
|
|
|
6
6
|
module SProc
|
|
7
|
+
# Defines the shell under which to invoke the sub-process
|
|
7
8
|
module ShellType
|
|
8
|
-
SHELL_TYPES = [
|
|
9
|
+
SHELL_TYPES = [
|
|
10
|
+
# Use the default shell for the platform we're on.
|
|
11
|
+
# - For Windows, it seems to be the 'cmd prompt'
|
|
12
|
+
# - For current ubuntu, it seems to be 'dash'
|
|
13
|
+
NATIVE = 0,
|
|
14
|
+
# Will create a 'bash' instance and run the subprocess
|
|
15
|
+
# within that instance.
|
|
16
|
+
BASH = 1
|
|
17
|
+
].freeze
|
|
9
18
|
end
|
|
10
19
|
|
|
11
20
|
# The possible states of this subprocess
|
|
@@ -62,20 +71,6 @@ module SProc
|
|
|
62
71
|
@execution_thread = nil
|
|
63
72
|
end
|
|
64
73
|
|
|
65
|
-
# @return the TaskInfo representing this SubProcess, nil if
|
|
66
|
-
# process has not started
|
|
67
|
-
def task_info
|
|
68
|
-
@runner.task_info
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
# check if this process has completed with exit code 0
|
|
72
|
-
# (success) or not
|
|
73
|
-
def exit_zero?
|
|
74
|
-
return false unless execution_state == ExecutionState::COMPLETED
|
|
75
|
-
|
|
76
|
-
task_info[:process_status].exitstatus.zero?
|
|
77
|
-
end
|
|
78
|
-
|
|
79
74
|
# Return the execution state of this SubProcess. Note that it is not
|
|
80
75
|
# identical with the life-cycle of the underlying ProcessStatus object
|
|
81
76
|
# @return current ExecutionState
|
|
@@ -105,7 +100,10 @@ module SProc
|
|
|
105
100
|
return ExecutionState::COMPLETED if status.exited?
|
|
106
101
|
|
|
107
102
|
# We don't currently handle a process that has been stopped...
|
|
108
|
-
|
|
103
|
+
raise NotImplementedError("Unhandled process 'stopped' status!") if status.stopped?
|
|
104
|
+
|
|
105
|
+
# We should never come here
|
|
106
|
+
raise RuntimeError("Unhandled process status: #{status.inspect}")
|
|
109
107
|
end
|
|
110
108
|
|
|
111
109
|
# Start the process non-blocking. Use one of the wait... methods
|
|
@@ -122,6 +120,14 @@ module SProc
|
|
|
122
120
|
exec(false, cmd, *args, **opts)
|
|
123
121
|
end
|
|
124
122
|
|
|
123
|
+
# check if this process has completed with exit code 0
|
|
124
|
+
# (success) or not
|
|
125
|
+
def exit_zero?
|
|
126
|
+
return false unless execution_state == ExecutionState::COMPLETED
|
|
127
|
+
|
|
128
|
+
task_info[:process_status].exitstatus.zero?
|
|
129
|
+
end
|
|
130
|
+
|
|
125
131
|
# Block caller until this subprocess has completed or aborted
|
|
126
132
|
# @return the TaskInfo struct of the completed process
|
|
127
133
|
def wait_on_completion
|
|
@@ -195,6 +201,12 @@ module SProc
|
|
|
195
201
|
all_proc
|
|
196
202
|
end
|
|
197
203
|
|
|
204
|
+
# @return the TaskInfo representing this SubProcess, nil if
|
|
205
|
+
# process has not started
|
|
206
|
+
def task_info
|
|
207
|
+
@runner.task_info
|
|
208
|
+
end
|
|
209
|
+
|
|
198
210
|
# return processes that are no longer running
|
|
199
211
|
def self.get_finished(running_proc)
|
|
200
212
|
running_proc.select do |p|
|
|
@@ -207,6 +219,10 @@ module SProc
|
|
|
207
219
|
private
|
|
208
220
|
|
|
209
221
|
def exec(synch, cmd, *args, **opts)
|
|
222
|
+
raise RuntimeError,"Subprocess already running!" unless @execution_thread.nil? || !@execution_thread.alive?
|
|
223
|
+
|
|
224
|
+
# kick-off a fresh task runner and execution thread
|
|
225
|
+
@runner = TaskRunner.new(@run_opts)
|
|
210
226
|
@execution_thread = Thread.new do
|
|
211
227
|
@runner.execute(cmd, *args, **opts)
|
|
212
228
|
end
|
|
@@ -258,7 +274,8 @@ module SProc
|
|
|
258
274
|
end
|
|
259
275
|
SProc.logger&.debug { "Start: #{task_info[:cmd_str]}" }
|
|
260
276
|
Open3.popen3(*args) do |stdin, stdout, stderr, thread|
|
|
261
|
-
|
|
277
|
+
@task_info[:popen_thread] = thread
|
|
278
|
+
threads = do_while_process_running(stdin, stdout, stderr)
|
|
262
279
|
@task_info[:process_status] = thread.value
|
|
263
280
|
threads.each(&:join)
|
|
264
281
|
end
|
|
@@ -277,8 +294,7 @@ module SProc
|
|
|
277
294
|
[@task_info[:cmd_str], opts]
|
|
278
295
|
end
|
|
279
296
|
|
|
280
|
-
def do_while_process_running(_stdin, stdout, stderr
|
|
281
|
-
@task_info[:popen_thread] = thread
|
|
297
|
+
def do_while_process_running(_stdin, stdout, stderr)
|
|
282
298
|
th1 = process_output_stream(stdout,
|
|
283
299
|
@task_info[:stdout], @opts[:stdout_callback])
|
|
284
300
|
th2 = process_output_stream(stderr,
|
data/lib/sproc/utils.rb
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require 'rbconfig'
|
|
2
|
+
|
|
3
|
+
# utility to find out info about our execution environment
|
|
4
|
+
module OSInfo
|
|
5
|
+
# the supported exec environments
|
|
6
|
+
module OS
|
|
7
|
+
WINDOWS = 0
|
|
8
|
+
LINUX = 1
|
|
9
|
+
MINGW = 2
|
|
10
|
+
CYGWIN = 3
|
|
11
|
+
OSX = 4
|
|
12
|
+
BSD = 5
|
|
13
|
+
UNKNOWN = 100
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# returns the current execution environment
|
|
17
|
+
def self.os_context
|
|
18
|
+
case RbConfig::CONFIG['host_os']
|
|
19
|
+
when /mswin/ then OS::WINDOWS
|
|
20
|
+
when /mingw/ then OS::MINGW
|
|
21
|
+
when /cygwin/ then OS::CYGWIN
|
|
22
|
+
when /darwin/ then OS::OSX
|
|
23
|
+
when /linux/ then OS::LINUX
|
|
24
|
+
when /bsd/ then OS::BSD
|
|
25
|
+
else OS::UNKNOWN
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# return the current underlying operating system
|
|
30
|
+
def self.host_os
|
|
31
|
+
if [OS::WINDOWS, OS::MINGW, OS::CYGWIN].include?(os_context)
|
|
32
|
+
OS::WINDOWS
|
|
33
|
+
else
|
|
34
|
+
os_context
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def on_windows?
|
|
39
|
+
host_os == OS::WINDOWS
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def on_linux?
|
|
43
|
+
os_context == OS::LINUX
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def on_bsd?
|
|
47
|
+
os_context == OS::BSD
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def on_osx?
|
|
51
|
+
os_context == OS::OSX
|
|
52
|
+
end
|
|
53
|
+
end
|
data/lib/sproc/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sproc
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Anders Rillbert
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-02-
|
|
11
|
+
date: 2021-02-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|
|
@@ -42,6 +42,7 @@ files:
|
|
|
42
42
|
- bin/setup
|
|
43
43
|
- lib/sproc.rb
|
|
44
44
|
- lib/sproc/core.rb
|
|
45
|
+
- lib/sproc/utils.rb
|
|
45
46
|
- lib/sproc/version.rb
|
|
46
47
|
- sproc.gemspec
|
|
47
48
|
homepage: https://github.com/rillbert/sproc
|