utils 0.81.0 → 0.83.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/bin/code_comment +1 -1
- data/bin/irb_client +68 -0
- data/bin/probe +3 -2
- data/lib/utils/config_file.rb +11 -0
- data/lib/utils/irb/irb_server.rb +219 -0
- data/lib/utils/irb.rb +89 -0
- data/lib/utils/probe/probe_client.rb +98 -0
- data/lib/utils/{probe_server.rb → probe/probe_server.rb} +2 -262
- data/lib/utils/probe/process_job.rb +130 -0
- data/lib/utils/probe/server_handling.rb +32 -0
- data/lib/utils/probe.rb +23 -0
- data/lib/utils/version.rb +1 -1
- data/lib/utils.rb +1 -1
- data/utils.gemspec +6 -6
- metadata +17 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: feae6a2fca0157be211250ec430f5f21a1c155653ace2c13b40ac20b281eca09
|
|
4
|
+
data.tar.gz: 9a5e7c3a34a1ead5023dde6b152d6d94a2f596a75405615fe109a931807a8b29
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2038fbdb9eb1822f8b095fba1620f90ddfdd71220496fd8c25a8b4a51d50c535a77fde0f6b4433bd0eca2101753cd54c4dc266644f7235736333b8f1e6f43201
|
|
7
|
+
data.tar.gz: 9cdff942de8097052d296f06bdc8e5f7a75572a8ccd2c63831a37248a6b9d1f0f99f0d92c400b1888e3007eb40816c2b1ee2e0a37ea0852b6e10de3bd1d16b28
|
data/bin/code_comment
CHANGED
|
@@ -184,7 +184,7 @@ end
|
|
|
184
184
|
filename_linenumber = ARGV.shift or fail "require file_name as second argument"
|
|
185
185
|
$config = Utils::ConfigFile.new
|
|
186
186
|
$config.configure_from_paths
|
|
187
|
-
$config_dir
|
|
187
|
+
$config_dir = Utils::ConfigDir.new('code_comment', env_var: 'XDG_CONFIG_HOME')
|
|
188
188
|
base_url = ENV['OLLAMA_URL'] || 'http://%s' % ENV.fetch('OLLAMA_HOST')
|
|
189
189
|
model = ENV.fetch('OLLAMA_MODEL', 'llama3.1')
|
|
190
190
|
construct, construct_type = fetch_construct(filename_linenumber)
|
data/bin/irb_client
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'utils/irb'
|
|
4
|
+
include Utils::IRB
|
|
5
|
+
|
|
6
|
+
def usage
|
|
7
|
+
<<~EOT
|
|
8
|
+
Usage: #{File.basename($0)} ACTION
|
|
9
|
+
|
|
10
|
+
Actions:
|
|
11
|
+
store_snippet Store code snippet from STDIN as current snippet
|
|
12
|
+
retrieve_current_snippet Show the currently stored snippet
|
|
13
|
+
eval_current_snippet Evaluate the currently stored snippet
|
|
14
|
+
execute_current_snippet Execute the currently stored snippet (no output)
|
|
15
|
+
execute_snippet Execute code snippet from STDIN (no output)
|
|
16
|
+
eval_snippet Evaluate code snippet from STDIN and print result
|
|
17
|
+
eval_lines Evaluate code lines from STDIND and print comment results
|
|
18
|
+
stop_server Stop the IRB server
|
|
19
|
+
|
|
20
|
+
Examples:
|
|
21
|
+
# Evaluate code and get result
|
|
22
|
+
echo '2 + 2' | #{File.basename($0)} eval_snippet
|
|
23
|
+
# => 4
|
|
24
|
+
|
|
25
|
+
# Execute code (no output)
|
|
26
|
+
echo 'puts "hello"' | #{File.basename($0)} execute_snippet
|
|
27
|
+
|
|
28
|
+
# Store code snippet
|
|
29
|
+
echo 'def hello; "world"; end' | #{File.basename($0)} store_snippet
|
|
30
|
+
|
|
31
|
+
# Work with stored snippets
|
|
32
|
+
echo 'def hello; "world"; end' | #{File.basename($0)} store_snippet
|
|
33
|
+
#{File.basename($0)} retrieve_current_snippet
|
|
34
|
+
# => def hello; "world"; end
|
|
35
|
+
#{File.basename($0)} eval_current_snippet
|
|
36
|
+
# => "world"
|
|
37
|
+
|
|
38
|
+
# Stop server
|
|
39
|
+
#{File.basename($0)} stop_server
|
|
40
|
+
EOT
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
case action = ARGV.shift || 'usage'
|
|
44
|
+
when 'store_snippet'
|
|
45
|
+
irb_client.send(action, STDIN.read)
|
|
46
|
+
when 'retrieve_current_snippet'
|
|
47
|
+
puts irb_client.send('eval_snippet', '@snippet')
|
|
48
|
+
when 'eval_current_snippet'
|
|
49
|
+
puts irb_client.send('eval_snippet', 'eval(@snippet)')
|
|
50
|
+
when 'execute_current_snippet'
|
|
51
|
+
puts irb_client.send('execute_snippet', 'eval(@snippet)')
|
|
52
|
+
when 'execute_snippet'
|
|
53
|
+
irb_client.send(action, STDIN.read)
|
|
54
|
+
when 'eval_snippet'
|
|
55
|
+
puts irb_client.send(action, STDIN.read)
|
|
56
|
+
when 'eval_lines'
|
|
57
|
+
prefix = ARGV.shift || ' # => '
|
|
58
|
+
lines = STDIN.readlines
|
|
59
|
+
if lines.empty?
|
|
60
|
+
abort "No input provided"
|
|
61
|
+
else
|
|
62
|
+
puts irb_client.send('eval_lines', lines, prefix)
|
|
63
|
+
end
|
|
64
|
+
when 'stop_server'
|
|
65
|
+
irb_client.send(action)
|
|
66
|
+
else
|
|
67
|
+
abort usage
|
|
68
|
+
end
|
data/bin/probe
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
require 'utils'
|
|
16
16
|
include Utils
|
|
17
|
+
include Utils::Probe
|
|
17
18
|
include Tins::GO
|
|
18
19
|
require 'shellwords'
|
|
19
20
|
|
|
@@ -78,7 +79,7 @@ end
|
|
|
78
79
|
# probe server instance to handle incoming requests and process jobs.
|
|
79
80
|
def start_server
|
|
80
81
|
Thread.abort_on_exception = $DEBUG
|
|
81
|
-
|
|
82
|
+
ProbeServer.new(
|
|
82
83
|
server_type: $config.probe.server_type,
|
|
83
84
|
port: $config.probe.tcp_server_port
|
|
84
85
|
).start
|
|
@@ -92,7 +93,7 @@ end
|
|
|
92
93
|
# It also enqueues jobs for execution on the probe server when specified.
|
|
93
94
|
#
|
|
94
95
|
def connect_server
|
|
95
|
-
probe_client =
|
|
96
|
+
probe_client = ProbeClient.new(
|
|
96
97
|
server_type: $config.probe.server_type,
|
|
97
98
|
port: $config.probe.tcp_server_port
|
|
98
99
|
)
|
data/lib/utils/config_file.rb
CHANGED
|
@@ -288,6 +288,17 @@ class Utils::ConfigFile
|
|
|
288
288
|
@probe ||= Probe.new
|
|
289
289
|
end
|
|
290
290
|
|
|
291
|
+
# The irb_server_url method configures the URL for the IRB server
|
|
292
|
+
# communication.
|
|
293
|
+
#
|
|
294
|
+
# This method sets up a DSL accessor for the IRB server URL, providing a
|
|
295
|
+
# default value that uses a Unix domain socket located in the current working
|
|
296
|
+
# directory.
|
|
297
|
+
#
|
|
298
|
+
# @return [ String ] the configured IRB server URL including the default
|
|
299
|
+
# socket path
|
|
300
|
+
dsl_accessor :irb_server_url, "unix://#{Pathname.pwd + 'irb.socket'}"
|
|
301
|
+
|
|
291
302
|
# A configuration class for file system operations.
|
|
292
303
|
#
|
|
293
304
|
# This class manages the configuration settings for searching and discovering
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
require 'logger'
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
|
|
4
|
+
# A class that provides server functionality for interactive Ruby (IRB)
|
|
5
|
+
# sessions.
|
|
6
|
+
#
|
|
7
|
+
# This class manages an IRB server instance that can receive and process code
|
|
8
|
+
# snippets for evaluation. It handles communication through Unix domain
|
|
9
|
+
# sockets, allowing external clients to send code for execution and receive the
|
|
10
|
+
# results back.
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# server = Utils::IRB::IRBServer.new(url: 'unix:///tmp/irb.sock')
|
|
14
|
+
# server.start
|
|
15
|
+
# #
|
|
16
|
+
# client = Utils::IRB::IRBServer.new(url: 'unix:///tmp/irb.sock')
|
|
17
|
+
# client.store_snippet('puts "Hello World"')
|
|
18
|
+
# result = server.eval_snippet('2 + 2')
|
|
19
|
+
class Utils::IRB::IRBServer
|
|
20
|
+
# The initialize method sets up a new IRBServer instance with the specified
|
|
21
|
+
# URL.
|
|
22
|
+
#
|
|
23
|
+
# This method configures the IRB server by initializing a logger for error
|
|
24
|
+
# reporting and storing the provided URL for server communication.
|
|
25
|
+
#
|
|
26
|
+
# @param url [ String ] the URL to be used for the IRB server communication
|
|
27
|
+
def initialize(url:, log_out: nil)
|
|
28
|
+
@url = url
|
|
29
|
+
@log_out = log_out
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# The url reader method provides access to the URL instance variable.
|
|
33
|
+
#
|
|
34
|
+
# @return [ String ] the URL value stored in the instance variable
|
|
35
|
+
attr_reader :url
|
|
36
|
+
|
|
37
|
+
# The snippet reader method provides access to the snippet instance variable.
|
|
38
|
+
#
|
|
39
|
+
# @return [ Object ] the snippet value stored in the instance variable
|
|
40
|
+
attr_reader :snippet
|
|
41
|
+
|
|
42
|
+
# The start method initializes and begins operation of the IRB server.
|
|
43
|
+
#
|
|
44
|
+
# This method sets up the server by building the underlying socket connection,
|
|
45
|
+
# logging the start event, and configuring a background receiver to handle
|
|
46
|
+
# incoming messages. It processes different message actions such as storing
|
|
47
|
+
# code snippets or evaluating code, and responds appropriately to each
|
|
48
|
+
# message type.
|
|
49
|
+
#
|
|
50
|
+
# @return [ Utils::IRB::IRBServer ] returns self to allow for method chaining
|
|
51
|
+
def start
|
|
52
|
+
@server = build_server
|
|
53
|
+
@logger.info "Starting #{self.class.name} server on #{@url}."
|
|
54
|
+
@server.receive_in_background do |message|
|
|
55
|
+
case message.action
|
|
56
|
+
when 'store'
|
|
57
|
+
@snippet = message.snippet
|
|
58
|
+
@logger.info "Stored #{message.to_json}."
|
|
59
|
+
when 'execute'
|
|
60
|
+
time_eval { eval(message.snippet) }
|
|
61
|
+
@logger.info "Execution of #{message.to_json} took %.2fs" % @eval_duration
|
|
62
|
+
when 'eval'
|
|
63
|
+
result = time_eval { eval(message.snippet) }
|
|
64
|
+
@logger.info "Evaluation of #{message.to_json} took %.2fs" % @eval_duration
|
|
65
|
+
message.respond(result: result.to_s, type: message.action)
|
|
66
|
+
when 'eval_lines'
|
|
67
|
+
b = binding
|
|
68
|
+
result = message.lines.map do |line|
|
|
69
|
+
l = line.chomp
|
|
70
|
+
r = b.eval(l)
|
|
71
|
+
[ l, message.prefix, r ].join
|
|
72
|
+
end.join(?\n)
|
|
73
|
+
message.respond(result: result, type: message.action)
|
|
74
|
+
when 'stop'
|
|
75
|
+
@logger.info "Stopping #{self.class.name} server on #{@url}."
|
|
76
|
+
Thread.current.exit
|
|
77
|
+
else
|
|
78
|
+
@logger.warn("Message for action #{message.action.inspect} not supported.")
|
|
79
|
+
end
|
|
80
|
+
rescue => e
|
|
81
|
+
@logger.error("#{self.class.name} caught #{e.class}: #{e} for #{message.to_json}.")
|
|
82
|
+
end
|
|
83
|
+
self
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# The store_snippet method transmits a code snippet to the client for storage.
|
|
87
|
+
#
|
|
88
|
+
# This method prepares a transmission request containing the specified code
|
|
89
|
+
# snippet and sends it to the client using the build_client mechanism. It is
|
|
90
|
+
# designed to facilitate the storage of code snippets within the system's
|
|
91
|
+
# communication protocol.
|
|
92
|
+
#
|
|
93
|
+
# @param code [ String ] the code snippet to be stored
|
|
94
|
+
#
|
|
95
|
+
# @return [ Utils::IRB::IRBServer ] returns self to allow for method chaining
|
|
96
|
+
def store_snippet(code)
|
|
97
|
+
build_client.transmit({ action: 'store', snippet: code })
|
|
98
|
+
self
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# The execute_snippet method sends a code snippet to the IRB server for
|
|
102
|
+
# execution and waits for the response.
|
|
103
|
+
#
|
|
104
|
+
# This method transmits an execute command along with the provided code
|
|
105
|
+
# snippet to the IRB server, allowing the server to evaluate the code and
|
|
106
|
+
# return the result.
|
|
107
|
+
#
|
|
108
|
+
# @param code [ String ] the code snippet to be executed
|
|
109
|
+
#
|
|
110
|
+
# @return [ Utils::IRB::IRBServer ] returns self to allow for method chaining
|
|
111
|
+
def execute_snippet(code)
|
|
112
|
+
build_client.transmit({ action: 'execute', snippet: code })
|
|
113
|
+
self
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# The eval_snippet method sends a code snippet to the IRB server for
|
|
117
|
+
# evaluation and returns the result.
|
|
118
|
+
#
|
|
119
|
+
# This method transmits the provided code snippet to the IRB server for
|
|
120
|
+
# execution, waits for the server's response, and extracts the evaluation
|
|
121
|
+
# result from the response.
|
|
122
|
+
#
|
|
123
|
+
# @param code [ String ] the code snippet to be evaluated
|
|
124
|
+
#
|
|
125
|
+
# @return [ String ] the result of the code snippet evaluation as a string
|
|
126
|
+
def eval_snippet(code)
|
|
127
|
+
message = build_client.transmit_with_response(
|
|
128
|
+
{ action: 'eval', snippet: code }
|
|
129
|
+
)
|
|
130
|
+
message.result
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# The eval_lines method sends a series of code lines to the IRB server for
|
|
134
|
+
# evaluation and returns the formatted results.
|
|
135
|
+
#
|
|
136
|
+
# This method transmits multiple lines of code to the IRB server for
|
|
137
|
+
# execution, with each line being evaluated in sequence. It includes a prefix
|
|
138
|
+
# for each result line and returns the combined output from the evaluation.
|
|
139
|
+
#
|
|
140
|
+
# @param lines [ Array<String> ] the array of code lines to be evaluated
|
|
141
|
+
# @param prefix [ String ] the prefix to be added to each result line, defaults to ' # => '
|
|
142
|
+
#
|
|
143
|
+
# @return [ String ] the formatted results from evaluating the code lines
|
|
144
|
+
def eval_lines(lines, prefix = ' # => ')
|
|
145
|
+
message = build_client.transmit_with_response(
|
|
146
|
+
{ action: 'eval_lines', prefix:, lines: }
|
|
147
|
+
)
|
|
148
|
+
message.result
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
# The stop_server method sends a stop command to the IRB server.
|
|
152
|
+
#
|
|
153
|
+
# This method communicates with the IRB server to request a graceful shutdown
|
|
154
|
+
# of the server process by transmitting a stop action.
|
|
155
|
+
#
|
|
156
|
+
# @return [ nil ] always returns nil after sending the stop command
|
|
157
|
+
def stop_server
|
|
158
|
+
build_client.transmit({ action: 'stop' })
|
|
159
|
+
nil
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
private
|
|
163
|
+
|
|
164
|
+
# The setup_logger method configures the log output destination for the IRB
|
|
165
|
+
# server.
|
|
166
|
+
#
|
|
167
|
+
# This method determines whether a log output path has been provided, and if
|
|
168
|
+
# not, constructs a default log path using the XDG state home directory or a
|
|
169
|
+
# fallback to the user's local state directory. It ensures the log directory
|
|
170
|
+
# exists and creates a new log file for writing.
|
|
171
|
+
#
|
|
172
|
+
# @return [ String ] the path to the log file that will be used for logging
|
|
173
|
+
def setup_logger
|
|
174
|
+
unless @log_out
|
|
175
|
+
xdg_dir = File.expand_path(ENV.fetch('XDG_STATE_HOME', '~/.local/state'))
|
|
176
|
+
log_path = Pathname.new(xdg_dir) + 'utils'
|
|
177
|
+
FileUtils.mkdir_p log_path
|
|
178
|
+
log_path += 'irb-server.log'
|
|
179
|
+
@log_out = File.new(log_path, ?a)
|
|
180
|
+
end
|
|
181
|
+
@log_out.sync = true
|
|
182
|
+
@logger = Logger.new(@log_out)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# The build_server method creates and returns a Unix domain socket server
|
|
186
|
+
# instance based on the URL configuration
|
|
187
|
+
#
|
|
188
|
+
# This method initializes a socket server by delegating to the
|
|
189
|
+
# UnixSocks.from_url factory method, which constructs an appropriate server
|
|
190
|
+
# type (TCP or domain socket) based on the URL scheme and configuration
|
|
191
|
+
# parameters
|
|
192
|
+
#
|
|
193
|
+
# @return [ UnixSocks::TCPSocketServer, UnixSocks::DomainSocketServer ] a new
|
|
194
|
+
# socket server instance configured according to the URL specification
|
|
195
|
+
def build_server
|
|
196
|
+
setup_logger
|
|
197
|
+
UnixSocks.from_url(url)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
alias build_client build_server
|
|
201
|
+
|
|
202
|
+
# The time_eval method measures the execution duration of a block.
|
|
203
|
+
#
|
|
204
|
+
# This method records the start time before yielding to the provided block,
|
|
205
|
+
# then calculates the elapsed time after the block completes, storing the
|
|
206
|
+
# duration in an instance variable for later access.
|
|
207
|
+
#
|
|
208
|
+
# @param block [ Proc ] the block of code to measure execution time for
|
|
209
|
+
#
|
|
210
|
+
# @return [ Object ] the result of the block execution
|
|
211
|
+
#
|
|
212
|
+
# @api private
|
|
213
|
+
def time_eval(&block)
|
|
214
|
+
s = Time.now
|
|
215
|
+
block.()
|
|
216
|
+
ensure
|
|
217
|
+
@eval_duration = Time.now - s
|
|
218
|
+
end
|
|
219
|
+
end
|
data/lib/utils/irb.rb
CHANGED
|
@@ -2,6 +2,7 @@ require 'irb/completion'
|
|
|
2
2
|
require 'enumerator'
|
|
3
3
|
require 'tempfile'
|
|
4
4
|
require 'pp'
|
|
5
|
+
require 'shellwords'
|
|
5
6
|
require 'utils'
|
|
6
7
|
require_maybe 'ap'
|
|
7
8
|
|
|
@@ -83,6 +84,48 @@ module Utils
|
|
|
83
84
|
ri(*patterns, doc: 'yri')
|
|
84
85
|
end
|
|
85
86
|
|
|
87
|
+
# The ai method interacts with an Ollama chat service to process queries
|
|
88
|
+
# and optionally return responses.
|
|
89
|
+
#
|
|
90
|
+
# This method constructs command-line arguments for the ollama_chat_send
|
|
91
|
+
# utility based on the provided options, executes the command with the
|
|
92
|
+
# query as input, and returns the response if requested.
|
|
93
|
+
#
|
|
94
|
+
# @param query [ String ] the input query to send to the Ollama chat
|
|
95
|
+
# service
|
|
96
|
+
# @param command [ TrueClass, FalseClass ] whether to treat the query as
|
|
97
|
+
# a command
|
|
98
|
+
# @param respond [ TrueClass, FalseClass ] whether to capture and return
|
|
99
|
+
# the response from the service
|
|
100
|
+
# @param parse [ TrueClass, FalseClass ] whether to parse the response
|
|
101
|
+
# @param dir [ String ] the directory to use for the operation
|
|
102
|
+
#
|
|
103
|
+
# @return [ String, nil ] the response from the Ollama chat service if
|
|
104
|
+
# respond is true, otherwise nil
|
|
105
|
+
def ai(query, command: false, respond: false, parse: false, dir: ?.)
|
|
106
|
+
dir = File.expand_path(dir)
|
|
107
|
+
args = {
|
|
108
|
+
?r => respond,
|
|
109
|
+
?t => command,
|
|
110
|
+
?p => parse,
|
|
111
|
+
?d => dir,
|
|
112
|
+
}
|
|
113
|
+
args = args.map { |k, v|
|
|
114
|
+
v == false and next
|
|
115
|
+
v == true ? "-#{k}" : [ "-#{k}", v.to_s ]
|
|
116
|
+
}.flatten.compact
|
|
117
|
+
args.unshift 'ollama_chat_send'
|
|
118
|
+
response = nil
|
|
119
|
+
IO.popen(Shellwords.join(args), 'r+') do |io|
|
|
120
|
+
io.write query
|
|
121
|
+
io.close_write
|
|
122
|
+
if respond
|
|
123
|
+
response = io.read
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
response
|
|
127
|
+
end
|
|
128
|
+
|
|
86
129
|
# The irb_open method opens a URL or executes a block to capture output
|
|
87
130
|
# and open it.
|
|
88
131
|
#
|
|
@@ -661,6 +704,50 @@ module Utils
|
|
|
661
704
|
nil
|
|
662
705
|
end
|
|
663
706
|
|
|
707
|
+
# The irb_server method provides access to an IRB server instance for
|
|
708
|
+
# interactive Ruby sessions.
|
|
709
|
+
#
|
|
710
|
+
# This method ensures that a single IRB server instance is created and
|
|
711
|
+
# started for the current process, loading the configuration from
|
|
712
|
+
# standard paths and using the configured server URL.
|
|
713
|
+
#
|
|
714
|
+
# @return [ Utils::IRB::IRBServer ] the IRB server instance, initialized
|
|
715
|
+
# and started if not already running
|
|
716
|
+
def irb_server
|
|
717
|
+
unless @irb_server
|
|
718
|
+
config = Utils::ConfigFile.new.tap(&:configure_from_paths)
|
|
719
|
+
@irb_server = Utils::IRB::IRBServer.new(url: config.irb_server_url).start
|
|
720
|
+
end
|
|
721
|
+
@irb_server
|
|
722
|
+
end
|
|
723
|
+
|
|
724
|
+
# The irb_server_stop method sends a stop command to the IRB server
|
|
725
|
+
# client.
|
|
726
|
+
#
|
|
727
|
+
# This method accesses the IRB client instance and invokes the
|
|
728
|
+
# stop_server method on it, which gracefully shuts down the IRB server
|
|
729
|
+
# process.
|
|
730
|
+
#
|
|
731
|
+
# @return [ nil ] always returns nil after sending the stop command to
|
|
732
|
+
# the server
|
|
733
|
+
def irb_server_stop
|
|
734
|
+
irb_client.stop_server
|
|
735
|
+
end
|
|
736
|
+
|
|
737
|
+
# The irb_client method provides access to an IRB server client instance.
|
|
738
|
+
#
|
|
739
|
+
# This method creates and returns a new IRB server client by first
|
|
740
|
+
# loading the configuration from standard paths and then using the
|
|
741
|
+
# configured server URL
|
|
742
|
+
# to initialize the client.
|
|
743
|
+
#
|
|
744
|
+
# @return [ Utils::IRB::IRBServer ] a new IRB server client instance configured
|
|
745
|
+
# with the URL from the application's configuration
|
|
746
|
+
def irb_client
|
|
747
|
+
config = Utils::ConfigFile.new.tap(&:configure_from_paths)
|
|
748
|
+
Utils::IRB::IRBServer.new(url: config.irb_server_url)
|
|
749
|
+
end
|
|
750
|
+
|
|
664
751
|
# The ed method opens files for editing using the system editor.
|
|
665
752
|
#
|
|
666
753
|
# This method provides a convenient way to edit files by invoking the
|
|
@@ -794,6 +881,8 @@ module Utils
|
|
|
794
881
|
end
|
|
795
882
|
end
|
|
796
883
|
|
|
884
|
+
require 'utils/irb/irb_server'
|
|
885
|
+
|
|
797
886
|
Utils::IRB.configure
|
|
798
887
|
|
|
799
888
|
class String
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
module Utils::Probe
|
|
2
|
+
# A client for interacting with the probe server through Unix domain sockets.
|
|
3
|
+
#
|
|
4
|
+
# This class provides an interface for enqueueing process jobs and managing
|
|
5
|
+
# environment variables on a remote probe server. It uses Unix domain sockets
|
|
6
|
+
# to communicate with the server, enabling distributed task execution and
|
|
7
|
+
# configuration management.
|
|
8
|
+
class ProbeClient
|
|
9
|
+
include ServerHandling
|
|
10
|
+
|
|
11
|
+
# A proxy class for managing environment variables through a probe server communication channel.
|
|
12
|
+
#
|
|
13
|
+
# This class provides a wrapper around the ENV object that allows setting and retrieving
|
|
14
|
+
# environment variables while logging these operations through the probe server.
|
|
15
|
+
# It intercepts assignments and lookups to provide visibility into environment modifications
|
|
16
|
+
# during probe server operations.
|
|
17
|
+
class EnvProxy
|
|
18
|
+
# The initialize method sets up a new instance with the provided server
|
|
19
|
+
# object.
|
|
20
|
+
#
|
|
21
|
+
# @param server [ UnixSocks::Server ] the server object to be assigned
|
|
22
|
+
# to the instance variable
|
|
23
|
+
def initialize(server)
|
|
24
|
+
@server = server
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# The []= method sets an environment variable value through the probe server.
|
|
28
|
+
#
|
|
29
|
+
# This method transmits a request to the probe server to set the specified
|
|
30
|
+
# environment variable key to the given value, then returns the updated
|
|
31
|
+
# environment value from the server's response.
|
|
32
|
+
#
|
|
33
|
+
# @param key [ String ] the environment variable key to set
|
|
34
|
+
# @param value [ String ] the value to assign to the environment variable
|
|
35
|
+
#
|
|
36
|
+
# @return [ String ] the updated environment variable value returned by the server
|
|
37
|
+
def []=(key, value)
|
|
38
|
+
response = @server.transmit_with_response(type: 'set_env', key:, value:)
|
|
39
|
+
response.env
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# The [] method retrieves the value of an environment variable from the probe server.
|
|
43
|
+
#
|
|
44
|
+
# This method sends a request to the probe server to fetch the current value of the specified
|
|
45
|
+
# environment variable key and returns the corresponding value.
|
|
46
|
+
#
|
|
47
|
+
# @param key [ String ] the environment variable key to retrieve
|
|
48
|
+
#
|
|
49
|
+
# @return [ String ] the value of the specified environment variable
|
|
50
|
+
def [](key)
|
|
51
|
+
response = @server.transmit_with_response(type: 'get_env', key:)
|
|
52
|
+
response.env
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
attr_reader :env
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# The initialize method sets up a new probe server instance.
|
|
59
|
+
#
|
|
60
|
+
# This method creates and configures a Unix domain socket server for
|
|
61
|
+
# handling probe jobs and communication. It initializes the server with a
|
|
62
|
+
# specific socket name and runtime directory, preparing it to listen for
|
|
63
|
+
# incoming connections and process jobs.
|
|
64
|
+
#
|
|
65
|
+
# @return [ Utils::ProbeServer ] a new probe server instance configured with
|
|
66
|
+
# the specified socket name and runtime directory
|
|
67
|
+
def initialize(server_type: :unix, port: 6666)
|
|
68
|
+
@server = create_server(server_type, port)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# The env method provides access to environment variable management through
|
|
72
|
+
# a proxy object.
|
|
73
|
+
#
|
|
74
|
+
# This method returns an EnvProxy instance that allows for setting and
|
|
75
|
+
# retrieving environment variables via the probe server communication
|
|
76
|
+
# channel.
|
|
77
|
+
#
|
|
78
|
+
# @return [ Utils::ProbeServer::EnvProxy ] a proxy object for environment
|
|
79
|
+
# variable operations
|
|
80
|
+
def env
|
|
81
|
+
EnvProxy.new(@server)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# The enqueue method submits a new process job to the probe server for
|
|
85
|
+
# execution.
|
|
86
|
+
#
|
|
87
|
+
# This method transmits a process job request to the underlying Unix domain
|
|
88
|
+
# socket server, which then adds the job to the processing queue. The job
|
|
89
|
+
# includes the specified command arguments that will be executed by the
|
|
90
|
+
# probe server.
|
|
91
|
+
#
|
|
92
|
+
# @param args [ Array ] the command arguments to be executed by the process
|
|
93
|
+
# job
|
|
94
|
+
def enqueue(args)
|
|
95
|
+
@server.transmit({ type: 'process_job', args: })
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -1,264 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
require 'term/ansicolor'
|
|
3
|
-
|
|
4
|
-
module Utils
|
|
5
|
-
# A module that provides server handling functionality for creating and
|
|
6
|
-
# managing socket servers.
|
|
7
|
-
#
|
|
8
|
-
# This module encapsulates the logic for initializing different types of
|
|
9
|
-
# socket servers based on the specified server type, supporting both TCP and
|
|
10
|
-
# domain socket configurations. It provides a centralized approach to server
|
|
11
|
-
# creation and management within the Utils library.
|
|
12
|
-
module ServerHandling
|
|
13
|
-
# The create_server method initializes and returns a socket server instance
|
|
14
|
-
# based on the specified server type.
|
|
15
|
-
#
|
|
16
|
-
# This method creates either a TCP socket server or a domain socket server
|
|
17
|
-
# depending on the server type parameter. It configures the server with the
|
|
18
|
-
# appropriate parameters including port number for TCP servers or socket
|
|
19
|
-
# name and runtime directory for domain sockets.
|
|
20
|
-
#
|
|
21
|
-
# @param server_type [ Symbol ] the type of socket server to create, either :tcp or another value for domain socket
|
|
22
|
-
# @param port [ Integer ] the port number to use for TCP socket server creation
|
|
23
|
-
#
|
|
24
|
-
# @return [ UnixSocks::TCPSocketServer, UnixSocks::DomainSocketServer ] a
|
|
25
|
-
# new socket server instance of the specified type
|
|
26
|
-
def create_server(server_type, port)
|
|
27
|
-
case server_type
|
|
28
|
-
when :tcp
|
|
29
|
-
UnixSocks::TCPSocketServer.new(port:)
|
|
30
|
-
else
|
|
31
|
-
UnixSocks::DomainSocketServer.new(socket_name: 'probe.sock', runtime_dir: Dir.pwd)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# A process job representation for execution within the probe server system.
|
|
37
|
-
#
|
|
38
|
-
# This class encapsulates the information and behavior associated with a
|
|
39
|
-
# single executable task that can be enqueued and processed by a ProbeServer.
|
|
40
|
-
# It holds command arguments, manages execution status, and provides
|
|
41
|
-
# mechanisms for serialization and display of job information.
|
|
42
|
-
class ProcessJob
|
|
43
|
-
include Term::ANSIColor
|
|
44
|
-
|
|
45
|
-
# Initializes a new ProcessJob instance with the specified arguments and
|
|
46
|
-
# optional probe server.
|
|
47
|
-
#
|
|
48
|
-
# This method creates a process job object that can be enqueued for
|
|
49
|
-
# execution by a probe server. It assigns a unique job ID from the probe
|
|
50
|
-
# server if provided and stores the command arguments as an array.
|
|
51
|
-
#
|
|
52
|
-
# @param args [ Array ] the command arguments to be executed by the job
|
|
53
|
-
# @param probe_server [ Utils::ProbeServer, nil ] the probe server instance
|
|
54
|
-
# to use for generating job IDs
|
|
55
|
-
#
|
|
56
|
-
# @return [ Utils::ProcessJob ] a new ProcessJob instance configured with
|
|
57
|
-
# the provided arguments and server reference
|
|
58
|
-
def initialize(args:, probe_server: nil)
|
|
59
|
-
@id = probe_server&.next_job_id
|
|
60
|
-
@args = Array(args)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
# Returns the unique identifier of the process job.
|
|
64
|
-
#
|
|
65
|
-
# @return [ Integer ] the job ID
|
|
66
|
-
attr_reader :id
|
|
67
|
-
|
|
68
|
-
# The args reader method provides access to the arguments stored in the
|
|
69
|
-
# instance.
|
|
70
|
-
#
|
|
71
|
-
# @return [ Array ] the array of arguments
|
|
72
|
-
attr_reader :args
|
|
73
|
-
|
|
74
|
-
# The ok method sets the success status of the process job.
|
|
75
|
-
#
|
|
76
|
-
# @param value [ TrueClass, FalseClass, nil ] the success status to set
|
|
77
|
-
attr_writer :ok
|
|
78
|
-
|
|
79
|
-
# Returns the type identifier for the process job.
|
|
80
|
-
#
|
|
81
|
-
# This method provides a constant string value that identifies the object
|
|
82
|
-
# as a process job within the probe server system, facilitating type-based
|
|
83
|
-
# dispatch and handling.
|
|
84
|
-
#
|
|
85
|
-
# @return [ String ] the string 'process_job' indicating the object's type
|
|
86
|
-
def type
|
|
87
|
-
'process_job'
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
# The ok method returns a character representation of the job's success
|
|
91
|
-
# status.
|
|
92
|
-
#
|
|
93
|
-
# This method provides a visual indicator of whether a process job has
|
|
94
|
-
# succeeded, failed, or is still in progress. It returns 'y' for successful
|
|
95
|
-
# jobs, 'n' for failed jobs, and '…' for jobs that are currently running or
|
|
96
|
-
# pending.
|
|
97
|
-
#
|
|
98
|
-
# @return [ String ] 'y' if the job succeeded, 'n' if it failed, or '…' if
|
|
99
|
-
# the status is unknown
|
|
100
|
-
def ok
|
|
101
|
-
case @ok
|
|
102
|
-
when false then 'n'
|
|
103
|
-
when true then 'y'
|
|
104
|
-
else '…'
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
# The ok_colorize method applies color formatting to a string based on the
|
|
109
|
-
# success status.
|
|
110
|
-
#
|
|
111
|
-
# This method returns the input string wrapped with color codes to indicate
|
|
112
|
-
# whether the associated process job succeeded, failed, or is in progress.
|
|
113
|
-
# Successful jobs are highlighted in green, failed jobs in red, and pending
|
|
114
|
-
# jobs are returned without any color formatting.
|
|
115
|
-
#
|
|
116
|
-
# @param string [ String ] the string to be colorized
|
|
117
|
-
#
|
|
118
|
-
# @return [ String ] the colorized string or the original string if status is unknown
|
|
119
|
-
def ok_colorize(string)
|
|
120
|
-
case @ok
|
|
121
|
-
when false then white { on_red { string } }
|
|
122
|
-
when true then black { on_green { string } }
|
|
123
|
-
else string
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
# The inspect method generates a colorized string representation of the
|
|
128
|
-
# process job.
|
|
129
|
-
#
|
|
130
|
-
# This method creates a formatted string that includes the job's unique
|
|
131
|
-
# identifier and its command arguments, with the status indicator
|
|
132
|
-
# color-coded based on whether the job succeeded, failed, or is pending.
|
|
133
|
-
#
|
|
134
|
-
# @return [ String ] a formatted string representation of the process job
|
|
135
|
-
# including its ID, arguments, and color-coded status indicator
|
|
136
|
-
def inspect
|
|
137
|
-
ok_colorize("#{id} #{args.map { |a| a.include?(' ') ? a.inspect : a } * ' '}")
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
alias to_s inspect
|
|
141
|
-
|
|
142
|
-
# The as_json method converts the process job object into a
|
|
143
|
-
# JSON-serializable hash.
|
|
144
|
-
#
|
|
145
|
-
# This method creates and returns a hash representation of the process job,
|
|
146
|
-
# containing its type, unique identifier, and command arguments.
|
|
147
|
-
#
|
|
148
|
-
# @return [ Hash ] a hash containing the type, id, and args of the process job
|
|
149
|
-
def as_json(*)
|
|
150
|
-
{ type:, id:, args:, }
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
# The to_json method converts the object to a JSON string representation.
|
|
154
|
-
#
|
|
155
|
-
# This method delegates to the as_json method to generate a hash representation
|
|
156
|
-
# of the object, then converts that hash to a JSON string using the
|
|
157
|
-
# standard JSON library's to_json method.
|
|
158
|
-
#
|
|
159
|
-
# @return [ String ] a JSON string representation of the object
|
|
160
|
-
def to_json(*)
|
|
161
|
-
as_json.to_json(*)
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
# A client for interacting with the probe server through Unix domain sockets.
|
|
166
|
-
#
|
|
167
|
-
# This class provides an interface for enqueueing process jobs and managing
|
|
168
|
-
# environment variables on a remote probe server. It uses Unix domain sockets
|
|
169
|
-
# to communicate with the server, enabling distributed task execution and
|
|
170
|
-
# configuration management.
|
|
171
|
-
class ProbeClient
|
|
172
|
-
include ServerHandling
|
|
173
|
-
|
|
174
|
-
# A proxy class for managing environment variables through a probe server communication channel.
|
|
175
|
-
#
|
|
176
|
-
# This class provides a wrapper around the ENV object that allows setting and retrieving
|
|
177
|
-
# environment variables while logging these operations through the probe server.
|
|
178
|
-
# It intercepts assignments and lookups to provide visibility into environment modifications
|
|
179
|
-
# during probe server operations.
|
|
180
|
-
class EnvProxy
|
|
181
|
-
# The initialize method sets up a new instance with the provided server
|
|
182
|
-
# object.
|
|
183
|
-
#
|
|
184
|
-
# @param server [ UnixSocks::Server ] the server object to be assigned
|
|
185
|
-
# to the instance variable
|
|
186
|
-
def initialize(server)
|
|
187
|
-
@server = server
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
# The []= method sets an environment variable value through the probe server.
|
|
191
|
-
#
|
|
192
|
-
# This method transmits a request to the probe server to set the specified
|
|
193
|
-
# environment variable key to the given value, then returns the updated
|
|
194
|
-
# environment value from the server's response.
|
|
195
|
-
#
|
|
196
|
-
# @param key [ String ] the environment variable key to set
|
|
197
|
-
# @param value [ String ] the value to assign to the environment variable
|
|
198
|
-
#
|
|
199
|
-
# @return [ String ] the updated environment variable value returned by the server
|
|
200
|
-
def []=(key, value)
|
|
201
|
-
response = @server.transmit_with_response(type: 'set_env', key:, value:)
|
|
202
|
-
response.env
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
# The [] method retrieves the value of an environment variable from the probe server.
|
|
206
|
-
#
|
|
207
|
-
# This method sends a request to the probe server to fetch the current value of the specified
|
|
208
|
-
# environment variable key and returns the corresponding value.
|
|
209
|
-
#
|
|
210
|
-
# @param key [ String ] the environment variable key to retrieve
|
|
211
|
-
#
|
|
212
|
-
# @return [ String ] the value of the specified environment variable
|
|
213
|
-
def [](key)
|
|
214
|
-
response = @server.transmit_with_response(type: 'get_env', key:)
|
|
215
|
-
response.env
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
attr_reader :env
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
# The initialize method sets up a new probe server instance.
|
|
222
|
-
#
|
|
223
|
-
# This method creates and configures a Unix domain socket server for
|
|
224
|
-
# handling probe jobs and communication. It initializes the server with a
|
|
225
|
-
# specific socket name and runtime directory, preparing it to listen for
|
|
226
|
-
# incoming connections and process jobs.
|
|
227
|
-
#
|
|
228
|
-
# @return [ Utils::ProbeServer ] a new probe server instance configured with
|
|
229
|
-
# the specified socket name and runtime directory
|
|
230
|
-
def initialize(server_type: :unix, port: 6666)
|
|
231
|
-
@server = create_server(server_type, port)
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
# The env method provides access to environment variable management through
|
|
235
|
-
# a proxy object.
|
|
236
|
-
#
|
|
237
|
-
# This method returns an EnvProxy instance that allows for setting and
|
|
238
|
-
# retrieving environment variables via the probe server communication
|
|
239
|
-
# channel.
|
|
240
|
-
#
|
|
241
|
-
# @return [ Utils::ProbeServer::EnvProxy ] a proxy object for environment
|
|
242
|
-
# variable operations
|
|
243
|
-
def env
|
|
244
|
-
EnvProxy.new(@server)
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
# The enqueue method submits a new process job to the probe server for
|
|
248
|
-
# execution.
|
|
249
|
-
#
|
|
250
|
-
# This method transmits a process job request to the underlying Unix domain
|
|
251
|
-
# socket server, which then adds the job to the processing queue. The job
|
|
252
|
-
# includes the specified command arguments that will be executed by the
|
|
253
|
-
# probe server.
|
|
254
|
-
#
|
|
255
|
-
# @param args [ Array ] the command arguments to be executed by the process
|
|
256
|
-
# job
|
|
257
|
-
def enqueue(args)
|
|
258
|
-
@server.transmit({ type: 'process_job', args: })
|
|
259
|
-
end
|
|
260
|
-
end
|
|
261
|
-
|
|
1
|
+
module Utils::Probe
|
|
262
2
|
# A probe server for managing and executing process jobs through Unix domain
|
|
263
3
|
# sockets.
|
|
264
4
|
#
|
|
@@ -267,7 +7,7 @@ module Utils
|
|
|
267
7
|
# maintains a queue of jobs, tracks their execution status, and provides an
|
|
268
8
|
# interactive interface for managing the server.
|
|
269
9
|
class ProbeServer
|
|
270
|
-
include ServerHandling
|
|
10
|
+
include Utils::Probe::ServerHandling
|
|
271
11
|
include Term::ANSIColor
|
|
272
12
|
|
|
273
13
|
# The initialize method sets up a new probe server instance.
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
module Utils::Probe
|
|
2
|
+
# A process job representation for execution within the probe server system.
|
|
3
|
+
#
|
|
4
|
+
# This class encapsulates the information and behavior associated with a
|
|
5
|
+
# single executable task that can be enqueued and processed by a ProbeServer.
|
|
6
|
+
# It holds command arguments, manages execution status, and provides
|
|
7
|
+
# mechanisms for serialization and display of job information.
|
|
8
|
+
class ProcessJob
|
|
9
|
+
include Term::ANSIColor
|
|
10
|
+
|
|
11
|
+
# Initializes a new ProcessJob instance with the specified arguments and
|
|
12
|
+
# optional probe server.
|
|
13
|
+
#
|
|
14
|
+
# This method creates a process job object that can be enqueued for
|
|
15
|
+
# execution by a probe server. It assigns a unique job ID from the probe
|
|
16
|
+
# server if provided and stores the command arguments as an array.
|
|
17
|
+
#
|
|
18
|
+
# @param args [ Array ] the command arguments to be executed by the job
|
|
19
|
+
# @param probe_server [ Utils::ProbeServer, nil ] the probe server instance
|
|
20
|
+
# to use for generating job IDs
|
|
21
|
+
#
|
|
22
|
+
# @return [ Utils::ProcessJob ] a new ProcessJob instance configured with
|
|
23
|
+
# the provided arguments and server reference
|
|
24
|
+
def initialize(args:, probe_server: nil)
|
|
25
|
+
@id = probe_server&.next_job_id
|
|
26
|
+
@args = Array(args)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Returns the unique identifier of the process job.
|
|
30
|
+
#
|
|
31
|
+
# @return [ Integer ] the job ID
|
|
32
|
+
attr_reader :id
|
|
33
|
+
|
|
34
|
+
# The args reader method provides access to the arguments stored in the
|
|
35
|
+
# instance.
|
|
36
|
+
#
|
|
37
|
+
# @return [ Array ] the array of arguments
|
|
38
|
+
attr_reader :args
|
|
39
|
+
|
|
40
|
+
# The ok method sets the success status of the process job.
|
|
41
|
+
#
|
|
42
|
+
# @param value [ TrueClass, FalseClass, nil ] the success status to set
|
|
43
|
+
attr_writer :ok
|
|
44
|
+
|
|
45
|
+
# Returns the type identifier for the process job.
|
|
46
|
+
#
|
|
47
|
+
# This method provides a constant string value that identifies the object
|
|
48
|
+
# as a process job within the probe server system, facilitating type-based
|
|
49
|
+
# dispatch and handling.
|
|
50
|
+
#
|
|
51
|
+
# @return [ String ] the string 'process_job' indicating the object's type
|
|
52
|
+
def type
|
|
53
|
+
'process_job'
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# The ok method returns a character representation of the job's success
|
|
57
|
+
# status.
|
|
58
|
+
#
|
|
59
|
+
# This method provides a visual indicator of whether a process job has
|
|
60
|
+
# succeeded, failed, or is still in progress. It returns 'y' for successful
|
|
61
|
+
# jobs, 'n' for failed jobs, and '…' for jobs that are currently running or
|
|
62
|
+
# pending.
|
|
63
|
+
#
|
|
64
|
+
# @return [ String ] 'y' if the job succeeded, 'n' if it failed, or '…' if
|
|
65
|
+
# the status is unknown
|
|
66
|
+
def ok
|
|
67
|
+
case @ok
|
|
68
|
+
when false then 'n'
|
|
69
|
+
when true then 'y'
|
|
70
|
+
else '…'
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# The ok_colorize method applies color formatting to a string based on the
|
|
75
|
+
# success status.
|
|
76
|
+
#
|
|
77
|
+
# This method returns the input string wrapped with color codes to indicate
|
|
78
|
+
# whether the associated process job succeeded, failed, or is in progress.
|
|
79
|
+
# Successful jobs are highlighted in green, failed jobs in red, and pending
|
|
80
|
+
# jobs are returned without any color formatting.
|
|
81
|
+
#
|
|
82
|
+
# @param string [ String ] the string to be colorized
|
|
83
|
+
#
|
|
84
|
+
# @return [ String ] the colorized string or the original string if status is unknown
|
|
85
|
+
def ok_colorize(string)
|
|
86
|
+
case @ok
|
|
87
|
+
when false then white { on_red { string } }
|
|
88
|
+
when true then black { on_green { string } }
|
|
89
|
+
else string
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# The inspect method generates a colorized string representation of the
|
|
94
|
+
# process job.
|
|
95
|
+
#
|
|
96
|
+
# This method creates a formatted string that includes the job's unique
|
|
97
|
+
# identifier and its command arguments, with the status indicator
|
|
98
|
+
# color-coded based on whether the job succeeded, failed, or is pending.
|
|
99
|
+
#
|
|
100
|
+
# @return [ String ] a formatted string representation of the process job
|
|
101
|
+
# including its ID, arguments, and color-coded status indicator
|
|
102
|
+
def inspect
|
|
103
|
+
ok_colorize("#{id} #{args.map { |a| a.include?(' ') ? a.inspect : a } * ' '}")
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
alias to_s inspect
|
|
107
|
+
|
|
108
|
+
# The as_json method converts the process job object into a
|
|
109
|
+
# JSON-serializable hash.
|
|
110
|
+
#
|
|
111
|
+
# This method creates and returns a hash representation of the process job,
|
|
112
|
+
# containing its type, unique identifier, and command arguments.
|
|
113
|
+
#
|
|
114
|
+
# @return [ Hash ] a hash containing the type, id, and args of the process job
|
|
115
|
+
def as_json(*)
|
|
116
|
+
{ type:, id:, args:, }
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# The to_json method converts the object to a JSON string representation.
|
|
120
|
+
#
|
|
121
|
+
# This method delegates to the as_json method to generate a hash representation
|
|
122
|
+
# of the object, then converts that hash to a JSON string using the
|
|
123
|
+
# standard JSON library's to_json method.
|
|
124
|
+
#
|
|
125
|
+
# @return [ String ] a JSON string representation of the object
|
|
126
|
+
def to_json(*)
|
|
127
|
+
as_json.to_json(*)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Utils::Probe
|
|
2
|
+
# A module that provides server handling functionality for creating and
|
|
3
|
+
# managing socket servers.
|
|
4
|
+
#
|
|
5
|
+
# This module encapsulates the logic for initializing different types of
|
|
6
|
+
# socket servers based on the specified server type, supporting both TCP and
|
|
7
|
+
# domain socket configurations. It provides a centralized approach to server
|
|
8
|
+
# creation and management within the Utils library.
|
|
9
|
+
module ServerHandling
|
|
10
|
+
# The create_server method initializes and returns a socket server instance
|
|
11
|
+
# based on the specified server type.
|
|
12
|
+
#
|
|
13
|
+
# This method creates either a TCP socket server or a domain socket server
|
|
14
|
+
# depending on the server type parameter. It configures the server with the
|
|
15
|
+
# appropriate parameters including port number for TCP servers or socket
|
|
16
|
+
# name and runtime directory for domain sockets.
|
|
17
|
+
#
|
|
18
|
+
# @param server_type [ Symbol ] the type of socket server to create, either :tcp or another value for domain socket
|
|
19
|
+
# @param port [ Integer ] the port number to use for TCP socket server creation
|
|
20
|
+
#
|
|
21
|
+
# @return [ UnixSocks::TCPSocketServer, UnixSocks::DomainSocketServer ] a
|
|
22
|
+
# new socket server instance of the specified type
|
|
23
|
+
def create_server(server_type, port)
|
|
24
|
+
case server_type
|
|
25
|
+
when :tcp
|
|
26
|
+
UnixSocks::TCPSocketServer.new(port:)
|
|
27
|
+
else
|
|
28
|
+
UnixSocks::DomainSocketServer.new(socket_name: 'probe.sock', runtime_dir: Dir.pwd)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
data/lib/utils/probe.rb
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# A module that provides probe server functionality for managing and executing
|
|
2
|
+
# process jobs through Unix domain sockets.
|
|
3
|
+
#
|
|
4
|
+
# This module encapsulates the core components for creating and interacting
|
|
5
|
+
# with probe servers that can enqueue and run process jobs in a distributed
|
|
6
|
+
# manner.
|
|
7
|
+
#
|
|
8
|
+
# The module includes classes for handling server communication, managing
|
|
9
|
+
# process jobs, and providing client interfaces for interacting with probe
|
|
10
|
+
# servers.
|
|
11
|
+
#
|
|
12
|
+
# It supports both TCP and Unix domain socket configurations for server
|
|
13
|
+
# communication and provides mechanisms for environment variable management and
|
|
14
|
+
# job execution tracking.
|
|
15
|
+
module Utils::Probe
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
require 'unix_socks'
|
|
19
|
+
require 'term/ansicolor'
|
|
20
|
+
require 'utils/probe/server_handling'
|
|
21
|
+
require 'utils/probe/process_job'
|
|
22
|
+
require 'utils/probe/probe_server'
|
|
23
|
+
require 'utils/probe/probe_client'
|
data/lib/utils/version.rb
CHANGED
data/lib/utils.rb
CHANGED
data/utils.gemspec
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
|
-
# stub: utils 0.
|
|
2
|
+
# stub: utils 0.83.0 ruby lib
|
|
3
3
|
|
|
4
4
|
Gem::Specification.new do |s|
|
|
5
5
|
s.name = "utils".freeze
|
|
6
|
-
s.version = "0.
|
|
6
|
+
s.version = "0.83.0".freeze
|
|
7
7
|
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
|
9
9
|
s.require_paths = ["lib".freeze]
|
|
@@ -11,9 +11,9 @@ Gem::Specification.new do |s|
|
|
|
11
11
|
s.date = "1980-01-02"
|
|
12
12
|
s.description = "This ruby gem provides some useful command line utilities".freeze
|
|
13
13
|
s.email = "flori@ping.de".freeze
|
|
14
|
-
s.executables = ["ascii7".freeze, "blameline".freeze, "changes".freeze, "classify".freeze, "code_comment".freeze, "code_indexer".freeze, "commit_message".freeze, "discover".freeze, "edit".freeze, "edit_wait".freeze, "enum".freeze, "git-empty".freeze, "git-versions".freeze, "json_check".freeze, "long_lines".freeze, "myex".freeze, "on_change".freeze, "path".freeze, "print_method".freeze, "probe".freeze, "rainbow".freeze, "rd2md".freeze, "search".freeze, "sedit".freeze, "serve".freeze, "ssh-tunnel".freeze, "strip_spaces".freeze, "sync_dir".freeze, "untest".freeze, "utils-utilsrc".freeze, "vcf2alias".freeze, "yaml_check".freeze]
|
|
15
|
-
s.extra_rdoc_files = ["README.md".freeze, "lib/utils.rb".freeze, "lib/utils/config_dir.rb".freeze, "lib/utils/config_file.rb".freeze, "lib/utils/editor.rb".freeze, "lib/utils/finder.rb".freeze, "lib/utils/grepper.rb".freeze, "lib/utils/irb.rb".freeze, "lib/utils/line_blamer.rb".freeze, "lib/utils/line_formatter.rb".freeze, "lib/utils/md5.rb".freeze, "lib/utils/patterns.rb".freeze, "lib/utils/probe_server.rb".freeze, "lib/utils/ssh_tunnel_specification.rb".freeze, "lib/utils/version.rb".freeze, "lib/utils/xt/source_location_extension.rb".freeze]
|
|
16
|
-
s.files = ["Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ascii7".freeze, "bin/blameline".freeze, "bin/changes".freeze, "bin/classify".freeze, "bin/code_comment".freeze, "bin/code_indexer".freeze, "bin/commit_message".freeze, "bin/discover".freeze, "bin/edit".freeze, "bin/edit_wait".freeze, "bin/enum".freeze, "bin/git-empty".freeze, "bin/git-versions".freeze, "bin/json_check".freeze, "bin/long_lines".freeze, "bin/myex".freeze, "bin/on_change".freeze, "bin/path".freeze, "bin/print_method".freeze, "bin/probe".freeze, "bin/rainbow".freeze, "bin/rd2md".freeze, "bin/search".freeze, "bin/sedit".freeze, "bin/serve".freeze, "bin/ssh-tunnel".freeze, "bin/strip_spaces".freeze, "bin/sync_dir".freeze, "bin/untest".freeze, "bin/utils-utilsrc".freeze, "bin/vcf2alias".freeze, "bin/yaml_check".freeze, "lib/utils.rb".freeze, "lib/utils/config_dir.rb".freeze, "lib/utils/config_file.rb".freeze, "lib/utils/editor.rb".freeze, "lib/utils/finder.rb".freeze, "lib/utils/grepper.rb".freeze, "lib/utils/irb.rb".freeze, "lib/utils/line_blamer.rb".freeze, "lib/utils/line_formatter.rb".freeze, "lib/utils/md5.rb".freeze, "lib/utils/patterns.rb".freeze, "lib/utils/probe_server.rb".freeze, "lib/utils/ssh_tunnel_specification.rb".freeze, "lib/utils/version.rb".freeze, "lib/utils/xt/source_location_extension.rb".freeze, "tests/test_helper.rb".freeze, "tests/utils_test.rb".freeze, "utils.gemspec".freeze]
|
|
14
|
+
s.executables = ["ascii7".freeze, "blameline".freeze, "changes".freeze, "classify".freeze, "code_comment".freeze, "code_indexer".freeze, "commit_message".freeze, "discover".freeze, "edit".freeze, "edit_wait".freeze, "enum".freeze, "git-empty".freeze, "git-versions".freeze, "irb_client".freeze, "json_check".freeze, "long_lines".freeze, "myex".freeze, "on_change".freeze, "path".freeze, "print_method".freeze, "probe".freeze, "rainbow".freeze, "rd2md".freeze, "search".freeze, "sedit".freeze, "serve".freeze, "ssh-tunnel".freeze, "strip_spaces".freeze, "sync_dir".freeze, "untest".freeze, "utils-utilsrc".freeze, "vcf2alias".freeze, "yaml_check".freeze]
|
|
15
|
+
s.extra_rdoc_files = ["README.md".freeze, "lib/utils.rb".freeze, "lib/utils/config_dir.rb".freeze, "lib/utils/config_file.rb".freeze, "lib/utils/editor.rb".freeze, "lib/utils/finder.rb".freeze, "lib/utils/grepper.rb".freeze, "lib/utils/irb.rb".freeze, "lib/utils/irb/irb_server.rb".freeze, "lib/utils/line_blamer.rb".freeze, "lib/utils/line_formatter.rb".freeze, "lib/utils/md5.rb".freeze, "lib/utils/patterns.rb".freeze, "lib/utils/probe.rb".freeze, "lib/utils/probe/probe_client.rb".freeze, "lib/utils/probe/probe_server.rb".freeze, "lib/utils/probe/process_job.rb".freeze, "lib/utils/probe/server_handling.rb".freeze, "lib/utils/ssh_tunnel_specification.rb".freeze, "lib/utils/version.rb".freeze, "lib/utils/xt/source_location_extension.rb".freeze]
|
|
16
|
+
s.files = ["Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ascii7".freeze, "bin/blameline".freeze, "bin/changes".freeze, "bin/classify".freeze, "bin/code_comment".freeze, "bin/code_indexer".freeze, "bin/commit_message".freeze, "bin/discover".freeze, "bin/edit".freeze, "bin/edit_wait".freeze, "bin/enum".freeze, "bin/git-empty".freeze, "bin/git-versions".freeze, "bin/irb_client".freeze, "bin/json_check".freeze, "bin/long_lines".freeze, "bin/myex".freeze, "bin/on_change".freeze, "bin/path".freeze, "bin/print_method".freeze, "bin/probe".freeze, "bin/rainbow".freeze, "bin/rd2md".freeze, "bin/search".freeze, "bin/sedit".freeze, "bin/serve".freeze, "bin/ssh-tunnel".freeze, "bin/strip_spaces".freeze, "bin/sync_dir".freeze, "bin/untest".freeze, "bin/utils-utilsrc".freeze, "bin/vcf2alias".freeze, "bin/yaml_check".freeze, "lib/utils.rb".freeze, "lib/utils/config_dir.rb".freeze, "lib/utils/config_file.rb".freeze, "lib/utils/editor.rb".freeze, "lib/utils/finder.rb".freeze, "lib/utils/grepper.rb".freeze, "lib/utils/irb.rb".freeze, "lib/utils/irb/irb_server.rb".freeze, "lib/utils/line_blamer.rb".freeze, "lib/utils/line_formatter.rb".freeze, "lib/utils/md5.rb".freeze, "lib/utils/patterns.rb".freeze, "lib/utils/probe.rb".freeze, "lib/utils/probe/probe_client.rb".freeze, "lib/utils/probe/probe_server.rb".freeze, "lib/utils/probe/process_job.rb".freeze, "lib/utils/probe/server_handling.rb".freeze, "lib/utils/ssh_tunnel_specification.rb".freeze, "lib/utils/version.rb".freeze, "lib/utils/xt/source_location_extension.rb".freeze, "tests/test_helper.rb".freeze, "tests/utils_test.rb".freeze, "utils.gemspec".freeze]
|
|
17
17
|
s.homepage = "http://github.com/flori/utils".freeze
|
|
18
18
|
s.licenses = ["GPL-2.0".freeze]
|
|
19
19
|
s.rdoc_options = ["--title".freeze, "Utils - Some useful command line utilities".freeze, "--main".freeze, "README.md".freeze]
|
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|
|
23
23
|
|
|
24
24
|
s.specification_version = 4
|
|
25
25
|
|
|
26
|
-
s.add_development_dependency(%q<gem_hadar>.freeze, [">= 2.16.
|
|
26
|
+
s.add_development_dependency(%q<gem_hadar>.freeze, [">= 2.16.3".freeze])
|
|
27
27
|
s.add_development_dependency(%q<test-unit>.freeze, [">= 0".freeze])
|
|
28
28
|
s.add_runtime_dependency(%q<unix_socks>.freeze, ["~> 0.3".freeze])
|
|
29
29
|
s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.51".freeze])
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: utils
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.83.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Florian Frank
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 2.16.
|
|
18
|
+
version: 2.16.3
|
|
19
19
|
type: :development
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 2.16.
|
|
25
|
+
version: 2.16.3
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: test-unit
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -277,6 +277,7 @@ executables:
|
|
|
277
277
|
- enum
|
|
278
278
|
- git-empty
|
|
279
279
|
- git-versions
|
|
280
|
+
- irb_client
|
|
280
281
|
- json_check
|
|
281
282
|
- long_lines
|
|
282
283
|
- myex
|
|
@@ -306,11 +307,16 @@ extra_rdoc_files:
|
|
|
306
307
|
- lib/utils/finder.rb
|
|
307
308
|
- lib/utils/grepper.rb
|
|
308
309
|
- lib/utils/irb.rb
|
|
310
|
+
- lib/utils/irb/irb_server.rb
|
|
309
311
|
- lib/utils/line_blamer.rb
|
|
310
312
|
- lib/utils/line_formatter.rb
|
|
311
313
|
- lib/utils/md5.rb
|
|
312
314
|
- lib/utils/patterns.rb
|
|
313
|
-
- lib/utils/
|
|
315
|
+
- lib/utils/probe.rb
|
|
316
|
+
- lib/utils/probe/probe_client.rb
|
|
317
|
+
- lib/utils/probe/probe_server.rb
|
|
318
|
+
- lib/utils/probe/process_job.rb
|
|
319
|
+
- lib/utils/probe/server_handling.rb
|
|
314
320
|
- lib/utils/ssh_tunnel_specification.rb
|
|
315
321
|
- lib/utils/version.rb
|
|
316
322
|
- lib/utils/xt/source_location_extension.rb
|
|
@@ -332,6 +338,7 @@ files:
|
|
|
332
338
|
- bin/enum
|
|
333
339
|
- bin/git-empty
|
|
334
340
|
- bin/git-versions
|
|
341
|
+
- bin/irb_client
|
|
335
342
|
- bin/json_check
|
|
336
343
|
- bin/long_lines
|
|
337
344
|
- bin/myex
|
|
@@ -358,11 +365,16 @@ files:
|
|
|
358
365
|
- lib/utils/finder.rb
|
|
359
366
|
- lib/utils/grepper.rb
|
|
360
367
|
- lib/utils/irb.rb
|
|
368
|
+
- lib/utils/irb/irb_server.rb
|
|
361
369
|
- lib/utils/line_blamer.rb
|
|
362
370
|
- lib/utils/line_formatter.rb
|
|
363
371
|
- lib/utils/md5.rb
|
|
364
372
|
- lib/utils/patterns.rb
|
|
365
|
-
- lib/utils/
|
|
373
|
+
- lib/utils/probe.rb
|
|
374
|
+
- lib/utils/probe/probe_client.rb
|
|
375
|
+
- lib/utils/probe/probe_server.rb
|
|
376
|
+
- lib/utils/probe/process_job.rb
|
|
377
|
+
- lib/utils/probe/server_handling.rb
|
|
366
378
|
- lib/utils/ssh_tunnel_specification.rb
|
|
367
379
|
- lib/utils/version.rb
|
|
368
380
|
- lib/utils/xt/source_location_extension.rb
|