xlogin 0.8.0 → 0.8.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
  SHA1:
3
- metadata.gz: 1d9a1b26c54a0a1729282e93dca1abcc8dfc1336
4
- data.tar.gz: 41c331ddf6bf109f0ef85b79d79f0f841dbb787c
3
+ metadata.gz: a71e3f5d31063e0a93efe56206322d5deb3f029a
4
+ data.tar.gz: 15efe2eeb297593352b1f9697a88f6a608210598
5
5
  SHA512:
6
- metadata.gz: 5c472d2e2fbe03a9b2bcfc088fe3a5143ac0fa20253c53c07dc84604ebd4fdbab787343bbd8e06e1f5eea259d1ff8894055e6a7f3dc0e7ecc855d472584c660c
7
- data.tar.gz: b46d85dca28cf7643e2c85fb517bf4c86a5a58418b76f88b3011436e2b4bdb04f1a2b1221c55a83923b3a33dcedfcbde2bd5de3f4591725e66a8725dae803636
6
+ metadata.gz: 6c3c536bce5218ddcae4701f31891c0db6bab5a6d59f40172bcb4ab07baab060a734576cb0e0c16435022c64adc479d2491c3b6a52172f509ce32319b2009b56
7
+ data.tar.gz: 556d8f2a5394d29fbd05d60826ab2096cb2db8475d13a5652ccdfa7c0804b51841bf789a8a8665920715944881a4b9bdd0f3d6e231b27d606e9f558cec268ee9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- xlogin (0.8.0)
4
+ xlogin (0.8.1)
5
5
  net-ssh
6
6
  net-ssh-gateway
7
7
  net-ssh-telnet
data/lib/xlogin/cli.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'optparse'
4
4
  require 'ostruct'
5
5
  require 'parallel'
6
+ require 'readline'
6
7
  require 'stringio'
7
8
 
8
9
  module Xlogin
@@ -75,10 +76,14 @@ module Xlogin
75
76
  end
76
77
 
77
78
  def tty(config)
78
- target = config.hostlist.sort_by { |e| e[:name] }.first
79
- $stdout.puts "Trying #{target[:name]}...", "Escape character is '^]'."
80
- config.hostlist = [target]
81
- login(config) { |session| session.interact! }
79
+ Signal.trap(:INT) { exit 0 }
80
+ list = config.hostlist.sort_by { |e| e[:name] }
81
+ list.each do |target|
82
+ Readline.readline(">> #{target[:name]} ", false) unless list.size == 1
83
+ $stdout.puts "Trying #{target[:name]}...", "Escape character is '^]'."
84
+ config.hostlist = [target]
85
+ login(config) { |session| session.interact! }
86
+ end
82
87
  end
83
88
 
84
89
  def exec(config)
@@ -1,5 +1,6 @@
1
1
  require 'rake'
2
2
  require 'rake/tasklib'
3
+ require 'ostruct'
3
4
  require 'stringio'
4
5
 
5
6
  module Xlogin
@@ -9,14 +10,18 @@ module Xlogin
9
10
  class << self
10
11
  include Rake::DSL
11
12
 
12
- def bulk(names, &block)
13
- names = names.map(&:strip).grep(/^\s*[^#]/).uniq
13
+ def generate(*target, **opts, &block)
14
+ hostnames = target.flat_map { |e| Xlogin.factory.list(e) }.map { |e| e[:name] }
15
+
14
16
  description = Rake.application.last_description
17
+ task 'all' => hostnames unless opts[:bundle] == false
15
18
 
16
- names.each do |name|
19
+ description = opts[:desc] if opts.key?(:desc)
20
+ hostnames.each do |hostname|
17
21
  desc description
18
- RakeTask.new(name, &block)
22
+ RakeTask.new(hostname, &block)
19
23
  end
24
+
20
25
  end
21
26
  end
22
27
 
@@ -24,66 +29,75 @@ module Xlogin
24
29
  attr_accessor :lock
25
30
  attr_accessor :log
26
31
  attr_accessor :silent
27
- attr_accessor :timeout
28
32
  attr_accessor :fail_on_error
29
33
 
30
34
  def initialize(name)
31
35
  @name = name
32
36
  @runner = nil
37
+ @config = OpenStruct.new
33
38
  @silent ||= Rake.application.options.silent
34
39
  @fail_on_error = true
35
40
 
36
- yield(self) if block_given?
37
- define_task
41
+ yield self if block_given?
42
+ define
38
43
  end
39
44
 
40
- def start(&block)
45
+ def run(&block)
41
46
  @runner = block
42
47
  end
43
48
 
49
+ def method_missing(name, *args, &block)
50
+ super(name, *args, &block) unless name.to_s =~ /^\w+=$/
51
+ @config.send(name, *args)
52
+ end
53
+
44
54
  private
45
- def define_task
55
+ def define
46
56
  description = Rake.application.last_description
47
57
  description = "#{description} - #{name}" if description
48
58
  desc description
49
59
 
60
+ mkdir_p(File.dirname(log), verbose: Rake.application.options.trace) if log
61
+ mkdir_p(File.dirname(lock), verbose: Rake.application.options.trace) if lock
62
+
50
63
  if lock
51
64
  task(name => lock)
52
65
  file(lock) do
53
- invoke
54
- mkdir_p(File.dirname(lock), verbose: Rake.application.options.trace)
55
- touch(lock, verbose: Rake.application.options.trace)
66
+ File.open(lock, 'w') do |fd|
67
+ run_task if fd.flock(File::LOCK_EX|File::LOCK_NB)
68
+ end
56
69
  end
57
70
  else
58
- task(name) { invoke }
71
+ task(name) do
72
+ run_task
73
+ end
59
74
  end
60
75
  end
61
76
 
62
- def invoke
77
+ def run_task
63
78
  buffer = StringIO.new
64
79
  loggers = []
65
- loggers << buffer if Rake.application.options.always_multitask
66
- loggers << $stdout unless Rake.application.options.always_multitask || silent
67
-
68
- if log
69
- mkdir_p(File.dirname(log), verbose: Rake.application.options.trace)
70
- loggers << log
71
- end
80
+ loggers << log if log
81
+ loggers << buffer if !silent && Rake.application.options.always_multitask
82
+ loggers << $stdout if !silent && !Rake.application.options.always_multitask
72
83
 
73
84
  begin
74
- session = Xlogin.get(name, log: loggers, timeout: timeout)
75
-
76
- @runner.call(session)
85
+ session = Xlogin.get(name, log: loggers, **@config.to_h)
86
+ session.instance_eval(&@runner)
77
87
  session.close if session
88
+
89
+ output($stdout, buffer.string) if !silent && Rake.application.options.always_multitask
78
90
  rescue => e
79
- $stderr.print "[ERROR] #{name} - #{e}\n"
91
+ output($stderr, buffer.string) if !silent && Rake.application.options.always_multitask
92
+ output($stderr, "[ERROR] Xlogin - #{e}\n")
80
93
  raise e if fail_on_error
81
94
  end
95
+ end
82
96
 
83
- if Rake.application.options.always_multitask && !silent
84
- lines = buffer.string.lines.map { |line| "#{name}\t" + line.gsub("\r", '') }
85
- lines.each { |line| $stdout.print "#{line.chomp}\n" }
86
- end
97
+ def output(fp, text)
98
+ prefix = (Rake.application.options.always_multitask)? "#{name}\t| " : ""
99
+ lines = text.lines.map { |line| "#{prefix}#{line.strip}\n" }
100
+ lines.each { |line| $stdout.print line }
87
101
  end
88
102
 
89
103
  end
@@ -1,3 +1,3 @@
1
1
  module Xlogin
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.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.8.0
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - haccht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-08 00:00:00.000000000 Z
11
+ date: 2018-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-telnet