sproc 0.5.0 → 0.7.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.
- checksums.yaml +4 -4
- data/lib/sproc.rb +1 -1
- data/lib/sproc/core.rb +2 -0
- data/lib/sproc/osinfo.rb +55 -0
- data/lib/sproc/version.rb +1 -1
- metadata +6 -7
- data/lib/sproc/reporting.rb +0 -196
- data/lib/sproc/utils.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9b6bbd295c0519d4a06d4b20768cc59c9e08cd940e4fa351eaeb85e32106010
|
4
|
+
data.tar.gz: 285071c6d925fb623c4815bf780f4c1954f6270c2fef2a277ef35e70e8e8775d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e9b1730da68e271acf7b6d4e79597af566524666ba59c56d70caa7e45901d850c4de5ba23040664347a7406b8695d149d61f6c17e1b2a96b9842c7307fcd9a7
|
7
|
+
data.tar.gz: eefd86ac13d27c867e6e2329c61fba7b7e4e850ba08daa0a82fb3c8a82e0f3b11663bcaf9b2a00704f57008c650d829fbaa82fadba56b726003ec504437911e3
|
data/lib/sproc.rb
CHANGED
data/lib/sproc/core.rb
CHANGED
@@ -336,6 +336,8 @@ module SProc
|
|
336
336
|
Thread.new do
|
337
337
|
until (raw_line = stream.gets).nil?
|
338
338
|
process_callback&.call(raw_line)
|
339
|
+
# log stream output directly in debug mode
|
340
|
+
SProc.logger&.debug { raw_line }
|
339
341
|
stream_cache << raw_line unless stream_cache.nil?
|
340
342
|
end
|
341
343
|
rescue IOError => e
|
data/lib/sproc/osinfo.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
|
3
|
+
# helper methods to find out os and execution environment
|
4
|
+
module SProc
|
5
|
+
module OSInfo
|
6
|
+
# the supported exec environments
|
7
|
+
module OS
|
8
|
+
WINDOWS = 0
|
9
|
+
LINUX = 1
|
10
|
+
MINGW = 2
|
11
|
+
CYGWIN = 3
|
12
|
+
OSX = 4
|
13
|
+
BSD = 5
|
14
|
+
UNKNOWN = 100
|
15
|
+
end
|
16
|
+
|
17
|
+
# returns the current execution environment
|
18
|
+
def self.os_context
|
19
|
+
case RbConfig::CONFIG['host_os']
|
20
|
+
when /mswin/ then OS::WINDOWS
|
21
|
+
when /mingw/ then OS::MINGW
|
22
|
+
when /cygwin/ then OS::CYGWIN
|
23
|
+
when /darwin/ then OS::OSX
|
24
|
+
when /linux/ then OS::LINUX
|
25
|
+
when /bsd/ then OS::BSD
|
26
|
+
else OS::UNKNOWN
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# return the current underlying operating system
|
31
|
+
def self.host_os
|
32
|
+
if [OS::WINDOWS, OS::MINGW, OS::CYGWIN].include?(os_context)
|
33
|
+
OS::WINDOWS
|
34
|
+
else
|
35
|
+
os_context
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def on_windows?
|
40
|
+
OSInfo.host_os == OS::WINDOWS
|
41
|
+
end
|
42
|
+
|
43
|
+
def on_linux?
|
44
|
+
OSInfo.os_context == OS::LINUX
|
45
|
+
end
|
46
|
+
|
47
|
+
def on_bsd?
|
48
|
+
OSInfo.os_context == OS::BSD
|
49
|
+
end
|
50
|
+
|
51
|
+
def on_osx?
|
52
|
+
OSInfo.os_context == OS::OSX
|
53
|
+
end
|
54
|
+
end
|
55
|
+
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.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anders Rillbert
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -43,8 +43,7 @@ files:
|
|
43
43
|
- bin/setup
|
44
44
|
- lib/sproc.rb
|
45
45
|
- lib/sproc/core.rb
|
46
|
-
- lib/sproc/
|
47
|
-
- lib/sproc/utils.rb
|
46
|
+
- lib/sproc/osinfo.rb
|
48
47
|
- lib/sproc/version.rb
|
49
48
|
- sproc.gemspec
|
50
49
|
homepage: https://github.com/rillbert/sproc
|
@@ -55,7 +54,7 @@ metadata:
|
|
55
54
|
homepage_uri: https://github.com/rillbert/sproc
|
56
55
|
source_code_uri: https://github.com/rillbert/sproc
|
57
56
|
changelog_uri: https://github.com/rillbert/sproc
|
58
|
-
post_install_message:
|
57
|
+
post_install_message:
|
59
58
|
rdoc_options: []
|
60
59
|
require_paths:
|
61
60
|
- lib
|
@@ -71,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
70
|
version: '0'
|
72
71
|
requirements: []
|
73
72
|
rubygems_version: 3.1.4
|
74
|
-
signing_key:
|
73
|
+
signing_key:
|
75
74
|
specification_version: 4
|
76
75
|
summary: Spawn commands as asynch/synch subprocesses.
|
77
76
|
test_files: []
|
data/lib/sproc/reporting.rb
DELETED
@@ -1,196 +0,0 @@
|
|
1
|
-
require_relative 'core'
|
2
|
-
|
3
|
-
# This module is written to provide sub-process
|
4
|
-
# execution with some human readable logging of process start/stop/errors
|
5
|
-
#
|
6
|
-
# It wraps SProc instances and execution with calls to logging methods
|
7
|
-
# that tries to make the resulting log user friendly
|
8
|
-
module SProc
|
9
|
-
module Reporting
|
10
|
-
class << self
|
11
|
-
attr_accessor :logger
|
12
|
-
end
|
13
|
-
|
14
|
-
def logger
|
15
|
-
Reporting.logger
|
16
|
-
end
|
17
|
-
|
18
|
-
# Run a process synchronuously via the native shell and log
|
19
|
-
# output suitable for a build log
|
20
|
-
#
|
21
|
-
# @param cmd_name a String containing a descriptive
|
22
|
-
# name for what the process will do.
|
23
|
-
# @param cmd, args, opts see SProc.exec_sync
|
24
|
-
#
|
25
|
-
# @return the SProc instance containing the completed process
|
26
|
-
def report_sync(cmd_name, cmd, *args, **opts)
|
27
|
-
p = create_proc_and_log(cmd_name,
|
28
|
-
ShellType::NONE, :exec_sync,
|
29
|
-
cmd, args, opts)
|
30
|
-
report_completed(p)
|
31
|
-
p
|
32
|
-
end
|
33
|
-
|
34
|
-
# Run a process asynchronuously via the native shell and log
|
35
|
-
# output suitable for a build log
|
36
|
-
#
|
37
|
-
# @param cmd_name a String containing a descriptive
|
38
|
-
# name for what the process will do.
|
39
|
-
# @param cmd, args, opts see SProc.exec_sync
|
40
|
-
#
|
41
|
-
# @return the created SProc instance
|
42
|
-
def report_async(cmd_name, cmd, *args, **opts)
|
43
|
-
create_proc_and_log(cmd_name,
|
44
|
-
ShellType::NONE, :exec_async,
|
45
|
-
cmd, args, opts)
|
46
|
-
end
|
47
|
-
|
48
|
-
# Run a process asynchronuously via the Bash shell and log
|
49
|
-
# output suitable for a build log
|
50
|
-
#
|
51
|
-
# @param cmd_name a String containing a descriptive
|
52
|
-
# name for what the process will do.
|
53
|
-
# @param cmd, args, opts see SProc.exec_sync
|
54
|
-
#
|
55
|
-
# @return the created SProc instance
|
56
|
-
def report_async_within_bash(cmd_name, cmd, *args, **opts)
|
57
|
-
create_proc_and_log(cmd_name,
|
58
|
-
ShellType::BASH, :exec_async,
|
59
|
-
cmd, args, opts)
|
60
|
-
end
|
61
|
-
|
62
|
-
# Log output from a completed/aborted process
|
63
|
-
#
|
64
|
-
# @param process the SProc instance that has run
|
65
|
-
# @return true/false corresponding to process success
|
66
|
-
def report_completed(process)
|
67
|
-
friendly_name = if @log_friendly_name_map&.key?(process)
|
68
|
-
"#{@log_friendly_name_map[process]}"
|
69
|
-
else
|
70
|
-
'Process'
|
71
|
-
end
|
72
|
-
started_ok = true
|
73
|
-
case process.execution_state
|
74
|
-
when ExecutionState::COMPLETED
|
75
|
-
process.exit_zero? && log_completed_ok(friendly_name, process.task_info)
|
76
|
-
!process.exit_zero? && log_completed_err(friendly_name, process.task_info)
|
77
|
-
when ExecutionState::ABORTED
|
78
|
-
log_aborted(friendly_name, process.task_info)
|
79
|
-
started_ok = false
|
80
|
-
when ExecutionState::FAILED_TO_START
|
81
|
-
log_failed_start(friendly_name, process.task_info)
|
82
|
-
started_ok = false
|
83
|
-
else
|
84
|
-
log_unexpected(friendly_name, process.task_info)
|
85
|
-
end
|
86
|
-
started_ok && process.exit_zero?
|
87
|
-
end
|
88
|
-
|
89
|
-
private
|
90
|
-
|
91
|
-
def create_proc_and_log(cmd_name, type, method, cmd, args, opts)
|
92
|
-
log_start(cmd_name, type, method, cmd, args, **opts)
|
93
|
-
p = SProc.new(type: type).send(method, cmd, args, **opts)
|
94
|
-
@log_friendly_name_map ||= {}
|
95
|
-
@log_friendly_name_map[p] = cmd_name
|
96
|
-
p
|
97
|
-
end
|
98
|
-
|
99
|
-
def log_method_result_ok(friendly_name, delta)
|
100
|
-
logger.info do
|
101
|
-
"#{friendly_name} completed successfully after #{delta.round(3)}s"
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def log_method_result_error(friendly_name_method, delta, exc)
|
106
|
-
logger.error do
|
107
|
-
"#{friendly_name_method} aborted by #{exc.class} after #{delta.round(3)}s\n"\
|
108
|
-
"Exception info: #{exc.message}"
|
109
|
-
end
|
110
|
-
|
111
|
-
logger.debug do
|
112
|
-
exc.backtrace.to_s
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
def log_start(cmd_name, type, method, cmd, *args, **opts)
|
117
|
-
logger.info do
|
118
|
-
async_str = method == :exec_async ? 'asynchronuously' : 'synchronuously'
|
119
|
-
type_str = type == ShellType::NONE ? 'without shell' : 'within the bash shell'
|
120
|
-
"'#{cmd_name}' executing #{async_str} #{type_str}..."
|
121
|
-
end
|
122
|
-
logger.debug do
|
123
|
-
msg = String.new("Starting #{cmd}")
|
124
|
-
msg << " with args: #{args.flatten.inspect}" unless args.nil? || args.empty?
|
125
|
-
msg << " and opts: #{opts.inspect}" unless opts.nil? || opts.empty?
|
126
|
-
msg
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def log_one_dll(regex, cmd_str, time)
|
131
|
-
m = regex.match(cmd_str)
|
132
|
-
s = m.nil? ? cmd_str : m[1]
|
133
|
-
max = 45
|
134
|
-
s = s.length > max ? s.slice(0..max - 1) : s.ljust(max)
|
135
|
-
logger.info { "#{s} took #{time.round(3)}s." }
|
136
|
-
end
|
137
|
-
|
138
|
-
def log_aborted(friendly_name, p_info)
|
139
|
-
logger.error do
|
140
|
-
"'#{friendly_name}' aborted!\n"\
|
141
|
-
"When running: #{p_info[:cmd_str]}\n"\
|
142
|
-
"#{merge_proc_output(p_info)}"\
|
143
|
-
"#{p_info[:process_status] unless p_info[:process_status].nil?}"
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
def log_failed_start(friendly_name, p_info)
|
148
|
-
logger.error do
|
149
|
-
"'#{friendly_name}' not run!\n"\
|
150
|
-
"Could not start process using: #{p_info[:cmd_str]}\n"\
|
151
|
-
"#{merge_proc_output(p_info)}"
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def log_completed_ok(friendly_name, p_info)
|
156
|
-
logger.info do
|
157
|
-
"'#{friendly_name}' completed successfully after #{p_info[:wall_time].round(3)}s"
|
158
|
-
end
|
159
|
-
logger.debug do
|
160
|
-
"Cmd: #{p_info[:cmd_str]}"
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
def log_completed_err(friendly_name, p_info)
|
165
|
-
logger.error do
|
166
|
-
"'#{friendly_name}' completed with exit code "\
|
167
|
-
"#{p_info[:process_status].exitstatus}\n"\
|
168
|
-
"When running: #{p_info[:cmd_str]}\n"\
|
169
|
-
"after #{p_info[:wall_time].round(3)}s\n"\
|
170
|
-
"#{merge_proc_output(p_info)}"
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
def log_unexpected(friendly_name, p_info)
|
175
|
-
logger.error do
|
176
|
-
"'#{friendly_name}' caused unexpected error!"\
|
177
|
-
' Trying to display info on a running process'\
|
178
|
-
"(#{p_info[:cmd_str]})"
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
# @return String with sections for each non-empty output stream
|
183
|
-
# and exception messages
|
184
|
-
def merge_proc_output(p_info)
|
185
|
-
inf_str = %i[stdout stderr].collect do |sym|
|
186
|
-
next('') if p_info[sym].empty?
|
187
|
-
|
188
|
-
"--- #{sym} ---\n#{p_info[sym]}"
|
189
|
-
end.join("\n")
|
190
|
-
|
191
|
-
exc = p_info[:exception]
|
192
|
-
inf_str << "--- exception ---\n#{exc}\n" unless exc.nil?
|
193
|
-
inf_str
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
data/lib/sproc/utils.rb
DELETED
@@ -1,53 +0,0 @@
|
|
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
|