ro_thor 4.5.2 → 4.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ro_thor.rb +6 -3
- data/lib/ro_thor/http.rb +5 -0
- data/lib/ro_thor/ssh.rb +21 -18
- data/spec/lib/ro_thor/ssh_spec.rb +19 -3
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40a5e6127722a684605524581c7e89944b58e56f1dd70b6a17ddea65bc2ef18e
|
4
|
+
data.tar.gz: b59e1dafcef1f636262269db13c6a4075c3d3aff5433f59d7754dd6dcb9a8f42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0e7640798240171dc4b27eb498606691985848b82b5fdc18bf1a34f886a2382503ed6eec44c4fe36c351517e7f919790ad4584a9245a9a72bd91125d52a21f8
|
7
|
+
data.tar.gz: 1284f79d0f46079b6ed0b1833b59449f022c4e8a0a39a7cd3c558db7100f23b4de93e7ab6ffbbfac9213efe02095ba3d9e94c2526480e20ed0b889962b896720
|
data/lib/ro_thor.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
$LOAD_PATH.unshift(Pathname.new(__FILE__).parent.to_s)
|
3
|
+
require 'shellwords'
|
3
4
|
require 'thor'
|
4
5
|
require 'open3'
|
5
6
|
require 'ro_thor/base'
|
@@ -54,7 +55,7 @@ class RoThor < Thor
|
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
57
|
-
def open_url(url, user_data_dir=nil, *args, &blk)
|
58
|
+
def open_url(url, user_data_dir = nil, *args, &blk)
|
58
59
|
user_data_dir ||= "#{ENV['HOME']}/.config/google-chrome"
|
59
60
|
sys %Q(google-chrome --user-data-dir=#{user_data_dir.strip} "#{url}")
|
60
61
|
end
|
@@ -63,6 +64,10 @@ class RoThor < Thor
|
|
63
64
|
RoFile.basename(Dir.pwd)
|
64
65
|
end
|
65
66
|
|
67
|
+
def sh_esc(str)
|
68
|
+
Shellwords.escape(str)
|
69
|
+
end
|
70
|
+
|
66
71
|
def cur_pj_name2(*args, &blk)
|
67
72
|
cur_pj_name.gsub(%r{^ro_}, "")
|
68
73
|
end
|
@@ -76,7 +81,6 @@ class RoThor < Thor
|
|
76
81
|
end
|
77
82
|
|
78
83
|
|
79
|
-
|
80
84
|
def down_d(*args, &blk)
|
81
85
|
RoFile.join("/media/roroco/disk750/Downloads", *args, &blk)
|
82
86
|
end
|
@@ -147,6 +151,5 @@ class RoThor < Thor
|
|
147
151
|
sh "xdotool windowactivate #{wins.first.strip}"
|
148
152
|
end
|
149
153
|
end
|
150
|
-
|
151
154
|
end
|
152
155
|
|
data/lib/ro_thor/http.rb
CHANGED
data/lib/ro_thor/ssh.rb
CHANGED
@@ -4,6 +4,7 @@ require 'net/ssh'
|
|
4
4
|
require_relative 'helper'
|
5
5
|
require_relative 'sh'
|
6
6
|
require_relative 'ro_file'
|
7
|
+
require 'term/ansicolor'
|
7
8
|
|
8
9
|
class RoThor
|
9
10
|
class SSH
|
@@ -12,24 +13,22 @@ class RoThor
|
|
12
13
|
|
13
14
|
attr_accessor :user_at_host, :se
|
14
15
|
|
15
|
-
def initialize(user_at_host
|
16
|
+
def initialize(user_at_host)
|
16
17
|
@user_at_host = user_at_host
|
17
18
|
m = user_at_host.match(%r{(.*)@(.*)})
|
18
19
|
@se = ::Net::SSH.start(m[2], m[1])
|
19
20
|
end
|
20
21
|
|
21
|
-
def down(from, to
|
22
|
+
def down(from, to)
|
22
23
|
RoFile.msp(to)
|
23
24
|
sys "scp #{user_at_host}:#{from} #{to}"
|
24
25
|
end
|
25
26
|
|
26
|
-
def up(from, to
|
27
|
+
def up(from, to)
|
27
28
|
sys "scp #{from} #{user_at_host}:#{to}"
|
28
29
|
end
|
29
30
|
|
30
|
-
def sh(*args,
|
31
|
-
args_clone, opts = args.ro_opts
|
32
|
-
|
31
|
+
def sh(*args, **opts)
|
33
32
|
cmd = args.join(" ")
|
34
33
|
msg = opts[:status] || cmd
|
35
34
|
|
@@ -43,8 +42,8 @@ class RoThor
|
|
43
42
|
stderr_lines = []
|
44
43
|
|
45
44
|
ch = se.open_channel do |ch|
|
46
|
-
ch.exec(
|
47
|
-
|
45
|
+
ch.exec(cmd) do |ch, success|
|
46
|
+
if !success
|
48
47
|
raise ::RoErr::RmtErr, "could not exe cmd: #{command.inspect}"
|
49
48
|
end
|
50
49
|
|
@@ -60,7 +59,7 @@ class RoThor
|
|
60
59
|
unless data.match(%r{cannot set terminal process group \((-)?\d+\): Inappropriate ioctl for device})\
|
61
60
|
or data.match(%r{no job control in this shell})
|
62
61
|
# or data.match(%Q(Cookie#domain returns dot-less domain name now. Use Cookie#dot_domain if you need "." at the beginning.))
|
63
|
-
if data.
|
62
|
+
if data.length > 100
|
64
63
|
err_msg = "\nerr_msg:\n#{data}"
|
65
64
|
else
|
66
65
|
err_msg = "err_msg:#{data}"
|
@@ -76,12 +75,14 @@ class RoThor
|
|
76
75
|
ch.wait
|
77
76
|
ch.close
|
78
77
|
|
78
|
+
stdout = out_a.join('')
|
79
|
+
|
79
80
|
stderr_lines = stderr_lines.hits
|
80
81
|
stderr_lines.delete_if do |l|
|
81
82
|
l.match(%r{^/.*warning\:.*$})
|
82
83
|
end
|
83
84
|
|
84
|
-
|
85
|
+
if !stderr_lines.empty?
|
85
86
|
if stderr_lines.any? do |l|
|
86
87
|
l.match(%r{\tfrom})
|
87
88
|
end
|
@@ -97,19 +98,21 @@ class RoThor
|
|
97
98
|
end
|
98
99
|
end
|
99
100
|
|
100
|
-
e = RoErr::RmtErr.new(uncol(err_msg_arr.join)
|
101
|
+
e = RoErr::RmtErr.new(stdout + uncol(err_msg_arr.join))
|
102
|
+
e.set_backtrace(bt.map(&:strip).hits)
|
101
103
|
else
|
102
|
-
e = RoErr::RmtErr.new(uncol(stderr_lines.join("\n"))
|
104
|
+
e = RoErr::RmtErr.new(stdout + uncol(stderr_lines.join("\n")))
|
105
|
+
e.set_backtrace(clr)
|
103
106
|
end
|
104
107
|
|
105
|
-
if ::RoCell::Rmt.ignore_err
|
106
|
-
|
107
|
-
else
|
108
|
-
|
109
|
-
end
|
108
|
+
# if ::RoCell::Rmt.ignore_err
|
109
|
+
# out_ins.warn e
|
110
|
+
# else
|
111
|
+
raise e
|
112
|
+
# end
|
110
113
|
end
|
111
114
|
|
112
|
-
|
115
|
+
stdout
|
113
116
|
end
|
114
117
|
|
115
118
|
def uncol(*args, &blk)
|
@@ -2,8 +2,24 @@ require 'rails_helper'
|
|
2
2
|
require 'ro_thor/ssh'
|
3
3
|
|
4
4
|
describe 'RoThor::Rmt.new' do
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
describe "sh" do
|
6
|
+
it "1" do
|
7
|
+
s = RoThor::SSH.new('root@techprpr')
|
8
|
+
s.sh('ls;ls')
|
9
|
+
end
|
10
|
+
|
11
|
+
it "capture err" do
|
12
|
+
s = RoThor::SSH.new("root@techprpr")
|
13
|
+
begin
|
14
|
+
# raise "err"
|
15
|
+
s.sh("lrekljeklwjl")
|
16
|
+
rescue Exception => e
|
17
|
+
puts "e:#{e} ---- #{File.basename __FILE__}:#{__LINE__}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "sh with regex" do
|
23
|
+
|
8
24
|
end
|
9
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ro_thor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ''
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 4.2.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: term-ansicolor
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.7.1
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.7.1
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: nokogiri
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,10 +140,10 @@ signing_key:
|
|
126
140
|
specification_version: 4
|
127
141
|
summary: ''
|
128
142
|
test_files:
|
143
|
+
- spec/spec_helper.rb
|
129
144
|
- spec/lib/ro_cmd/thor/dp_spec.rb
|
145
|
+
- spec/lib/core_ext/array_spec.rb
|
130
146
|
- spec/lib/ro_thor/ssh_spec.rb
|
131
147
|
- spec/lib/ro_thor/ro_err_spec.rb
|
132
|
-
- spec/lib/core_ext/array_spec.rb
|
133
148
|
- spec/rails_helper.rb
|
134
|
-
- spec/spec_helper.rb
|
135
149
|
- spec/mysql/my.cnf
|