toolrack 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/toolrack.rb +34 -1
- data/lib/toolrack/condition_utils.rb +5 -1
- data/lib/toolrack/exception_utils.rb +12 -9
- data/lib/toolrack/process_utils.rb +103 -0
- data/lib/toolrack/runtime_utils.rb +24 -0
- data/lib/toolrack/version.rb +2 -2
- data/process_test/backtick_test.rb +2 -0
- data/process_test/pty_test.rb +0 -0
- data/process_test/shell_test.rb +14 -0
- data/process_test/system_test.rb +3 -0
- data/toolrack.gemspec +6 -4
- metadata +31 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9695907a18e7af223dc46afdede9aadf6a63860cd85600eac575d1707f92122a
|
4
|
+
data.tar.gz: 33b7a5e328a97b336f75d74e87adfd11c9d2e4e4db65096db9657cbc8d438a3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed2140ad2e0ddd44977b8375e02f4d81ce30e2c5c3c8ade312d0ebb24213373d38783a3f509994f23bb866977d74825e42f8ea585f78a1bd64afdb24d017294c
|
7
|
+
data.tar.gz: ec78c82697275f8ad85900892a017dfe0be6edbc5a19f761d382d53dcf372c9f3c68f7d7bb4678b7af02d25a77346f2ba082c6d099d002ac563c9173fb40d8d3
|
data/lib/toolrack.rb
CHANGED
@@ -1,11 +1,44 @@
|
|
1
1
|
require "toolrack/version"
|
2
2
|
|
3
|
+
require 'tlogger'
|
4
|
+
require 'singleton'
|
5
|
+
|
3
6
|
require_relative 'toolrack/exception_utils'
|
4
7
|
require_relative 'toolrack/condition_utils'
|
8
|
+
#require_relative 'toolrack/process_utils'
|
9
|
+
require_relative 'toolrack/runtime_utils'
|
5
10
|
|
6
11
|
module Antrapol
|
7
|
-
module
|
12
|
+
module ToolRack
|
8
13
|
class Error < StandardError; end
|
9
14
|
# Your code goes here...
|
15
|
+
|
16
|
+
class GlobalConf
|
17
|
+
include Singleton
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
class Logger
|
22
|
+
include Singleton
|
23
|
+
include Antrapol::ToolRack::ConditionUtils
|
24
|
+
|
25
|
+
attr_reader :glogger
|
26
|
+
def initialize
|
27
|
+
# boolean
|
28
|
+
loggerDebug = ENV['TOOLRACK_DEBUG']
|
29
|
+
logFile = ENV['TOOLRACK_LOGFILE']
|
30
|
+
maxLogNo = ENV['TOOLRACK_MAX_LOGFILE'] || 10
|
31
|
+
logFileSize = ENV['TOOLRACK_MAX_LOGFILE_SIZE'] || 10*1024*1024
|
32
|
+
|
33
|
+
if not is_empty?(loggerDebug) and loggerDebug
|
34
|
+
@glogger = Tlogger.new(STDOUT)
|
35
|
+
elsif not is_empty?(logFile)
|
36
|
+
@glogger = Tlogger.new(logFile,maxLogNo,logFileSize)
|
37
|
+
else
|
38
|
+
@glogger = Tlogger.new('toolrack.log',maxLogNo,logFileSize)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
10
43
|
end
|
11
44
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
|
3
3
|
module Antrapol
|
4
|
-
module
|
4
|
+
module ToolRack
|
5
5
|
module ConditionUtils
|
6
6
|
|
7
7
|
def is_empty?(obj)
|
@@ -14,6 +14,10 @@ module Antrapol
|
|
14
14
|
end
|
15
15
|
end # is_empty?
|
16
16
|
|
17
|
+
def not_empty?(obj)
|
18
|
+
!is_empty?(obj)
|
19
|
+
end # not empty
|
20
|
+
|
17
21
|
end # ConditionUtils
|
18
22
|
end # MyToolRack
|
19
23
|
end # Antrapol
|
@@ -1,41 +1,44 @@
|
|
1
1
|
|
2
|
-
require_relative '
|
2
|
+
require_relative 'condition_utils'
|
3
3
|
|
4
4
|
module Antrapol
|
5
|
-
module
|
5
|
+
module ToolRack
|
6
6
|
module ExceptionUtils
|
7
|
-
include Antrapol::
|
7
|
+
include Antrapol::ToolRack::ConditionUtils
|
8
8
|
|
9
9
|
# raise_if_empty
|
10
10
|
# Raise the given (or default if not given) exception if the val given is empty
|
11
11
|
# val - variable/object that shall be tested for emptiness
|
12
12
|
# message - message to be thrown if it is true
|
13
13
|
# error - exception object to be thrown
|
14
|
-
def raise_if_empty(val, message, error = Antrapol::
|
14
|
+
def raise_if_empty(val, message, error = Antrapol::ToolRack::Error)
|
15
15
|
raise_error(message,error) if is_empty?(val)
|
16
16
|
end # raise_if_empty
|
17
|
+
alias_method :raise_if_empty?, :raise_if_empty
|
17
18
|
|
18
19
|
#
|
19
20
|
# raise_if_false
|
20
21
|
#
|
21
|
-
def raise_if_false(bool, message, error = Antrapol::
|
22
|
+
def raise_if_false(bool, message, error = Antrapol::ToolRack::Error)
|
22
23
|
if not bool
|
23
24
|
raise_error(message,error)
|
24
25
|
end
|
25
26
|
end # raise_if_false
|
27
|
+
alias_method :raise_if_false?, :raise_if_false
|
26
28
|
|
27
29
|
#
|
28
30
|
# raise_if_true
|
29
31
|
#
|
30
|
-
def raise_if_true(bool, message, error = Antrapol::
|
32
|
+
def raise_if_true(bool, message, error = Antrapol::ToolRack::Error)
|
31
33
|
raise_if_false(!bool, message, error)
|
32
34
|
end # raise_if_true
|
35
|
+
alias_method :raise_if_true?, :raise_if_true
|
33
36
|
|
34
37
|
protected
|
35
|
-
def raise_error(message, error = Antrapol::
|
38
|
+
def raise_error(message, error = Antrapol::ToolRack::Error)
|
36
39
|
if error.nil?
|
37
40
|
if @default_exception.nil?
|
38
|
-
raise Antrapol::
|
41
|
+
raise Antrapol::ToolRack::Error, message
|
39
42
|
else
|
40
43
|
raise @default_exception, message
|
41
44
|
end
|
@@ -45,5 +48,5 @@ module Antrapol
|
|
45
48
|
end # raise_error
|
46
49
|
|
47
50
|
end # ExceptionUtils
|
48
|
-
end #
|
51
|
+
end # ToolRack
|
49
52
|
end # Antrapol
|
@@ -0,0 +1,103 @@
|
|
1
|
+
|
2
|
+
require 'pty'
|
3
|
+
require 'expect'
|
4
|
+
require 'io/console'
|
5
|
+
require 'tlogger'
|
6
|
+
require 'open3'
|
7
|
+
|
8
|
+
|
9
|
+
module Antrapol
|
10
|
+
module ToolRack
|
11
|
+
module ProcessUtils
|
12
|
+
|
13
|
+
# backtick
|
14
|
+
# backtick will only return at the end of the process.
|
15
|
+
# If in the event there is a prompt to user, this should nto be used.
|
16
|
+
def basic_exec(cmd)
|
17
|
+
Antrapol::ToolRack::Logger.instance.glogger.debug "Basic shell exec command : #{cmd}"
|
18
|
+
`#{cmd}`
|
19
|
+
end # basic_shell_exec
|
20
|
+
|
21
|
+
# system
|
22
|
+
# System call link the stdout and stdin to the calling process and idea
|
23
|
+
# to call mild interactive process
|
24
|
+
def system_exec(cmd, opts = { }, &block)
|
25
|
+
Antrapol::ToolRack::Logger.instance.glogger.debug "System exec command : #{cmd}"
|
26
|
+
system(cmd)
|
27
|
+
$.
|
28
|
+
end # system_exec
|
29
|
+
|
30
|
+
#def popen_exec(cmd, opts = { }, &block)
|
31
|
+
# puts "Cmd : #{cmd}"
|
32
|
+
# IO.popen(cmd, "r+") do |io|
|
33
|
+
# puts io.gets
|
34
|
+
# puts io.gets
|
35
|
+
# puts io.gets
|
36
|
+
# end
|
37
|
+
#end
|
38
|
+
|
39
|
+
def popen3_exec(cmd, opts = { }, &block)
|
40
|
+
Antrapol::ToolRack::Logger.instance.glogger.debug "Popen3 exec command : #{cmd}"
|
41
|
+
stdout, stderr, status = Open3.capture3(cmd)
|
42
|
+
block.call(:popen_exec, { output: stdout, error: stderr, status: status })
|
43
|
+
end
|
44
|
+
|
45
|
+
def pty_exec(cmd, opts = { }, &block)
|
46
|
+
|
47
|
+
Antrapol::ToolRack::Logger.instance.glogger.debug "PTY exec command : #{cmd}"
|
48
|
+
|
49
|
+
logger = opts[:logger] || Tlogger.new(STDOUT)
|
50
|
+
expect = opts[:expect] || { }
|
51
|
+
bufSize = opts[:intBufSize] || 1024000
|
52
|
+
|
53
|
+
if bufSize != nil and bufSize.to_i > 0
|
54
|
+
else
|
55
|
+
bufSize = 1024000
|
56
|
+
end
|
57
|
+
|
58
|
+
logger.debug "Command : #{cmd}"
|
59
|
+
PTY.spawn(cmd[0], *(cmd[1..-1])) do |pout,pin,pid| #, 'env TERM=ansi') do |stdout, stdin, pid|
|
60
|
+
|
61
|
+
pin.sync = true
|
62
|
+
|
63
|
+
begin
|
64
|
+
loop do
|
65
|
+
dat = []
|
66
|
+
loop do
|
67
|
+
d = pout.sysread(bufSize)
|
68
|
+
dat << d
|
69
|
+
break if d.length < bufSize
|
70
|
+
end
|
71
|
+
#dat = dat.join("\r\n")
|
72
|
+
|
73
|
+
if block
|
74
|
+
block.call(:inspect, { data: dat, output: pout, input: pin })
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
rescue EOFError => ex
|
79
|
+
logger.error "EOF : #{ex}"
|
80
|
+
#clog "EOF reached. Waiting to kill process.", :debug, :os_cmd
|
81
|
+
Process.wait(pid)
|
82
|
+
#clog "Processed killed.", :debug, :os_cmd
|
83
|
+
rescue Exception => ex
|
84
|
+
logger.error ex.message
|
85
|
+
logger.error ex.backtrace.join("\n")
|
86
|
+
#clog ex.message, :error, :os_cmd
|
87
|
+
#clog ex.backtrace.join("\n"), :error, :os_cmd
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
# end PTY.spawn() method
|
92
|
+
|
93
|
+
$?.exitstatus
|
94
|
+
|
95
|
+
end # pty_exec
|
96
|
+
|
97
|
+
end # module ProcessUtils
|
98
|
+
|
99
|
+
class ProcessUtilsEngine
|
100
|
+
extend ProcessUtils
|
101
|
+
end
|
102
|
+
end # module ToolRack
|
103
|
+
end # module Antrapol
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Antrapol
|
4
|
+
module ToolRack
|
5
|
+
module RuntimeUtils
|
6
|
+
|
7
|
+
def detect_os
|
8
|
+
case RbConfig::CONFIG['host_os']
|
9
|
+
when /cygwin|mswin|mingw|bccwin|wince|emx/
|
10
|
+
:win
|
11
|
+
when /darwin|mac/
|
12
|
+
:mac
|
13
|
+
else
|
14
|
+
:linux
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def detect_ruby
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/toolrack/version.rb
CHANGED
File without changes
|
data/toolrack.gemspec
CHANGED
@@ -2,19 +2,19 @@ require_relative 'lib/toolrack/version'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "toolrack"
|
5
|
-
spec.version = Antrapol::
|
5
|
+
spec.version = Antrapol::ToolRack::VERSION
|
6
6
|
spec.authors = ["Chris"]
|
7
7
|
spec.email = ["chrisliaw@antrapol.com"]
|
8
8
|
|
9
9
|
spec.summary = %q{Collection of simple utilities but I find it increase clarity}
|
10
10
|
spec.description = %q{Just collections of utilities}
|
11
|
-
spec.homepage = ""
|
11
|
+
spec.homepage = "https://github.com/chrisliaw/toolrack"
|
12
12
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
13
|
|
14
14
|
#spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/chrisliaw/toolrack"
|
18
18
|
#spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
19
19
|
|
20
20
|
# Specify which files should be added to the gem when it is released.
|
@@ -25,4 +25,6 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.bindir = "exe"
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency "tlogger", "~> 0.21"
|
28
30
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toolrack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
12
|
-
dependencies:
|
11
|
+
date: 2020-10-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: tlogger
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.21'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.21'
|
13
27
|
description: Just collections of utilities
|
14
28
|
email:
|
15
29
|
- chrisliaw@antrapol.com
|
@@ -28,12 +42,20 @@ files:
|
|
28
42
|
- lib/toolrack.rb
|
29
43
|
- lib/toolrack/condition_utils.rb
|
30
44
|
- lib/toolrack/exception_utils.rb
|
45
|
+
- lib/toolrack/process_utils.rb
|
46
|
+
- lib/toolrack/runtime_utils.rb
|
31
47
|
- lib/toolrack/version.rb
|
48
|
+
- process_test/backtick_test.rb
|
49
|
+
- process_test/pty_test.rb
|
50
|
+
- process_test/shell_test.rb
|
51
|
+
- process_test/system_test.rb
|
32
52
|
- toolrack.gemspec
|
33
|
-
homepage:
|
53
|
+
homepage: https://github.com/chrisliaw/toolrack
|
34
54
|
licenses: []
|
35
|
-
metadata:
|
36
|
-
|
55
|
+
metadata:
|
56
|
+
homepage_uri: https://github.com/chrisliaw/toolrack
|
57
|
+
source_code_uri: https://github.com/chrisliaw/toolrack
|
58
|
+
post_install_message:
|
37
59
|
rdoc_options: []
|
38
60
|
require_paths:
|
39
61
|
- lib
|
@@ -48,8 +70,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
70
|
- !ruby/object:Gem::Version
|
49
71
|
version: '0'
|
50
72
|
requirements: []
|
51
|
-
rubygems_version: 3.
|
52
|
-
signing_key:
|
73
|
+
rubygems_version: 3.1.4
|
74
|
+
signing_key:
|
53
75
|
specification_version: 4
|
54
76
|
summary: Collection of simple utilities but I find it increase clarity
|
55
77
|
test_files: []
|