raykit 0.0.304 → 0.0.305
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/raykit +4 -2
- data/lib/raykit/command.rb +238 -241
- data/lib/raykit/console.rb +256 -260
- data/lib/raykit/dir.rb +39 -36
- data/lib/raykit/dotnet.rb +90 -90
- data/lib/raykit/environment.rb +77 -77
- data/lib/raykit/git/commit.rb +12 -13
- data/lib/raykit/git/directory.rb +142 -147
- data/lib/raykit/git/files.rb +43 -42
- data/lib/raykit/git/repositories.rb +75 -77
- data/lib/raykit/git/repository.rb +90 -93
- data/lib/raykit/log.rb +39 -37
- data/lib/raykit/logevent.rb +30 -28
- data/lib/raykit/logging.rb +47 -47
- data/lib/raykit/msbuild.rb +19 -11
- data/lib/raykit/nugetpackage.rb +8 -8
- data/lib/raykit/project.rb +261 -274
- data/lib/raykit/rake.rb +29 -31
- data/lib/raykit/runner.rb +37 -37
- data/lib/raykit/secrets.rb +30 -30
- data/lib/raykit/sourceImport.rb +62 -63
- data/lib/raykit/sourceImports.rb +35 -38
- data/lib/raykit/string.rb +14 -12
- data/lib/raykit/tasks.rb +46 -48
- data/lib/raykit/text.rb +24 -22
- data/lib/raykit/timer.rb +24 -22
- data/lib/raykit/version.rb +79 -86
- data/lib/raykit/vstest.rb +17 -15
- data/lib/raykit/zip.rb +35 -37
- data/lib/raykit.rb +14 -14
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ce7014fb0f09e6200f197f0af6d67c51dbce58df476d440d8cb1dc39a99f44d
|
4
|
+
data.tar.gz: ae8b9b47b88762e6778d594bb34a1d6da36f20e5c69f2dbd3ee7fc9c861d09f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 073f890fd9f91ddccf1c3a264865f2b5359b6f315f9434823d6683c5b3d99e0dc4b56dffa1d9e2a7c2cee41a4fa74892c0321318ff466f7237e42c8ddb09c0db
|
7
|
+
data.tar.gz: 6631387820d5366183c50a0f8f0b6fb31eccff7b9c778dab3ea0e89c13b59c66c6ec6c31c86dc4bbc82fc8352ba318444776192905f9bb1b37052c68e36b8b1f
|
data/bin/raykit
CHANGED
data/lib/raykit/command.rb
CHANGED
@@ -1,265 +1,262 @@
|
|
1
|
-
|
2
|
-
require 'timeout'
|
3
|
-
require 'json'
|
4
|
-
require 'yaml'
|
5
|
-
require 'logger'
|
6
|
-
require 'securerandom'
|
1
|
+
# frozen_string_literal: true
|
7
2
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
attr_accessor :timeout
|
15
|
-
# The working directory, defaults the current directory if not specified
|
16
|
-
attr_accessor :directory
|
17
|
-
# The start time
|
18
|
-
attr_accessor :start_time
|
19
|
-
# The execution time in seconds
|
20
|
-
attr_accessor :elapsed
|
21
|
-
attr_accessor :command,:output,:error,:exitstatus
|
22
|
-
attr_accessor :user,:machine
|
23
|
-
attr_accessor :logging_enabled
|
24
|
-
attr_accessor :success_log_level
|
3
|
+
require "open3"
|
4
|
+
require "timeout"
|
5
|
+
require "json"
|
6
|
+
require "yaml"
|
7
|
+
require "logger"
|
8
|
+
require "securerandom"
|
25
9
|
|
26
|
-
|
27
|
-
@timeout=0
|
28
|
-
@directory = Dir.pwd
|
29
|
-
@output = ''
|
30
|
-
@error = ''
|
31
|
-
@exitstatus = 0
|
32
|
-
@user = Environment.user
|
33
|
-
@machine=Environment.machine
|
34
|
-
@logging_enabled = true
|
35
|
-
end
|
10
|
+
BUFFER_SIZE = 1024 unless defined?(BUFFER_SIZE)
|
36
11
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
12
|
+
module Raykit
|
13
|
+
# Functionality to support executing and logging system commands
|
14
|
+
class Command
|
15
|
+
@@commands = []
|
16
|
+
# The timeout in seconds, defaults to 0 if not specified
|
17
|
+
attr_accessor :timeout
|
18
|
+
# The working directory, defaults the current directory if not specified
|
19
|
+
attr_accessor :directory
|
20
|
+
# The start time
|
21
|
+
attr_accessor :start_time
|
22
|
+
# The execution time in seconds
|
23
|
+
attr_accessor :elapsed
|
24
|
+
attr_accessor :command, :output, :error, :exitstatus, :user, :machine, :logging_enabled, :success_log_level
|
49
25
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
pid = thread.pid
|
61
|
-
start = Time.now
|
62
|
-
elapsed = Time.now-start
|
63
|
-
while ((elapsed) < @timeout) and thread.alive?
|
64
|
-
Kernel.select([stdout,stderr], nil, nil, tick)
|
65
|
-
begin
|
66
|
-
@output << stdout.read_nonblock(BUFFER_SIZE)
|
67
|
-
@error << stderr.read_nonblock(BUFFER_SIZE)
|
68
|
-
rescue IO::WaitReadable
|
69
|
-
rescue EOFError
|
70
|
-
@exitstatus=thread.value.exitstatus
|
71
|
-
break
|
72
|
-
end
|
73
|
-
elapsed = Time.now-start
|
74
|
-
end
|
75
|
-
if thread.alive?
|
76
|
-
if(Gem.win_platform?)
|
77
|
-
`taskkill /f /pid #{pid}`
|
78
|
-
else
|
79
|
-
Process.kill("TERM", pid)
|
80
|
-
end
|
81
|
-
@exitstatus=5
|
82
|
-
@error="timed out"
|
83
|
-
else
|
84
|
-
@exitstatus=thread.value.exitstatus
|
85
|
-
end
|
86
|
-
}
|
87
|
-
end
|
88
|
-
@elapsed = timer.elapsed
|
89
|
-
if @logging_enabled
|
90
|
-
log
|
91
|
-
if @exitstatus != 0
|
92
|
-
to_log_event.to_seq
|
93
|
-
else
|
94
|
-
#puts '---logging---'
|
95
|
-
if !@success_log_level.nil?
|
96
|
-
e = to_log_event
|
97
|
-
e["Level"] = "Verbose" if @success_log_level == "Verbose"
|
98
|
-
e["Level"]= "Debug" if @success_log_level == Logger::DEBUG
|
99
|
-
e["Level"] = "Information" if @success_log_level == Logger::INFO
|
100
|
-
e["Level"] = "Warning" if @elapsed > 60*2
|
101
|
-
e.to_seq
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
26
|
+
def init_defaults
|
27
|
+
@timeout = 0
|
28
|
+
@directory = Dir.pwd
|
29
|
+
@output = ""
|
30
|
+
@error = ""
|
31
|
+
@exitstatus = 0
|
32
|
+
@user = Environment.user
|
33
|
+
@machine = Environment.machine
|
34
|
+
@logging_enabled = true
|
35
|
+
end
|
106
36
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
"SourceContext"=>"Raykit::Command",
|
118
|
-
"Category"=>"Command",
|
119
|
-
"Timeout"=>@timeout,
|
120
|
-
"Directory"=>@directory,
|
121
|
-
"Output"=>output,
|
122
|
-
"Error"=>error,
|
123
|
-
"ExitStatus"=>@exitstatus,
|
124
|
-
"Elapsed"=>elapsed_str,
|
125
|
-
"ElapsedSeconds"=>@elapsed
|
126
|
-
})
|
127
|
-
end
|
37
|
+
def initialize(command, timeout = 0, success_log_level = Logger::DEBUG, logging_enabled = true)
|
38
|
+
@@commands = []
|
39
|
+
init_defaults
|
40
|
+
@success_log_level = success_log_level
|
41
|
+
@logging_enabled = logging_enabled
|
42
|
+
@command = command
|
43
|
+
@timeout = timeout
|
44
|
+
run if @command.length.positive?
|
45
|
+
self
|
46
|
+
end
|
128
47
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
"ExitStatus"=>@exitstatus,
|
145
|
-
"Elapsed"=>elapsed_str})
|
146
|
-
log.info event.to_json
|
147
|
-
# ---------------------------
|
48
|
+
def run
|
49
|
+
# puts '---running---'
|
50
|
+
@start_time = Time.now
|
51
|
+
timer = Timer.new
|
52
|
+
if @timeout.zero?
|
53
|
+
@output, @error, process_status = Open3.capture3(@command)
|
54
|
+
@exitstatus = process_status.exitstatus
|
55
|
+
else
|
56
|
+
Open3.popen3(@command, chdir: @directory) do |_stdin, stdout, stderr, thread|
|
57
|
+
tick = 2
|
58
|
+
pid = thread.pid
|
59
|
+
start = Time.now
|
60
|
+
elapsed = Time.now - start
|
61
|
+
while ((elapsed) < @timeout) && thread.alive?
|
62
|
+
Kernel.select([stdout, stderr], nil, nil, tick)
|
148
63
|
begin
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
LOG.log('Raykit.Command',Logger::Severity::INFO,json)
|
156
|
-
else
|
157
|
-
LOG.log('Raykit.Command',Logger::Severity::ERROR,json)
|
158
|
-
end
|
159
|
-
rescue JSON::GeneratorError => ge
|
160
|
-
puts to_hash.to_s
|
161
|
-
puts ge.to_s
|
162
|
-
json=JSON.generate(to_hash)
|
64
|
+
@output << stdout.read_nonblock(BUFFER_SIZE)
|
65
|
+
@error << stderr.read_nonblock(BUFFER_SIZE)
|
66
|
+
rescue IO::WaitReadable
|
67
|
+
rescue EOFError
|
68
|
+
@exitstatus = thread.value.exitstatus
|
69
|
+
break
|
163
70
|
end
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
if
|
168
|
-
|
71
|
+
elapsed = Time.now - start
|
72
|
+
end
|
73
|
+
if thread.alive?
|
74
|
+
if Gem.win_platform?
|
75
|
+
`taskkill /f /pid #{pid}`
|
169
76
|
else
|
170
|
-
|
77
|
+
Process.kill("TERM", pid)
|
171
78
|
end
|
79
|
+
@exitstatus = 5
|
80
|
+
@error = "timed out"
|
81
|
+
else
|
82
|
+
@exitstatus = thread.value.exitstatus
|
83
|
+
end
|
172
84
|
end
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
85
|
+
end
|
86
|
+
@elapsed = timer.elapsed
|
87
|
+
if @logging_enabled
|
88
|
+
log
|
89
|
+
if @exitstatus != 0
|
90
|
+
to_log_event.to_seq
|
91
|
+
else
|
92
|
+
# puts '---logging---'
|
93
|
+
unless @success_log_level.nil?
|
94
|
+
e = to_log_event
|
95
|
+
e["Level"] = "Verbose" if @success_log_level == "Verbose"
|
96
|
+
e["Level"] = "Debug" if @success_log_level == Logger::DEBUG
|
97
|
+
e["Level"] = "Information" if @success_log_level == Logger::INFO
|
98
|
+
e["Level"] = "Warning" if @elapsed > 60 * 2
|
99
|
+
e.to_seq
|
100
|
+
end
|
186
101
|
end
|
102
|
+
end
|
103
|
+
end
|
187
104
|
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
105
|
+
def to_log_event
|
106
|
+
secrets = Secrets.new
|
107
|
+
msg = secrets.hide(@command)
|
108
|
+
level = "Verbose"
|
109
|
+
level = "Warning" if @exitstatus != 0
|
110
|
+
output = @output
|
111
|
+
error = @error
|
112
|
+
output = @output[-1000..-1] if @output.length > 1200
|
113
|
+
error = @error[-1000..-1] if @error.length > 1200
|
114
|
+
Raykit::LogEvent.new(level, msg, {
|
115
|
+
"SourceContext" => "Raykit::Command",
|
116
|
+
"Category" => "Command",
|
117
|
+
"Timeout" => @timeout,
|
118
|
+
"Directory" => @directory,
|
119
|
+
"Output" => output,
|
120
|
+
"Error" => error,
|
121
|
+
"ExitStatus" => @exitstatus,
|
122
|
+
"Elapsed" => elapsed_str,
|
123
|
+
"ElapsedSeconds" => @elapsed,
|
124
|
+
})
|
125
|
+
end
|
126
|
+
|
127
|
+
def log
|
128
|
+
# --- Rolling File JSON -----
|
129
|
+
log = Logger.new("#{Raykit::Environment.log_dir}/Raykit.Commands.txt", "daily")
|
130
|
+
log.formatter = proc do |_severity, _datetime, _progname, msg|
|
131
|
+
"#{msg}\n"
|
132
|
+
end
|
133
|
+
secrets = Secrets.new
|
134
|
+
msg = secrets.hide(@command) # "?"# self.summary(false)
|
135
|
+
level = "Verbose"
|
136
|
+
level = "Warning" if @exitstatus != 0
|
137
|
+
event = Raykit::LogEvent.new(level, msg, {
|
138
|
+
"Timeout" => @timeout,
|
139
|
+
"Directory" => @directory,
|
140
|
+
"Output" => @output,
|
141
|
+
"Error" => @error,
|
142
|
+
"ExitStatus" => @exitstatus,
|
143
|
+
"Elapsed" => elapsed_str,
|
144
|
+
})
|
145
|
+
log.info event.to_json
|
146
|
+
# ---------------------------
|
147
|
+
begin
|
148
|
+
json = JSON.generate(to_hash)
|
149
|
+
log_filename = "#{Environment.get_dev_dir("log")}/Raykit.Command/#{SecureRandom.uuid}.json"
|
150
|
+
log_dir = File.dirname(log_filename)
|
151
|
+
FileUtils.mkdir_p(log_dir) unless Dir.exist?(log_dir)
|
152
|
+
File.open(log_filename, "w") { |f| f.write(json) }
|
153
|
+
if @exitstatus.zero?
|
154
|
+
LOG.log("Raykit.Command", Logger::Severity::INFO, json)
|
155
|
+
else
|
156
|
+
LOG.log("Raykit.Command", Logger::Severity::ERROR, json)
|
193
157
|
end
|
158
|
+
rescue JSON::GeneratorError => e
|
159
|
+
puts to_hash.to_s
|
160
|
+
puts e.to_s
|
161
|
+
json = JSON.generate(to_hash)
|
162
|
+
end
|
163
|
+
end
|
194
164
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
165
|
+
def elapsed_str
|
166
|
+
if elapsed < 1.0
|
167
|
+
end
|
168
|
+
"#{format("%.0f", elapsed)}s"
|
169
|
+
end
|
199
170
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
171
|
+
def summary(show_directory = false)
|
172
|
+
checkmark = "\u2713"
|
173
|
+
# warning="\u26A0"
|
174
|
+
error = "\u0058"
|
175
|
+
symbol = Rainbow(checkmark.encode("utf-8")).green
|
176
|
+
symbol = Rainbow(error.encode("utf-8")).red if @exitstatus != 0
|
177
|
+
if show_directory
|
178
|
+
puts "#{symbol} #{elapsed_str.rjust(4)} #{Rainbow(SECRETS.hide(@command)).yellow} (#{@directory})"
|
179
|
+
else
|
180
|
+
puts "#{symbol} #{elapsed_str.rjust(4)} #{Rainbow(SECRETS.hide(@command)).yellow}" # + " (#{@directory})"
|
181
|
+
end
|
182
|
+
# puts symbol + " " + elapsed_str.rjust(4) + " " + Rainbow(SECRETS.hide(@command)).yellow# + " (#{@directory})"
|
183
|
+
end
|
205
184
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
hash[:elapsed] = @elapsed
|
213
|
-
hash[:output] = @output.force_encoding("ISO-8859-1").encode("UTF-8")
|
214
|
-
hash[:error] = @error.force_encoding("ISO-8859-1").encode("UTF-8")
|
215
|
-
hash[:exitstatus] = @exitstatus
|
216
|
-
hash[:user] = @user
|
217
|
-
hash[:machine] = @machine
|
218
|
-
hash[:context] = "Raykit.Command"
|
219
|
-
hash
|
220
|
-
end
|
185
|
+
def details
|
186
|
+
# summary
|
187
|
+
puts @output
|
188
|
+
puts @error
|
189
|
+
puts
|
190
|
+
end
|
221
191
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
@start_time=hash["start_time"]
|
227
|
-
@elapsed=hash["elapsed"]
|
228
|
-
@output=hash["output"]
|
229
|
-
@error=hash["error"]
|
230
|
-
@exitstatus=hash["exitstatus"]
|
231
|
-
@user=hash["user"] if(hash.include?("user"))
|
232
|
-
@machine=hash["machine"] if(hash.include?("machine"))
|
233
|
-
end
|
192
|
+
def save
|
193
|
+
filename = "#{Environment.get_dev_dir("log")}/Commands/#{SecureRandom.uuid}"
|
194
|
+
log_dir = File.dirname(filename)
|
195
|
+
FileUtils.mkdir_p(log_dir) unless Dir.exist?(log_dir)
|
234
196
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
197
|
+
File.open(filename, "w") do |f|
|
198
|
+
f.write(JSON.pretty_generate(to_hash))
|
199
|
+
end
|
200
|
+
self
|
201
|
+
end
|
240
202
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
203
|
+
def to_hash
|
204
|
+
hash = {}
|
205
|
+
hash[:command] = @command
|
206
|
+
hash[:directory] = @directory
|
207
|
+
hash[:timeout] = @timeout
|
208
|
+
hash[:start_time] = @start_time
|
209
|
+
hash[:elapsed] = @elapsed
|
210
|
+
hash[:output] = @output.force_encoding("ISO-8859-1").encode("UTF-8")
|
211
|
+
hash[:error] = @error.force_encoding("ISO-8859-1").encode("UTF-8")
|
212
|
+
hash[:exitstatus] = @exitstatus
|
213
|
+
hash[:user] = @user
|
214
|
+
hash[:machine] = @machine
|
215
|
+
hash[:context] = "Raykit.Command"
|
216
|
+
hash
|
217
|
+
end
|
218
|
+
|
219
|
+
def from_hash(hash)
|
220
|
+
@command = hash["command"]
|
221
|
+
@directory = hash["directory"]
|
222
|
+
@timeout = hash["timeout"]
|
223
|
+
@start_time = hash["start_time"]
|
224
|
+
@elapsed = hash["elapsed"]
|
225
|
+
@output = hash["output"]
|
226
|
+
@error = hash["error"]
|
227
|
+
@exitstatus = hash["exitstatus"]
|
228
|
+
@user = hash["user"] if hash.include?("user")
|
229
|
+
@machine = hash["machine"] if hash.include?("machine")
|
230
|
+
end
|
231
|
+
|
232
|
+
def self.parse(json)
|
233
|
+
cmd = Command.new("")
|
234
|
+
cmd.from_hash(JSON.parse(json))
|
235
|
+
cmd
|
236
|
+
end
|
237
|
+
|
238
|
+
def self.parse_yaml_commands(yaml)
|
239
|
+
# commands=Array.new()
|
240
|
+
data = YAML.safe_load(yaml)
|
241
|
+
commands = get_script_commands(data)
|
242
|
+
end
|
243
|
+
|
244
|
+
def self.get_script_commands(hash)
|
245
|
+
commands = []
|
246
|
+
if hash.key?("script")
|
247
|
+
hash["script"].each do |cmd|
|
248
|
+
commands << cmd
|
245
249
|
end
|
250
|
+
end
|
251
|
+
hash.each do |_k, v|
|
252
|
+
next unless v.is_a?(Hash)
|
246
253
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
hash['script'].each{|cmd|
|
251
|
-
commands << cmd
|
252
|
-
}
|
253
|
-
end
|
254
|
-
hash.each{|k,v|
|
255
|
-
if(v.is_a?(Hash))
|
256
|
-
subcommands=get_script_commands(v)
|
257
|
-
subcommands.each{|c|
|
258
|
-
commands << c
|
259
|
-
}
|
260
|
-
end
|
261
|
-
}
|
262
|
-
commands
|
254
|
+
subcommands = get_script_commands(v)
|
255
|
+
subcommands.each do |c|
|
256
|
+
commands << c
|
263
257
|
end
|
258
|
+
end
|
259
|
+
commands
|
264
260
|
end
|
265
|
-
end
|
261
|
+
end
|
262
|
+
end
|