xlogin 0.15.8 → 0.16.3

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: 1f333ffef6f055b9ffb8d986d1dd8137483d685d1c51680ed5ac280daad66ec2
4
- data.tar.gz: 823ef09cd1c287fe17c15988357d14621e34d133674f96e1553791bc7c791dcd
3
+ metadata.gz: 275b3d2ef47b42378243799768a5654d993a3a3f1d3c64b893367c41ea714598
4
+ data.tar.gz: a4deb367df7c2c42e7330d53f4b2abfe7266d96a59dd3b4e8de0160cbe8125c9
5
5
  SHA512:
6
- metadata.gz: 294d3d7d4f46c29e76bac6157ddbc94c4787e12fe907134333b477579a480db3f6867d6f0689a3b48b4fd0c65bbcdcc080a10633c941bd4f02ca0d47dd19c2d9
7
- data.tar.gz: d17d60532330cc5dd16644f459d8a19509fe95950c01970e92315cd25b8e09547c9a7a071d52661a557d3e70935a39f03ba85b1fa058448b8b640da743630138
6
+ metadata.gz: 45bfb93bf676763536cb996f1f775035c14e6561888245d5d3a34eda6769da01270facb941f4c84c9a167c72cfa1440ade59c6d2bd4485d2acfeec06a138c57c
7
+ data.tar.gz: 351d88211a993c21930f2e30f6435c245ee920190ba6705664cc953c79ef0640bca465b466fc10344d1e3003257adaca58001d47ec03d9bf5e3d19e5f8bfb98b
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
@@ -59,8 +66,10 @@ module Xlogin
59
66
 
60
67
  private
61
68
  def define
62
- mkdir_p(File.dirname(log), verbose: Rake.application.options.trace) if log
63
- mkdir_p(File.dirname(lock), verbose: Rake.application.options.trace) if lock
69
+ self.log = File.join(Dir.pwd, 'log', name + '.log') if self.log == true
70
+ self.lock = File.join(Dir.pwd, 'lock', name_with_scope) if self.lock == true
71
+ mkdir_p(File.dirname(self.log), verbose: Rake.application.options.trace) if self.log
72
+ mkdir_p(File.dirname(self.lock), verbose: Rake.application.options.trace) if self.lock
64
73
 
65
74
  if lock
66
75
  task(name => lock)
@@ -78,41 +87,41 @@ module Xlogin
78
87
 
79
88
  def run_task
80
89
  buffer = StringIO.new
81
- loggers = []
82
- loggers << log if log
83
- loggers << $stdout if !silent && !Rake.application.options.always_multitask
84
- loggers << buffer
90
+ loggers = [buffer]
91
+ loggers << log if log
92
+ loggers << STDOUT if !silent && !Rake.application.options.always_multitask
85
93
 
86
94
  session = Xlogin.get(name, log: loggers, timeout: timeout)
95
+ instance_exec(session, &@runner)
87
96
 
88
- @runner.call(session)
89
- $stdout.print log_text(buffer.string) if !silent && Rake.application.options.always_multitask
90
-
97
+ print(buffer.string) if !silent && Rake.application.options.always_multitask
91
98
  return true
92
99
  rescue => e
93
100
  RakeTask.shutdown! if fail_on_error
94
101
 
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
-
102
+ session.log_message(e.to_s.colorize(color: :red)) if session
103
+ print(buffer.string + "\n", color: :red) if Rake.application.options.always_multitask
100
104
  return false
101
105
  ensure
102
106
  session.close rescue nil
103
107
  end
104
108
 
105
- def log_text(text)
106
- text.lines.map{ |line| "#{Time.now.iso8601} #{name}\t|#{line.gsub(/^.*\r/, '')}" }.join
107
- end
109
+ def puts(text, **opts)
110
+ return text.each { |e| puts(e, **opts) } if text.kind_of?(Array)
108
111
 
109
- end
112
+ text = text.to_s
113
+ text = text + "\n" unless text[-1] == "\n"
114
+ print(text, **opts)
115
+ end
110
116
 
111
- module SessionModule
117
+ def print(text, **opts)
118
+ text = text.to_s
119
+ return if text.empty?
112
120
 
113
- def comment(line, lf: true, **color)
114
- write_log(line.chomp.colorize({color: :light_white}.merge(**color)))
115
- cmd('') if lf
121
+ text = text.gsub("\r", '')
122
+ text = text.lines.map{ |text| "#{name}\t|#{text}" }.join if Rake.application.options.always_multitask
123
+ text = text.colorize(**opts)
124
+ $stdout.print(text)
116
125
  end
117
126
 
118
127
  end
@@ -45,7 +45,7 @@ module Xlogin
45
45
  rescue => e
46
46
  unless (num_try += 1) > (@config.retry || 0)
47
47
  sleep 2.0 ** (num_try)
48
- retry
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.8"
2
+ VERSION = "0.16.3"
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.8
4
+ version: 0.16.3
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-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-telnet