xlogin 0.15.7 → 0.16.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7b8fd89987339e341998c05917253187ab98bf73001b307eefcd4fa6f5db15c
4
- data.tar.gz: adc3c1a866e2cc9437ad90d7938ed9076b2eb21f1d9a37c81b62d58ea1e85bad
3
+ metadata.gz: 342f00cdb5f923c597cf7f40c1d4cf35c8cb7ecb596caa8457c05b09c9b7bd2d
4
+ data.tar.gz: 4a7f6f3041a53b942ea434a8417b6b150397fed622e1a2f7a3b7dc0148f87865
5
5
  SHA512:
6
- metadata.gz: b0c4de1d7d7d30d47edf174c393968b218a9937f1bb535a2b3f888428f52b13535b15787d0464c2489a0005ccb2f36d41648b5e8cb668f489ee9bfa88154fbf9
7
- data.tar.gz: 10971772a9085d3afdab205e73b6a1f85273256d43e4ee099348fab381a157cae7a7f0fcfbe73811ab0692856bb7e4374c0bf4ef179da0372210295aa50e9e2b
6
+ metadata.gz: 7bb500f47f1b95b5f29c3f10083df805a1dd09cb23ce3696719a8bcffe00812cd947b3001743085663e698628c1d7ed78aa1c2db9c77e434791ad2bf32f0acb9
7
+ data.tar.gz: abeccd10d1efca609233477172d1926bd3003f05ac4faec3d81b8750c096f7745f0c886fe3801143a52d09afabfcafecbd5c253480ec4c899e0b60bf1d5f7236
data/lib/xlogin.rb CHANGED
@@ -21,14 +21,14 @@ module Xlogin
21
21
  end
22
22
 
23
23
  class << self
24
- def list(*patterns)
25
- factory.list_hostinfo(*patterns)
26
- end
27
-
28
24
  def find(*patterns)
29
25
  list(*patterns).first
30
26
  end
31
27
 
28
+ def list(*patterns)
29
+ factory.list_hostinfo(*patterns)
30
+ end
31
+
32
32
  def get(args, **opts, &block)
33
33
  session = case args
34
34
  when Hash then factory.build(**args.merge(**opts))
@@ -26,14 +26,14 @@ module Xlogin
26
26
  end
27
27
 
28
28
  def list_hostinfo(*patterns)
29
- patterns = patterns.flat_map{ |e| e.split(/\s+/) }.compact
29
+ patterns = patterns.compact.flat_map{ |e| e.split(/\s+/) }
30
30
  return @inventory.values if patterns.empty?
31
31
 
32
32
  values1 = patterns.map do |pattern|
33
33
  values2 = pattern.split(',').map do |entry|
34
34
  key, val = entry.to_s.split(':')
35
35
  key, val = 'name', key if val.nil?
36
- @inventory.values.select{ |e| File.fnmatch(val, e[key.to_sym]) }
36
+ @inventory.values.select{ |e| File.fnmatch(val, e[key.to_sym], File::FNM_EXTGLOB) }
37
37
  end
38
38
  values2.reduce(&:&) || []
39
39
  end
@@ -10,13 +10,20 @@ module Xlogin
10
10
  class << self
11
11
  include Rake::DSL
12
12
 
13
- def generate(*patterns, **opts, &block)
13
+ def all(*patterns, &block)
14
14
  description = Rake.application.last_description
15
- hostnames = Xlogin.list(*patterns).map{ |e| e[:name] }
15
+ task all: Xlogin.list(*patterns).map{ |e| e[:name] }
16
16
 
17
- task 'all' => hostnames unless opts[:all] == false
17
+ desc description
18
+ generate(*patterns, &block)
19
+ end
20
+
21
+ def generate(*patterns, &block)
22
+ description = Rake.application.last_description
23
+
24
+ hostnames = Xlogin.list(*patterns).map{ |e| e[:name] }
18
25
  hostnames.each do |hostname|
19
- desc "#{description} with #{hostname}"
26
+ desc "#{description} - #{hostname}" if description
20
27
  RakeTask.new(hostname, &block)
21
28
  end
22
29
  end
@@ -78,41 +85,41 @@ module Xlogin
78
85
 
79
86
  def run_task
80
87
  buffer = StringIO.new
81
- loggers = []
82
- loggers << log if log
83
- loggers << $stdout if !silent && !Rake.application.options.always_multitask
84
- loggers << buffer
88
+ loggers = [buffer]
89
+ loggers << log if log
90
+ loggers << STDOUT if !silent && !Rake.application.options.always_multitask
85
91
 
86
92
  session = Xlogin.get(name, log: loggers, timeout: timeout)
93
+ instance_exec(session, &@runner)
87
94
 
88
- @runner.call(session)
89
- $stdout.print log_text(buffer.string) if !silent && Rake.application.options.always_multitask
90
-
95
+ print(buffer.string) if !silent && Rake.application.options.always_multitask
91
96
  return true
92
97
  rescue => e
93
98
  RakeTask.shutdown! if fail_on_error
94
99
 
95
- session.comment(e.to_s, lf: false, color: :red) if session
96
- if Rake.application.options.always_multitask && !buffer.string.empty?
97
- $stderr.print log_text(buffer.string + "\n").colorize(color: :red)
98
- end
99
-
100
+ session.log_message(e.to_s.colorize(color: :red)) if session
101
+ print(buffer.string + "\n", color: :red) if Rake.application.options.always_multitask
100
102
  return false
101
103
  ensure
102
104
  session.close rescue nil
103
105
  end
104
106
 
105
- def log_text(text)
106
- text.lines.map{ |line| "#{Time.now.iso8601} #{name}\t|#{line.gsub(/^.*\r/, '')}" }.join
107
- end
107
+ def puts(text, **opts)
108
+ return text.each { |e| puts(e, **opts) } if text.kind_of?(Array)
108
109
 
109
- end
110
+ text = text.to_s
111
+ text = text + "\n" unless text[-1] == "\n"
112
+ print(text, **opts)
113
+ end
110
114
 
111
- module SessionModule
115
+ def print(text, **opts)
116
+ text = text.to_s
117
+ return if text.empty?
112
118
 
113
- def comment(line, lf: true, **color)
114
- write_log(line.chomp.colorize({color: :light_white}.merge(**color)))
115
- cmd('') if lf
119
+ text = text.gsub("\r", '')
120
+ text = text.lines.map{ |text| "#{name}\t|#{text}" }.join if Rake.application.options.always_multitask
121
+ text = text.colorize(**opts)
122
+ $stdout.print(text)
116
123
  end
117
124
 
118
125
  end
@@ -44,8 +44,8 @@ module Xlogin
44
44
  super(args)
45
45
  rescue => e
46
46
  unless (num_try += 1) > (@config.retry || 0)
47
- sleep 1.0
48
- retry
47
+ sleep 2.0 ** (num_try)
48
+ retry
49
49
  end
50
50
  raise e
51
51
  end
@@ -84,7 +84,7 @@ module Xlogin
84
84
  return waitfor(prompt_pattern) if args.empty?
85
85
 
86
86
  line = super(*args) do |recv|
87
- write_log(recv)
87
+ log_message(recv)
88
88
  block.call(recv) if block
89
89
  end
90
90
 
@@ -123,11 +123,11 @@ module Xlogin
123
123
  end
124
124
  end
125
125
 
126
- private
127
- def write_log(text)
126
+ def log_message(text)
128
127
  @loggers.each{ |_, logger| logger.syswrite(text) if logger }
129
128
  end
130
129
 
130
+ private
131
131
  def build_log(log)
132
132
  case log
133
133
  when String
data/lib/xlogin/telnet.rb CHANGED
@@ -38,7 +38,7 @@ module Xlogin
38
38
  @sock.syswrite(bs)
39
39
  when @sock
40
40
  begin
41
- write_log(fh.readpartial(1024))
41
+ log_message(fh.readpartial(1024))
42
42
  rescue Errno::EAGAIN
43
43
  retry
44
44
  end
@@ -1,3 +1,3 @@
1
1
  module Xlogin
2
- VERSION = "0.15.7"
2
+ VERSION = "0.16.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xlogin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.7
4
+ version: 0.16.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - haccht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-28 00:00:00.000000000 Z
11
+ date: 2021-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-telnet