xlogin 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1bdf011d17fbb9f332a09e59355fd1c4397799cc
4
- data.tar.gz: f2f1cb422bfed21add6fa1ff6760fe741322fb17
3
+ metadata.gz: 3fe50364e64650b54e9d1a7eda4fa625370a1439
4
+ data.tar.gz: 099fcd36ef9083f54d55e5a972878251f79da858
5
5
  SHA512:
6
- metadata.gz: c8a83cb62990a031a9db36e68701373fae43cffa3eee30c79d99743a6eae17f8b92f0da8554bd8f4885e3c8bf6fe155f97c7c00fd85534d09850b9ea3fa8f16a
7
- data.tar.gz: 3c763adb40a901f7277fcd494ecab91386a7618e8680aa8047f107cd8e5881a95dcb9b336856df784d12781a7993579924a2c89aac59123498b1e5d4eb5c37eb
6
+ metadata.gz: 185a11590ff1f0559991a405574e5a2b3ef9d18f5a4940a833baa2c6460515cafaf2a2be08d683fbc4ae411b6bb1d81d206b836bf487732357a37445b91b18cf
7
+ data.tar.gz: fa4164c955bd8246ccf0a8db70e8e224bc2e9cf29b4cf1afd8dbadbf6913e07289b5492b74f305b85a3a0b7b8e62d99a16596f3e8d52ad26cfbed7fd1550fb6f
@@ -30,16 +30,7 @@ module Xlogin
30
30
  end
31
31
 
32
32
  def configure(&block)
33
- instance_eval(&block) if block
34
-
35
- source(DEFAULT_INVENTORY_FILE) if factory.list.empty?
36
- if factory.list_templates.empty?
37
- unless Dir.exist?(DEFAULT_TEMPLATE_DIR)
38
- FileUtils.mkdir_p(DEFAULT_TEMPLATE_DIR)
39
- Xlogin::BUILTIN_TEMPLATE_FILES.each { |file| FileUtils.cp(file, DEFAULT_TEMPLATE_DIR) }
40
- end
41
- template_dir(DEFAULT_TEMPLATE_DIR)
42
- end
33
+ instance_eval(&block)
43
34
  end
44
35
 
45
36
  def authorized?
@@ -51,18 +42,23 @@ module Xlogin
51
42
  @authorized = boolean == true || (block && block.call == true)
52
43
  end
53
44
 
54
- def source(source_file)
45
+ def source(source_file = DEFAULT_INVENTORY_FILE)
55
46
  factory.source(source_file)
56
47
  end
57
48
 
58
49
  def template(*template_files)
59
- factory.source_template(*template_files)
50
+ return factory.source_template(*template_files) unless template_files.empty?
51
+
52
+ unless Dir.exist?(DEFAULT_TEMPLATE_DIR)
53
+ FileUtils.mkdir_p(DEFAULT_TEMPLATE_DIR)
54
+ BUILTIN_TEMPLATE_FILES.each { |file| FileUtils.cp(file, DEFAULT_TEMPLATE_DIR) }
55
+ end
56
+ template_dir(DEFAULT_TEMPLATE_DIR)
60
57
  end
61
58
 
62
59
  def template_dir(*template_dirs)
63
- template_dirs.each do |template_dir|
64
- template(*Dir.glob(File.join(template_dir, '*.rb')))
65
- end
60
+ files = template_dirs.flat_map { |dir| Dir.glob(File.join(dir, '*.rb')) }
61
+ template(*files)
66
62
  end
67
63
 
68
64
  end
@@ -8,9 +8,6 @@ require 'stringio'
8
8
  module Xlogin
9
9
  class CLI
10
10
 
11
- DEFAULT_INVENTORY_PATH = File.join(ENV['HOME'], '.xloginrc')
12
- DEFAULT_TEMPLATE_DIR = File.join(ENV['HOME'], '.xlogin.d')
13
-
14
11
  def self.run(args = ARGV)
15
12
  config = getopts(args)
16
13
  client = Xlogin::CLI.new
@@ -23,10 +20,10 @@ module Xlogin
23
20
  def self.getopts(args)
24
21
  config = OpenStruct.new(
25
22
  task: 'tty',
26
- inventory: DEFAULT_INVENTORY_PATH,
23
+ hostlist: [],
27
24
  parallels: 5,
25
+ inventory: nil,
28
26
  templates: [],
29
- hostlist: [],
30
27
  )
31
28
 
32
29
  parser = OptionParser.new
@@ -53,7 +50,6 @@ module Xlogin
53
50
  end
54
51
  end
55
52
 
56
- config.templates += Dir.glob(File.join(DEFAULT_TEMPLATE_DIR, '*.rb')) if config.templates.empty?
57
53
  Xlogin.configure do
58
54
  source(config.inventory)
59
55
  template(*config.templates)
@@ -4,7 +4,7 @@ module Xlogin
4
4
  class Template
5
5
 
6
6
  module RelayTemplate
7
- def build(uri, **params)
7
+ def build(uri, **params)
8
8
  login_host = params.delete(:relay)
9
9
  return super(uri, **params) unless login_host
10
10
 
@@ -37,14 +37,12 @@ module Xlogin
37
37
  #
38
38
  ## Write firmware definition
39
39
  #
40
- # require 'timeout'
41
- # login do |*args|
42
- # username, password = *args
40
+ # login do |username, password|
43
41
  # waitfor(/login:\s*\z/) && puts(username)
44
42
  # waitfor(/Password:\s*\z/) && puts(password)
45
43
  # end
46
44
  #
47
- # delegate do |uri, opts|
45
+ # delegate do |uri, **opts|
48
46
  # cmd("telnet #{uri.host}")
49
47
  # login(*uri.userinfo.split(':'))
50
48
  # end
@@ -67,7 +67,6 @@ module Xlogin
67
67
 
68
68
  def build(type:, uri:, **params)
69
69
  template = get_template(type)
70
- raise Xlogin::SessionNotFound.new("Target not defined") unless uri
71
70
  raise Xlogin::TemplateNotFound.new("Template not found: '#{type}'") unless template
72
71
 
73
72
  template.build(uri, **params)
@@ -1,6 +1,5 @@
1
1
  require 'rake'
2
2
  require 'rake/tasklib'
3
- require 'readline'
4
3
  require 'thread'
5
4
  require 'stringio'
6
5
 
@@ -32,6 +31,10 @@ module Xlogin
32
31
  end
33
32
  end
34
33
  end
34
+
35
+ def mutex
36
+ @mutex ||= Mutex.new
37
+ end
35
38
  end
36
39
 
37
40
 
@@ -86,10 +89,14 @@ module Xlogin
86
89
  begin
87
90
  session = Xlogin.factory.build_from_hostname(name, log: loggers)
88
91
  @runner.call(session)
89
- $stdout.puts buffer.string.lines.map { |line| "#{name}\t" + line.gsub("\r", '') }
92
+ RakeTask.mutex.synchronize do
93
+ $stdout.puts buffer.string.lines.map { |line| "#{name}\t" + line.gsub("\r", '') }
94
+ end
90
95
  rescue => e
91
- $stdout.puts buffer.string.lines.map { |line| "#{name}\t" + line.gsub("\r", '') }
92
- $stderr.puts "#{name}\t#{e}"
96
+ RakeTask.mutex.synchronize do
97
+ $stdout.puts buffer.string.lines.map { |line| "#{name}\t" + line.gsub("\r", '') }
98
+ $stderr.puts "#{name}\t#{e}"
99
+ end
93
100
  end
94
101
  else
95
102
  loggers << $stdout unless silent
@@ -1,7 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'net/ssh/gateway'
3
3
  require 'ostruct'
4
- require 'readline'
5
4
  require 'stringio'
6
5
 
7
6
  module Xlogin
@@ -42,7 +41,6 @@ module Xlogin
42
41
  'Prompt' => Regexp.union(*@template.prompt.map(&:first)),
43
42
  )
44
43
  rescue => e
45
- $stdout.puts e
46
44
  retry if (max_retry -= 1) > 0
47
45
  raise e
48
46
  end
@@ -108,10 +106,9 @@ module Xlogin
108
106
  private
109
107
  def ssh_tunnel(gateway)
110
108
  gateway_uri = URI(gateway)
111
- username, password = *gateway_uri.userinfo.split(':')
112
-
113
109
  case gateway_uri.scheme
114
110
  when 'ssh'
111
+ username, password = *gateway_uri.userinfo.split(':')
115
112
  gateway = Net::SSH::Gateway.new(
116
113
  gateway_uri.host,
117
114
  username,
@@ -140,6 +137,7 @@ module Xlogin
140
137
  when IO, StringIO
141
138
  output_log
142
139
  end
140
+
143
141
  lambda { |c| logger.syswrite c if logger }
144
142
  end
145
143
  end
@@ -1,3 +1,3 @@
1
1
  module Xlogin
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
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.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - haccht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-17 00:00:00.000000000 Z
11
+ date: 2017-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-telnet